Hello, friends. In this post, you will learn how to install PostgreSQL on Debian 11.
PostgreSQL is one of the oldest and most powerful relational database managers available today. And although MariaDB is emerging as one of the most popular along with SQLite, PostgreSQL is also the best known.
So if you are a developer, it would be convenient to know how to install it and get it ready for development.
Install PostgreSQL on Debian 11
PostgreSQL is included in the Debian 11 repositories, so the installation is effortless. However, in this post, we will help you to get the latest stable version.
So, open a terminal or via SSH connect to your server. Once you have the terminal, update the system.
sudo apt update sudo apt upgrade
Then, install some necessary packages. Most likely they are already there, but better to be certain.
sudo apt install curl apt-transport-https
Add the GPG key from the PostgreSQL repository:
curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo gpg --dearmor -o /usr/share/keyrings/postgresql-keyring.gpg
Next, add the PostgreSQL repository to the system:
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
After this, refresh APT
sudo apt update
Finally, install PostgreSQL
sudo apt install postgresql-15
By default, it will be started and enabled to start with the system. You can verify this by running.
systemctl status postgresql
Configuring PostgreSQL on Debian 11
There is not too much to configure to get it set up. The first thing is that PostgreSQL listens by default on
127.0.0.1 so if you use it on a server or virtual machine you have to change this.
Open the configuration file:
sudo nano /etc/postgresql/15/main/postgresql.conf
listen_addresses and add the IP address of the machine or use the wildcard
listen_addresses = '192.168.1.55'.
Save the changes and close the editor.
Restart it to apply the changes
sudo systemctl restart postgresql
Now you can access the PostgreSQL console
sudo -u postgres psql
The previous command, what it does is that from the user
postgres it executes
Once inside the console, you can use
psql psql (15.2 (Debian 15.2-1.pgdg110+1)) Type "help" for help.
PostgreSQL is a jewel of open source and the father of many great projects, and it is always good to have it at hand.