Skip to content

Instantly share code, notes, and snippets.

@shreyas-satish
Last active January 19, 2016 13:48
Show Gist options
  • Save shreyas-satish/1424124 to your computer and use it in GitHub Desktop.
Save shreyas-satish/1424124 to your computer and use it in GitHub Desktop.
Installing Postgresql on linux with apt
sudo apt-get install python-software-properties
Next, let’s add the repository containing PostgreSQL 9.0:
sudo add-apt-repository ppa:pitti/postgresql
sudo apt-get update
Now, we need to install the database, the contrib tools, and several supporting libraries:
sudo apt-get install postgresql-9.0 postgresql-contrib-9.0
sudo apt-get install postgresql-server-dev-9.0 libpq-dev libpq5
Installing all of these packages now will save you the pain later of trying to track down why certain things won’t work. Another good step is to symlink the archival cleanup tool to /usr/bin for use when you need to enable replication with WAL:
sudo ln -s /usr/lib/postgresql/9.0/bin/pg_archivecleanup /usr/bin/
At this time, you should also recreate the cluster to ensure proper UTF-8 encoding for all databases:
Set password for postgres
sudo passwd postgres
Login to
su postgres
pg_dropcluster --stop 9.0 main
pg_createcluster --start -e UTF-8 9.0 main
Logout of postgres
sudo /etc/init.d/postgresql restart
sudo /etc/init.d/postgresql status
Once this has all been done, you can find the configuration directory in /etc/postgresql/9.0/main and the data directory in /var/lib/postgresql/9.0/main.
//Optional
Another useful tool is pg_top, which allows you to view the status of your PostgreSQL processes along with the currently executing queries:
sudo wget http://pgfoundry.org/frs/download.php/1781/pg_top-3.6.2.tar.gz
tar -zxpvf pg_top-3.6.2.tar.gz
cd pg_top-3.6.2
./configure
make
//Optional End
PostgreSQL and all related utilities should now be properly installed. From here, you can begin creating databases and users with the psql command:
Login to postgres
psql -d postgres
CREATE USER deploy WITH PASSWORD 'jw8s0F4';
CREATE ROLE admin SUPERUSER
CREATE DATABASE name;
Finally, you may want to set auth for 'postgres' to md5 or trust
vim /etc/postgresql/9.0/main/pg_hba.conf
If you have multiple postgres installations running simultaneously, you can pick the postgres cluster you want to work with:
psql --cluster 9.5/main -d postgres
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment