PostgreSQL

PostgreSQL is an object-relational database system that has the features of traditional commercial database systems with enhancements to be found in next-generation DBMS systems.

Installation

To install PostgreSQL, run the following command in the command prompt:

sudo apt-get install postgresql

Once the installation is complete, you should configure the PostgreSQL server based on your needs, although the default configuration is viable.

Configuration

By default, connection via TCP/IP is disabled. PostgreSQL supports multiple client authentication methods. By default, IDENT authentication method is used. Please refer the PostgreSQL Administrator's Guide.

The following discussion assumes that you wish to enable TCP/IP connections and use the MD5 method for client authentication. PostgreSQL configuration files are stored in the /etc/postgresql/<version>/main directory. For example, if you install PostgreSQL 7.4, the configuration files are stored in the /etc/postgresql/7.4/main directory.

[Tip]

To configure ident authentication, add entries to the /etc/postgresql/7.4/main/pg_ident.conf file.

To enable TCP/IP connections, edit the file /etc/postgresql/7.4/main/postgresql.conf

Locate the line #tcpip_socket = false and change it to tcpip_socket = true. You may also edit all other parameters, if you know what you are doing! For details, refer to the configuration file or to the PostgreSQL documentation.

By default, the user credentials are not set for MD5 client authentication. So, first it is necessary to configure the PostgreSQL server to use trust client authentication, connect to the database, configure the password, and revert the configuration back to use MD5 client authentication. To enable trust client authentication, edit the file /etc/postgresql/7.4/main/pg_hba.conf

Comment out all the existing lines which use ident and MD5 client authentication and add the following line:

local all postgres trust sameuser

Then, run the following command to start the PostgreSQL server:

sudo /etc/init.d/postgresql start

Once the PostgreSQL server is successfully started, run the following command at a terminal prompt to connect to the default PostgreSQL template database

psql -U postgres -d template1

The above command connects to PostgreSQL database template1 as user postgres. Once you connect to the PostgreSQL server, you will be at a SQL prompt. You can run the following SQL command at the psql prompt to configure the password for the user postgres.

template1=# ALTER USER postgres with encrypted password 'your_password';

After configuring the password, edit the file /etc/postgresql/7.4/main/pg_hba.conf to use MD5 authentication:

Comment the recently added trust line and add the following line:

local all postgres md5 sameuser
[Warning]

The above configuration is not complete by any means. Please refer the PostgreSQL Administrator's Guide to configure more parameters.