How to install PostgreSQL 9.6 on Ubuntu 16.04

if [[ -d /var/lib/postgresql ]]; then
  cd /var/lib/postgresql
sudo apt-get remove --purge postgresql postgresql-9.5 postgresql-client-9.5 postgresql-client-common postgresql-common postgresql-contrib-9.5 postgresql-10 postgresql-client-10 postgresql-contrib-10 pgadmin3 phppgadmin
sudo apt-get autoremove -y
echo 'deb xenial-pgdg main' | sudo tee '/etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - | sudo apt-key add -
sudo apt-get update
sudo apt-get install -y postgresql-client-9.6 postgresql-contrib-9.6 libpq-dev postgresql-server-dev-9.6 postgresql-doc-9.6

Stop PostgreSQL

sudo -u postgres /usr/lib/postgresql/9.6/bin/pg_ctl -D /etc/postgresql/9.6/main/ -l logfile stop
sudo service postgresql stop

Start PostgreSQL

sudo -u postgres /usr/lib/postgresql/9.6/bin/pg_ctl -D /etc/postgresql/9.6/main/ -l logfile start

Leave a comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.