Howto: Debian / Ubuntu Linux Install PostgreSQL Database Server

by on May 2, 2007 · 4 comments· LAST UPDATED December 21, 2007

in , ,

Q. How do I install PostgreSQL server under Ubuntu Linux?

A. PostgreSQL is an Open Source Software object relational database management system. POSTGRES pioneered many of the object-relational concepts now becoming available in some commercial databases. Traditional relational database management systems (RDBMS) support a data model consisting of a collection of named relations, containing attributes of a specific type. In current commercial systems, possible types include floating point numbers, integers, character strings, money, and dates.

Task: Install PostgreSQL

The best way to install PostgreSQL under Debian or Ubuntu Linux is to use apt-get command
# apt-get install postgresql
OR
$ sudo apt-get install postgresql
Output:

Reading package lists... Done
Building dependency tree... Done
The following extra packages will be installed:
  openssl postgresql-7.4 postgresql-client postgresql-client-7.4 postgresql-client-common postgresql-common ssl-cert
Suggested packages:
  ca-certificates postgresql-doc-7.4
Recommended packages:
  postgresql-plpython-7.4 postgresql-plperl-7.4 postgresql-pltcl-7.4
The following NEW packages will be installed
  openssl postgresql postgresql-7.4 postgresql-client postgresql-client-7.4 postgresql-client-common postgresql-common
  ssl-cert
0 upgraded, 8 newly installed, 0 to remove and 0 not upgraded.
Need to get 5620kB of archives.
After unpacking 14.3MB of additional disk space will be used.
Do you want to continue [Y/n]? y
Get: 1 http://cudlug.cudenver.edu stable/main openssl 0.9.8c-4 [1004kB]
......
........
..
...
Setting up postgresql-7.4 (7.4.16-1) ...
Creating new cluster (configuration: /etc/postgresql/7.4/main, data: /var/lib/postgresql/7.4/main)...
Moving configuration file /var/lib/postgresql/7.4/main/postgresql.conf to /etc/postgresql/7.4/main...
Moving configuration file /var/lib/postgresql/7.4/main/pg_hba.conf to /etc/postgresql/7.4/main...
Moving configuration file /var/lib/postgresql/7.4/main/pg_ident.conf to /etc/postgresql/7.4/main...
Configuring postgresql.conf to use port 5432...
Starting PostgreSQL 7.4 database server: main.
Setting up postgresql-client (7.5.22) ...
Setting up postgresql (7.5.22) ...

Task: Connect to PostgreSQL server

You can login as PostgreSQL superuser, enter command:
$ su - postgres
Now connect to default database called template1:
$ psql template1
Output:

postgres@debian:~$ psql template1
Welcome to psql 7.4.16, the PostgreSQL interactive terminal.
Type:  \\copyright for distribution terms
       \\h for help with SQL commands
       \\? for help on internal slash commands
       \\g or terminate with semicolon to execute query
       \\q to quit
template1=#

Type \l to list database
Type \q to quit

See also:

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 4 comments… read them below or add one }

1 kien October 3, 2009 at 10:48 am

when t use command:
$ su – postgres
Password:
I don’t know what my password? Can you support me, thank you.

Reply

2 Chris Rogers October 3, 2009 at 2:02 pm

By default there is none

When it asks to enter a password just simply press enter. without typing anything

Reply

3 hai October 3, 2009 at 3:47 pm

when I seting a data base I used command:
/usr/bin/createdb -h localhost -p 5433 -U dellstore
and supposing dellstore is a data base. at once apprience a command :
password:
let’s help me answer why? thanks

Reply

4 Rahul Chaudhari October 8, 2009 at 9:23 am

After installation and before connecting you can set a password for postgres as follows,

sudo passwd postgres

This command will ask new password directly.

Reply

Leave a Comment

Tagged as: , , , , , ,

Previous Faq:

Next Faq: