In this tutorial we’ll learn how to install PostgreSQL on Ubuntu 18.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 18.04 LTS minimal install from a web hosting company or you use our minimal server tutorial to install a server from scratch.
Install PostgreSQL on Ubuntu 18.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 on Ubuntu 18.04.
Run the following command to install the PostgreSQL 10 package:
apt install postgresql-client
If you plan to use PostgreSQL with PHP, you’ll need to install the PostgreSQL PHP extension:
apt 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 (10.2 (Ubuntu 10.2-1)) Type "help" for help. postgres=#
You may create password for user postgres for security purpose:
postgres=# \password postgres
Congratulation’s! You have successfully install and configured PostgreSQL on your Ubuntu 18.04 LTS server. Thanks for using this tutorial installing PostgreSQL on Ubuntu 18.04 LTS (Bionic Beaver) system.