Tuesday, February 25, 2014

Managing PostgreSQL with pgsql and pgAdmin3

The command line interface (CLI) tool that comes with Postgres server is known as pgsql. Alternatively, pgAdmin3 and phpPgAdmin can be installed.

The pgsql

Among some of the commands for pgsql can be shown as below;

Example of common commands

Login to the Postgres prompt
$ psql -U postgres -h

Create a role to create database
postgres=# CREATE ROLE dbadmin CREATEDB;

Create a role as administrator
postgres=# CREATE ROLE admin SUPERUSER;

Create a role to create group roles
postgres=# CREATE ROLE dbadmin CREATEROLE;

Add a user to any of above role groups
postgres=# GRANT dbadmin to userone;

Remove a user from a role group
postgres=# REVOKE dbadmin from userone;

A user can change their roles if they are assigned to several roles. 
postgres=# SET ROLE admin;

A user can restore to default role group 
postgres=# RESET ROLE;

Remove a role
postgres=# DROP ROLE admin;

List available users and roles
postgres=# \du

                               List of roles
   Role name   |                   Attributes                   | Member of 
 admin         | Create DB, Cannot login                        | {}
 dbmsuser      | Superuser                                      | {admin}
 dbmsuserlogin | Superuser, Cannot login                        | {}
 postgres      | Superuser, Create role, Create DB, Replication | {}

Change privileges of a role

Create a database and assign to a role
postgres=# CREATE DATABASE mycms WITH admin;

Delete a database
postgres=# DROP DATABASE mycms;


The Window pgAdmin3

Try out SQL statements within these tools. I found one nice reference at http://www.itl.nist.gov/div897/ctg/dm/sql_examples.htm

Installing PostgreSQL on Centos 6

PostgreSQL being an OSS licensed database is very different compared to MySQL. PostgreSQL (or Postges) maintains a repository for Linux systems like Centos to install the database. This repository is known as pgdg and is maintained at yum.postgresql.org or yum.pgrpms.org

Installation of the Postgres comes with psql, this is a CLI to manage Postgres.

Installation of PostgreSQL 9.3 on Centos 6.4 is as follows;

Step 1:
Open a CLI as root user and retrieve the pgdg repo RPM, then install it. This will allow the Centos to find for software from the pgdg.

wget http://yum.postgresql.org/9.3/redhat/rhel-6-x86_64/pgdg-centos93-9.3-1.noarch.rpm
rpm -ivh pgdg-centos93-9.3-1.noarch.rpm

wget http://yum.pgrpms.org/9.3/redhat/rhel-6-x86_64/pgdg-centos93-9.3-1.noarch.rpm
rpm -ivh pgdg-centos93-9.3-1.noarch.rpm

Step 2:
Install the client and server.

yum groupinstall "PostgreSQL Database Server 9.3 PGDG"

yum install postgresql93 postgresql93-server


Step 3:
Initialise database and tables, and start. This creates the default user postgres.

service postgresql-9.3 initdb
service postgresql-9.3 start

You can now login with the default user to the Postgres terminal as follows;

[root]# su postgres
bash$ cd
bash$ psql -d postgres

If you get the error "psql: could not connect to server: No such file or directory...." Ensure the postgresql server service is running.
Step 4:
As the postgres user, create an administrative user, then log out from the psql (use \q), then the shell (Control-d).


As reference, here is summary of the syntax:
CREATE ROLE name [ [WITH] option [ . . . ] ]

 where option includes:

Step 5:
Edit Postgres configuration file;

vi /var/lib/pgsql/9.3/data/postgresql.conf

Uncomment the line and save.
#listen_addresses = ‘localhost’ and change it to listen_addresses = ‘*’

vi /var/lib/pgsql/9.3/data/pg_hba.conf

Add a line at bottom of the file to allow non-local connections, e.g.
host    all             dbmsuser            md5

Post installation
chkconfig postgresql-9.3 on


Thursday, February 20, 2014

Italian God Fathers May Run Open Source

In the current economic challenges, many countries are looking at saving cost via ICT and Italy is not an exception. Umbria, a region in the centre of Italy that produces cheese, lentils, truffles and have a relatively large number of small industries. This 900,000 strong population region is home to an active GNU/Linux User Group Perugia.

In 2012, Umbria saw the start of a revolution to switch to LibreOffice, which is LGPL or open source software (OSS) licensed. LibreOffice provides office productivity tools that include a word processor (like MS Word), presentation (like MS Powerpoint), spreadsheet (like MS Excel) and more. Advantages of this software is that it is free to download and install for almost all computers as it supports MS Windows, Linux and Mac platforms. Most popular editable document formats can be open and edited and its interface is rather intuitive and easy to use. It comes with a portable version where users can install it on a USB drive and carry it around to run LibreOffice any where. A built in PDF converter allows any edited file to be frozen and to be distributed with read only access and consistent format.

MS Office have been introducing its OOXML format through the docx formats which will eventually required every organisation to purchase an upgrade license for MS Office and this will incur la high upgrade cost. LibreOffice by default save files in Open Document Format or ODF (International document standards ISO/IEC 26300:2006) and it also supports past versions of MS Word, Excel and Powerpoint.

Through LibreUmbria, schools were introduced to use LibreOffice as their primary document editing applications before it was expanded further further to other organisations. This also received the government's top innovation award for Italian Government Projects in 2012/2013. Will the rest of the Italian Government and private organisations follow suit?

Read up news on the region of Umbria to switch over from MS Office to LibreOffice.

Jan 16, 2014 from ZDNet
Sep 26, 2013 from LibreOffice
Jun 5, 2013 from Document Foundation Blog

List of open standards can be found at ISO Public site

Wednesday, February 5, 2014

Passwordless root SSH Public Key Authentication on CentOS 6

Need to remote login to linux servers?

Create a public key and store it in the remote server. By default it is recognised as authorized_keys but this is fully configurable. The ssh-keygen generated the public key with RSA that is by default called id_rsa.pub

A well written article to do this can be found at Passwordless root SSH Public Key Authentication on CentOS 6

An alternative sshpass command as mentioned in January 31, 2014 Linuxpromagazine seems to force users to make the password visible. Good that this is no available in a default Centos 6, as this will help to maintain good password practices. I.e. do not have password kept where anyone can read it.