Debian

How to Install PostgreSQL on Debian 10

Install PostgreSQL on Debian 10

Introduction:

PostgreSQL is a very famous free and open-source relational database management system (DBMS) that was developed in 1996 and is still very extensively used. It is written in C programming language. The main reason behind using this relational DBMS is its support for all the three major operating systems i.e. Linux, macOS, and Windows along with some other minor operating systems. In today’s article, our focus will be on the method of installing PostgreSQL on Debian 10.

Method of Installing PostgreSQL on Debian 10:

For installing PostgreSQL on your Debian 10 system, you have to perform all the steps that we have listed below:

Step # 1: Update your Debian 10 System:

Since we are going to install a new database management system (DBMS) on our Debian 10 system that is why we have to update our system’s cache first with the help of the following command:

sudo apt update

Once our Debian 10 system will finish the update, it will display the number of packages to be upgraded as shown in the image below:

Step # 2: Install PostgreSQL on your Debian 10 System:

After updating our Debian 10 system, we are good to go with the installation of PostgreSQL on it. It can be installed by running the following command:

sudo apt install postgresql postgresql-contrib

The PostgreSQL DBMS will take a few minutes to install on Debian 10 along with all of its required packages and dependencies. Once it is installed, your terminal will allow you to proceed further as shown in the image below:

Step # 3: Check the Version of the Installed PostgreSQL on your Debian 10 System:

After installing PostgreSQL on Debian 10, you can check out its version by executing the following command:

psql --version

The version of PostgreSQL installed on our Debian 10 system is shown in the image below:

Step # 4: Start the PostgreSQL Service on Debian 10:

In some Linux distributions, the PostgreSQL service starts automatically, however, you can always start it manually by issuing the following command in your Debian 10 system:

sudo systemctl start postgresql

If the PostgreSQL service is started without any potential issues, then you will not face any error messages as shown in the image below:

Step # 5: Check the Status of the PostgreSQL Service on Debian 10:

After starting the PostgreSQL service on your Debian 10 system, you can check its status by running the following command:

sudo systemctl status postgresql

The status of the PostgreSQL service on our Debian 10 system is shown in the image below:

Step # 6: Check whether PostgreSQL is Accepting New Connections or not:

Additionally, you can also check whether your PostgreSQL DBMS is accepting new connections or not. This can be done by running the following command:

pg_isready

If your PostgreSQL service will be ready, then it will display the “accepting connections” status as shown in the image below:

Step # 7: Switch to the Default User Account of PostgreSQL in Debian 10:

Now the next step is to access the PostgreSQL shell for which we have to switch to its default user account. When you install the PostgreSQL DBMS, a user account named “postgres” is created by default. We can switch to that account by running the following command:

sudo su – postgres

When you will run this command, you will notice that the root user will switch to the default PostgreSQL user on the terminal as shown in the image below:

Step # 8: Enter the PostgreSQL Shell in Debian 10:

Once you have switched to the default PostgreSQL user account in Debian 10, you can easily enter its shell by issuing the following command in the terminal:

psql

The PostgreSQL shell is shown in the image below:

Method of Removing PostgreSQL from Debian 10:

After getting your work done with the PostgreSQL DBMS in Debian 10, if you ever wish to remove this DBMS along with all of its configuration files, then you can execute the following command:

sudo apt-get --purge remove postgresql\*

Once the PostgreSQL DBMS is removed from your Debian 10 system, it will display these messages on your terminal:

Now when the PostgreSQL DBMS is removed successfully from your Debian 10 system, then you would no longer need those packages and dependencies that were installed automatically with this DBMS. For getting rid of all such packages and dependencies, you can run the following command in the terminal:

sudo apt-get autoremove

Once this command has removed all the unused and irrelevant packages and dependencies from your Debian 10 system, you will be displayed with the output shown in the image below on your terminal:

Conclusion:

In this article, we provided you with a brief introduction to the PostgreSQL DBMS. Then we explained to you step by step how you can install this extremely useful DBMS on your Debian 10 system. Finally, we also shared with you the method with which you can remove the PostgreSQL DBMS from your Debian 10 system.

Similar Posts