How to Install and Connect PostgreSQL 12 on Ubuntu 22.04


In addition to databases, there are services that maintain databases, called Database Management or DBMS. One of these DBMSs is calling PostgreSQL. This article will help you to get acquainting with PostgreSQL and learn How to Install and Connect PostgreSQL 12 on Ubuntu 22.04. You can check and purchase Ubuntu VPS server packages provided on the Eldernode website.

Tutorial Install and Connect PostgreSQL 14 on Ubuntu 22.04

Recommended Article: How to install and use vi as a full text editor

Introduction to PostgreSQL

PostgreSQL is a free and open source database management system based on SQL. This database supports SQL and JSON for its relational and non-relational queries for development with SQL. PostgreSQL can include a variety of advanced information and performance optimized features.

Features Provided in PostgreSQL 12

–> Improved high performance and workloads of distributed data.

–> Query parallelization and logical iteration.

–> Workloads with writing above.

–> Advances in synchronization.

–> Security enhancement.

In the rest of this article, we will teach you step by step how to Install and Connect PostgreSQL 12 on Ubuntu 22.04.

How to Install PostgreSQL on Ubuntu 22.04

First update and upgrade your system:

sudo apt update  sudo apt -y install vim bash-completion wget  sudo apt -y upgrade

Then reboot your system:

sudo reboot

Now import the GPG key using the following command:

curl -fsSL|sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/postgresql.gpg

You must add the new version of PostgreSQL to the default package repositories of the operating system:

apt policy postgresql

Enter the GPG key used to sign the packages:

curl -fsSL|sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/postgresql.gpg

Use the following command to add the PostgreSQL repository on your Ubuntu 22.04:

echo "deb `lsb_release -cs`-pgdg main" |sudo tee /etc/apt/sources.list.d/pgdg.list

Run the command below to inform the system about the newly added repository:

sudo apt update

Now install PostgreSQL 12 on Ubuntu 22.04 with the following command:

sudo apt install postgresql-12 postgresql-client-12

You can check PostgreSQL status using the following command:

systemctl status postgresql.service

To set come up after every system reboot using the following command:

systemctl status [email protected]


How to Test PostgreSQL Connection

Note that a postgres user was created automatically during installation. First, give your account sudo privileges with the following command:

sudo su - postgres  

Now you need to reset user password to a strong password:

psql -c "alter user postgres with password 'StrongAdminPassw0rd'"

Then start PostgreSQL by entering the following command:


To get connection details use the below command:


Now you should create a test database and user with the following command:


To grant all privileges on database mytestdb to mytestuser run the following command:

GRANT ALL PRIVILEGES ON DATABASE mytestdb to mytestuser;

You can list created databases by running the following command:


Then connect to the database by running the following command:

\c mytestdb

You can use createuser to create users:

createuser myuser --password

To use createdb to create database using the following command:

createdb mydb -O myuser

Finally, run the following command:

psql -l
Recommended Article: How to Install and Connect PostgreSQL 12 on Ubuntu 22.04


PostgreSQL is one of the services that maintain databases. In this article, you get acquainted with the new features in PostgreSQL 14 and also learned how to install and connect PostgreSQL 12 on Ubuntu 22.04 and we also examined configuration methods of PostgreSQL 14.

How useful was this post?

Click on a star to rate it!

Average rating 3 / 5. Vote count: 4

No votes so far! Be the first to rate this post.

We Are Waiting for your valuable comments and you can be sure that it will be answered in the shortest possible time.

Leave a Reply

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

We are by your side every step of the way

Think about developing your online business; We will protect it compassionately

We are by your side every step of the way


7 days a week, 24 hours a day