31.7 C
Guru Unix /Linux and GNU supporter

How to install PostgreSql on Ubuntu18.04

Install and Use PostgreSQL on Ubuntu 18.04

Database management systems are the major components for websites and almost every application uses database to store their data as well as manage this data to produce different results for specific purpose. Basically database provide a structural way to organize and manage data to access information.

Before starting the installation of PostgreSQL on Ubuntu. Let’s have a description about this database. PostgreSQL is a relational database management system in which we use a system that provides the implementation of original SQL (Structure Query Language). PostgreSQL is the most popular choice which provides advanced features in which transactions are reliable data concurrency handles without read locks.

In this article we will learn how to install and use PostgreSQL in our Ubuntu server. So let’s start by the following steps.

STEP1:  Installing PostgreSQL on Ubuntu.

- Advertisement -

The first step for installing PostgreSQL on Ubuntu is to add repository files of Postgres packages into Ubuntu. Note that your server should be configured initially in which there is a non-root user and some basic firewall settings are configured. However, this is your first time, so refresh your local package and then install Postgres package. Following is the process to install the package by command.


 $  sudo apt update
 $  sudo apt install postgresql postgresql-contrib 


After installing Postgres into Ubuntu server, then you have to check that whether it is listening to the socket on port number 5432. For this purpose, follow the command mentioned below:


$ ss -nlt

The server will start after the reboot completes. Then you can enable or disable this by using following commands.


$ sudo systemctl disable postgresql
$ sudo systemctl enable postgresql


To configure your server to listen all networks, then you have to change its main configuration file using following command.


$ sudo nano /etc/postgresql/10/main/postgresql.conf

Step 2: Listening and restarting PostgreSQL.

After configuring Postgresql to listen for all networks, now we have to type the command to check whether it is listening or not. And then later we will restart the server. For this purpose, follow the instructions by typing the commands.


listen_addresses = ‘*’
$ sudo service postgresql restart

Note: If you have enabled UFW firewall, then you can open the server’s port5432 for any incoming traffic by following command


$ sudo ufw allow from any to any port 5432 proto tcp


Step 3: Connecting to PostgreSQL.

After installing and configuring the PostgreSQL in our server, now it is the time to connect this system to use it and create database, users etc. For connecting to PostgreSQL follow the commands or instruction accordingly to make it successful for you.


$ sudo su – postgres
$ psql


Step 4: Check lists of database in PostgreSQL.

After connecting to the server we are now required to check whether there are databases in the server. For this purpose, perform following steps.


postgres-# \l

This will give you following results:

In order to list the users in the database type following steps or commands.


postgres-# \du


Step 5: Change user Password in PostgreSQL.

After we have seen databases and users, now we can change user’s password by performing the following step.


postgres=# ALTER USER postgres WITH PASSWORD  ‘newpass’;



For creating new user in database follow the below mentioned steps.


postgres=# CREATE USER newuser WITH PASSWORD ‘123’;



After creating users now we can upgrade and check login info for the users. For this purpose follow the steps.


postgres=# ALTER USER newuser WITH SUPERUSER;  (For upgrading user)



postgres-# \conninfo   (For log-in info)



After this you can now exit the program by typing following command.


postgres-# \q



After following all the guideline, you are now able to install PostgreSQL in Ubuntu to use the features of PostgreSQL. And using this DBMS to manage and creating user. However, you should follow the same procedure to make it accurate. If you face any problem, then leave a message or comment. We will help you in every matter.


- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
"The best Linux newsletter on the web"


Please enter your comment!
Please enter your name here

Latest article