How to Install PostgreSQL on Debian 12: Easy Guide

How to Install PostgreSQL on Debian 12

Do you want to install PostgreSQL on Debian 12? You are at the right place!

PostgreSQL is an open-source database system that helps to store and manage data. It is known for its reliability, flexibility, and support of various applications. PostgreSQL is often used because it can handle large amounts of data and offers many features for building and running databases efficiently.

In this guide, we will cover the installation and configuration of PostgreSQL on Debian 12.

So let’s start the guide!

How to Install PostgreSQL on Debian 12

Use the following steps to install PostgreSQL on Debian 12.

First of all, update the Debian’s packages list:

sudo apt update
Updating Debian Repository

Now, use the command below to add the official PostgreSQL repository to your system and allow it to install PostgreSQL and its updates directly via APT:

sudo sh -c 'echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'

After that, insert the PostgreSQL signing key:

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

Update the Debian 12 repository again to save the changes made:

sudo apt update
Adding PostgreSQL Repository on Debian

As all the requirements have been fulfilled, PostgreSQL is all set to be installed on your Debian 12 system, use the below command to install it:

sudo apt install postgresql-16
installing the PostgreSQL 16 server

As PostgreSQL has been successfully installed. Start, enable, and check its status using the following commands:

sudo systemctl start postgresql.service
sudo systemctl enable postgresql.service 
sudo systemctl status postgresql.service
Configuring PostgreSQL on Debian

You can also verify the installation of PostgreSQL by opening the PostgreSQL terminal for database management:

sudo su postgres
cd
psql
Verifying PostgreSQL Installation

Conclusion

This guide demonstrated how to install PostgreSQL 16 on Debian 12. We started by updating the package list, adding the PostgreSQL APT repository, inserting the signing key, and installing PostgreSQL. 

We also showed how to start, enable, and check the PostgreSQL service status, and verified the installation by accessing the PostgreSQL terminal.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top
Scroll to Top