PostgreSQL is also known as Postgres, an open-source and powerful objects-based relational database system that is used and combined with many features of SQL language. Using the Postgres database, you can easily store and scale the complicated data workload. Most of the mobile and web applications used the Postgres database for storing data. Postgres database can be installed on almost all operating systems including Linux.
Here at Ibmi Media, we shall look into the procedure to follow in order to install Postgres or PostgreSQL 14 on the Debian 11 system using the command line method.
You can follow the steps here to Install PostgreSQL 13 on Debian 11: https://linuxapt.com/blog/733-install-postgresql-13-on-debian-11
1. Install Prerequisites
To begin, update the system repositories list using the 'apt' command:
$ sudo apt update
Now, install the recommended HTTPS support packages by executing the below-mentioned command:
$ sudo apt install -y curl apt-transport-https
2. Add repository of PostgreSQL
By default, the PostgreSQL packages are not included in the Debian 11 repository. However, you can install the required packages by adding the PostgreSQL repository to your Debian system. So, download or import the signing key of the PostgreSQL repository by using the following command:
$ curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo gpg --dearmor -o /usr/share/keyrings/postgresql-keyring.gpg
Add the PostgreSQL repository to your Debian 11 system by executing the below-mentioned command:
$ echo "deb [signed-by=/usr/share/keyrings/postgresql-keyring.gpg] http://apt.postgresql.org/pub/repos/apt/ bullseye-pgdg main" | sudo tee /etc/apt/sources.list.d/postgresql.list
3. Install PostgreSQL on Debian 11
Once the repository is included, install the PostgreSQL on Debian 11 system. The following syntax will help you to install the desired PostgreSQL version on your system:
$ sudo apt update
$ sudo apt install -y postgresql-version
Here, we are installing the latest PostgreSQL-14 on this system. Therefore, this command will be changed into the following order:
$ sudo apt install -y postgresql-14
The '-y' option will allow you to ignore the confirmation prompt on your terminal window.
Once the Postgres installation is completed, the service of PostgreSQL will automatically start on your system.
Verify the 'Active' or excited status of Postgres service by running the below-mentioned command:
$ sudo systemctl status postgresql
If you did not receive the 'Active' status of the PostgreSQL service then, you can enable and start the PostgreSQL services by running the following command:
$ sudo systemctl enable postgresql
$ sudo systemctl start postgresql
Once the postgreSQL installation is completed on your system, it creates by default a user with the name 'Postgres' that you can find in the /etc/passwd file:
$ cat /etc/passwd | grep -i postgres
The postgreSQL listens at the localhost port '127.0.0.1' by default. but, you change it with your system IP address:
$ sudo nano /etc/postgresql/14/main/postgresql.conf
Change the listen_addresses to your <IPAddress> or * symbol:
listen_addresses = 'IP-Address'
Now, restart the postgreSQL service on your system:
$ sudo systemctl restart postgresql
Login as a 'postgres' user to the postgres database by using the below-mentioned command:
$ sudo -u postgres psql
Now, we can use the PostgreSQL database through the psql commands:
$ psql
This article covers how to install PostgreSQL 14 on the Debian 11 system. In fact, you can easily create the postgreSQL databases on your system. You can follow the steps here to install the PostgreSQL on Ubuntu: https://linuxapt.com/blog/1188-install-postgresql-on-ubuntu-20-04 .
With PostgreSQL 14 installed on your Ubuntu 20.04 system, you can now comfortably use it to steer your database-powered apps or projects to new heights.