Monthly Archives: December 2014

Setting up PostgreSQL on a local Linux computer

I recently installed Linux on a new machine and had to go through the setup of PostgreSQL again. Here's the steps I did in order to get the database up and running:

1. Install postgres and pgadmin

sudo apt-get updatedmin3
sudo apt-get install postgresql
sudo apt-get install pgadmin3

2. Change password of postgres user

PostgreSQL sets up an admin user (called "postgres") for database maintenance. In order to log in as this user and create the database, change their password:

$ sudo passwd postgres
[sudo] password for phil: 
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully

3. Set up the database as postgres user

Next, log in using the postgres user

$ su
phil # su postgres

As this user, you can start postgres and create a new database. Finally, grant all privileges to your regular user, so that you have full access to the newly created database:

$ psql
 psql (9.3.5)
 Type "help" for help.
 postgres=# create database test;
 postgres=# grant all privileges on database test to phil;
 postgres=# \q

You can now log in to the database test with your normal account by typing

$ psql -d test