In this tutorial we’ll learn how to install PostgreSQL on Ubuntu 16.04. We will also install and configure its prerequisites. PostgreSQL is a free, open-source object-relational database management system (object-RDBMS), similar to MySQL, and is standards-compliant and extensible. It is commonly used as a back-end for web and mobile applications.
I recommend to use a minimal Ubuntu server setup as a basis for the tutorial, that can be a virtual or a root server image with an Ubuntu 16.04 minimal install from a web hosting company or you use our minimal server tutorial to install a server from scratch.
Install PostgreSQL on Ubuntu 16.04
Step 1. First, ensure your system and apt package lists are fully up-to-date by running the following:
apt-get update -y && apt-get upgrade -y
Step 2. Installing PostgreSQL.
Run the following command to install PostgreSQL repository:
apt-get install postgresql-9.5
If you plan to use PostgreSQL with PHP, you’ll need to install the PostgreSQL PHP extension:
apt-get install php-pgsql
Start PostgreSQL service using the following command as per your operating systems. Also, enable PostgreSQL service to auto start on system boot:
systemctl start postgresql systemctl enable postgresql
Step 3. Verify PostgreSQL Installation.
Let’s log in to postfix to verify that installation completed successfully:
su - postgres
Use psql command to access PostgreSQL prompt with admin privileges:
$ psql psql (9.6.0) Type "help" for help. postgres=#
You may create password for user postgres for security purpose:
postgres=# \password postgres
Congratulation’s! You have successfully configured PostgreSQL on your Ubuntu 16.04 server.