Postgresql Installation in Ubuntu

About PostgreSQL

PostgreSQL is an object-relational database management system (ORDBMS). It is released under a BSD-style license and is thus free software. As with many other open-source programs, PostgreSQL is not controlled by any single company, but relies on a global community of developers and companies to develop it.

Installation in Ubuntu

Now, I am going to install postgresql package. I am using ubuntu feisty and now want to download postgresql-8.1. The latest release of postgresql is postgresql-8.3.


jafar@dns4:/home/jafar# sudo apt-get install postgresql-8.1
 

jafar@dns4:~$ sudo su  

[sudo] password for jafar:

root@dns4:~$ sudo /etc/init.d/postgresql-8.1 restart 

root@dns4:/home/jafar# su postgres 

postgres@dns4:/home/jafar$

Edit pg_hba.conf :

postgres@dns4:/home/jafar$ vi /etc/postgresql/8.1/main/pg_hba.conf 

# TYPE  DATABASE    USER        CIDR-ADDRESS          METHOD

# "local" is for Unix domain socket connections only
local   all         all                               password          
# IPv4 local connections:
host    all         all         127.0.0.1/32          password
host    all         all         192.168.0.10/32    password   
        

Edit postgresql.conf :

postgres@dns4:/home/jafar$ vi /etc/postgresql/8.1/main/postgresql.conf

#---------------------------------------------------------------------------
# CONNECTIONS AND AUTHENTICATION
#---------------------------------------------------------------------------

# - Connection Settings -

listen_addresses = 'localhost'          # what IP address(es) to listen on;      
                                                       # comma-separated list of addresses;
                                                       # defaults to 'localhost', '*' = all
port = 5432

Make sure to activate listen addresses line , or we can use '*' and dont forget to make sure we are using port 5432 as default postgresql port.

postgres@dns4:/home/jafar$ psql template1  

Welcome to psql 8.1.10, the PostgreSQL interactive terminal.

Type:  \copyright for distribution terms
       \h for help with SQL commands
       \? for help with psql commands
       \g or terminate with semicolon to execute query
       \q to quit

template1=#

template1=# create user diki password 'lagibelajar';   CREATE ROLE
template1=# create database belajar owner diki;   
     CREATE DATABASE
template1=# \q

postgres@dns4:/home/jafar$ createlang plpgsql belajar  

postgres@dns4:/home/jafar$ psql belajar -U diki
Password for user belajar:
Welcome to psql 8.1.10, the PostgreSQL interactive terminal.

Type:  \copyright for distribution terms
       \h for help with SQL commands
       \? for help with psql commands
       \g or terminate with semicolon to execute query
       \q to quit

belajar=>