First, check the version of Ubuntu:
lsb_release -sc
You need to add the latest PostgreSQL repository for the latest version, otherwise It will install PostgreSQL 9.3. This is for trusty version.
sudo add-apt-repository "deb https://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main"
Update and Install PostgreSQL 9.4:
sudo apt-get update
sudo apt-get install postgresql-9.4
List the current Clusters
pg_lsclusters
Stop the 9.4 cluster and drop it.
sudo pg_dropcluster 9.4 main --stop
Upgrade the 9.3 cluster to the latest version.
sudo pg_upgradecluster 9.3 main
Your 9.3 cluster should now be "down".
pg_lsclusters
Ver Cluster Port Status Owner Data directory Log file
9.3 main 5433 down postgres /var/lib/postgresql/9.3/main /var/log/postgresql/postgresql-9.3-main.log
9.4 main 5432 online postgres /var/lib/postgresql/9.4/main /var/log/postgresql/postgresql-9.4-main.log
Check that the upgraded cluster works, then remove the 9.3 cluster.
sudo pg_dropcluster 9.3 main
Adapted from:
http://www.dbrnd.com/2016/04/postgresql-how-to-install-postgresql-9-4-on-ubuntu-14-04/ https://gist.github.com/dideler/60c9ce184198666e5ab4
Thanks worked smoothly for me but I had the following error after running
update
:which can be resolved by running: