PostgreSQL is an open-source relational database management system (RDBMS) emphasizing extensibility and SQL compliance.
It is the default database for macOS Server and is also available for Windows, Linux, FreeBSD, and OpenBSD.
PostgreSQL is easy-to-use with a full stack of RDBMS database features and capabilities for handling data. It can be easily installed on Linux environments.
In this context, we shall look into how to install PostgreSQL on Debian 10.
Steps to follow to install PostgreSQL on Debian 10 ?
To get PostgreSQL installed on Debian 10 system, you have to perform all the steps outlined below.
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.
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.
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
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.
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
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:
If your PostgreSQL service is ready, then it will display the "accepting connections" status.
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 run this command, you will notice that the root user will switch to the default PostgreSQL user on the terminal.
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:
This command will display the PostgreSQL shell.
How to uninstall PostgreSQL from Debian 10 ?
Whenever you need to remove PostgreSQL DBMS from Debian 10, as well as its configuration files, then you can execute the following command:
$ sudo apt-get --purge remove postgresql\*
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.
To get rid of all such packages and dependencies, you can run the following command in the terminal:
$ sudo apt-get autoremove
This command will remove all the unused and irrelevant packages and dependencies from your Debian 10 system.