Install PostgreSQL on Ubuntu

Install PostgreSQL on Ubuntu

The following is a quick guide to install postgres 8.2 on Ubuntu 7.04, but it might also work for older version of postgres and Ubuntu, and other Debian based distros. Firstly, enter the following command to install postgres, enter the password on prompt.
$ sudo apt-get install postgresql postgresql-client postgresql-contrib
This installs both server and client postgres on your machine, but the server is more relevant in this article. Secondly, we need to reset the ‘postgres’ user password, which is the admin account for the postgres server: Login as the root:
$ su
Then login to postgres without needing a password
$ su - postgres
Now login to the postgres template database:
$ psql template1
template1=# ALTER USER postgres WITH PASSWORD 'your_new_password';
Type in
template1=# \\q
to quit. The password for the postgres account in the database has been updated, now we need to do the same for unix user ‘postgres’: Clear the password for postgres first,
$ sudo passwd -d postgres
Then update the password
$ passwd
Now enter the same password that you used previously. You should now be able to login to postgres using the ‘postgres’ account:
$ psql -U postgres
A welcome message should display:
Welcome to psql 8.2.7, 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

The database should be empty, and you are ready to start creating new databases and tables.


Leave a Reply

Your email address will not be published. Required fields are marked *

My new Snowflake Blog is now live. I will not be updating this blog anymore but will continue with new contents in the Snowflake world!