Advance

Tutorial Install PostgreSQL in Ubuntu 21.04

Tutorial Install PostgreSQL in Ubuntu 21.04

PostgreSQL is simply a database management system or DBMS that is optimized for different types of operating systems. PostgreSQL can be installed and serviced on various models of operating systems such as Windows, Linux, and macOS. In this article, we are going to teach you about Tutorial Install PostgreSQL in Ubuntu 21.04 step by step. You can visit the packages available in Eldernode if you wish to purchase an Ubuntu VPS server.

How to Install PostgreSQL in Ubuntu 21.04

PostgreSQL is one of the most advanced general-purpose database management systems and it should be added that its code is open source. In the next section, we will have a definition of PostgreSQL. Then we will teach you to step by step how to install PostgreSQL on Ubuntu 21.04, which is the latest release of Ubuntu. We will then teach you how to configure PostgreSQL, and finally, explain how to access it. Please stay tuned for the rest of this article.

Recommended Article: How to install R on Ubuntu 20.04

What is PostgreSQL?

PostgreSQL database, which is referring to as Postgres in some sources, is one of the most powerful open source databases in the world with an emphasis on flexibility and compliance with standards.

PostgreSQL is developed by the PostgreSQL Global Development Team, which includes a large number of volunteers. It should note that the PostgreSQL database is an object-relational database management system that is optimizing for different types of operating systems. It can also be installed and serviced on various models of operating systems such as Windows, Linux, and macOS.

To install PostgreSQL on Ubuntu 21.04, you can use the following steps to do so.

Install PostgreSQL in Ubuntu 21.04 | 20.04

In this section, we want to teach you how to Install PostgreSQL in Ubuntu 21.04. To do this, just run the following commands in order. First, you need to import PostgreSQL’s signing key using the following command:

wget -q https://www.postgresql.org/media/keys/ACCC4CF8.asc -O- | sudo apt-key add -

Then in the next step, you have to add the PostgreSQL repository information to the Postgresql.list file using the following command:

echo "deb [arch=amd64] http://apt.postgresql.org/pub/repos/apt/ focal-pgdg main" | sudo tee /etc/apt/sources.list.d/postgresql.list

At this point you can run the following command to update the repository list:

sudo apt update

You can now easily install PostgreSQL by running the following command:

sudo apt install -y postgresql-12

Note that by default, the PostgreSQL service starts automatically after installation. So you can check the status of the PostgreSQL service by running the following command:

sudo systemctl status postgresql

Note: In the above command, you should replace status with start, stop, restart to start, stop, and restart PostgreSQL service respectively.

How to Configure PostgreSQL in Ubuntu 21.04

In this section, we are going to teach you how to configure PostgreSQL. Note that the PostgreSQL server listens by default on localhost (127.0.0.1). So you need to configure PostgreSQL from time to time to listen in all the adapters or the IP address of the system to allow applications hosted on external machines to connect to the database.

Open the configuration file using the editor you want:

sudo nano /etc/postgresql/12/main/postgresql.conf

In the next step, you need to set listen_addresses to * or <IPAddress>.

listen_addresses = '*'

After making the changes, you should now restart PostgreSQL with the following command:

sudo systemctl restart postgresql

Finally, you can verify that PostgreSQL is listening on port 5432 using the following command:

sudo netstat -antup | grep 5432

How to Access PostgreSQL on Ubuntu 21.04

After you have successfully installed and configured PostgreSQL according to the instructions in the previous sections, we now want to teach you how to access it. You must first log in as a Postgres user to manage the database:

sudo su -l postgres

Then you can easily use the following command to enter the interactive shell to work with the PostgreSQL database:

psql

You can use the following command to write a database:

postgres=# CREATE DATABASE test;

You can also create a user using the following command:

postgres=# CREATE USER Michael WITH SUPERUSER LOGIN PASSWORD 'password';

After completing the previous steps, you can now use the following command to check if the user is created or not:

postgres=# \du

You can also use the following command to list databases:

postgres=# \l

You can log in to the database using the following command:

psql -h localhost -d test -U Michael
Recommended Article: How to Install WebSploit On Ubuntu 20.04

Conclusion

In addition to databases, there are services that maintain databases. These services are calling database management systems or DBMS. One of these DBMSs is called PostgreSQL. In this article, we tried to teach you how to Install PostgreSQL in Ubuntu 21.04 after introducing PostgreSQL. We then taught you how to configure and access PostgreSQL.

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

Leave Your Comment

Your email address will not be published.

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

+18054214518

7 days a week, 24 hours a day