Post­greSQL is an open-source database man­age­ment system. It’s used for every­thing from small apps to large-scale en­ter­prise systems that require high re­li­a­bil­i­ty and strong data integrity. In­stalling Post­greSQL on Debian 13 only takes a few steps.

Dedicated Servers
Per­for­mance through in­no­va­tion
  • Dedicated en­ter­prise hardware
  • Con­fig­urable hardware equipment
  • ISO-certified data centers

Step 1: Check the pre­req­ui­sites

To follow this guide, you’ll need a computer or server running Debian 13 and a user account with either root priv­i­leges or with access to ad­min­is­tra­tor commands via the sudo group. If your account doesn’t have sudo rights yet, log in as root and add the user to the sudo group with the command usermod -aG sudo <USERNAME>. Then log out and back in so the change takes effect. You’ll also need a stable internet con­nec­tion to download the necessary Post­greSQL packages.

Note

If you are not running Debian 13, you can either perform a new Debian 13 in­stal­la­tion or upgrade from Debian 12 to Debian 13.

Step 2: Update the system

Since you are in­stalling new software, first make sure your system is up to date. To do this, run the following commands in the terminal:

sudo apt update
sudo apt upgrade -y
bash

apt update refreshes the package lists with the most recent versions available in the repos­i­to­ries. apt upgrade -y updates all installed packages. This helps avoid errors or conflicts when in­stalling Post­greSQL.

Step 3: Install Post­greSQL on Debian 13

With your system updated, install Post­greSQL from the Debian repos­i­to­ries:

sudo apt install -y postgresql postgresql-contrib
bash

The postgresql package contains the database server itself. postgresql-contrib includes useful ex­ten­sions like advanced text search and sta­tis­ti­cal functions. In­stal­la­tion usually takes just a few seconds.

Step 4: Check the service is running

To confirm that Post­greSQL started suc­cess­ful­ly, check its service status:

sudo systemctl status postgresql
bash

If the output shows active (running), the server is running. If not, start it manually with sudo systemctl start postgresql.

Image: Image: Screenshot of the PostgreSQL service status
The green ‘active’ status confirms that your Post­greSQL service is running.

To make sure Post­greSQL starts au­to­mat­i­cal­ly whenever the system boots, enable auto-start using:

sudo systemctl enable postgresql
bash

Step 5: Open the Post­greSQL shell

During in­stal­la­tion, Debian au­to­mat­i­cal­ly creates a special Linux user called postgres. This account is the default Post­greSQL ad­min­is­tra­tor. To work with the database, switch to this user and start the shell:

sudo -i -u postgres
psql
bash

The first command switches you to the “postgres” account. The second starts the Post­greSQL command line interface, where the prompt changes to postgres=#. From here, you can run SQL commands.

Image: Image: Screenshot of the PostgreSQL Shell
The “postgres=#” entry shows you are in the Post­greSQL shell.

Step 6: Create a new user and database

Inside the Post­greSQL shell, you can create your own database and a user account to manage it. For example, the following command creates a new user called “appuser” with a secure password:

CREATE ROLE appuser WITH LOGIN PASSWORD 'SecurePassword123';
sql

Next, create a database owned by this user:

CREATE DATABASE appdb OWNER appuser;
sql

This sets up a database named “appdb” managed by “appuser”. This user can now create tables and store data in it.

If the commands run suc­cess­ful­ly, Post­greSQL returns the CREATE ROLE and CREATE DATABASE messages.

Step 7: Test your setup

To check if the new user works, exit the Post­greSQL shell with: \q. Then connect to the new database as “appuser” using:

psql -U appuser -d appdb
bash

You’ll be prompted for the password you set earlier. After entering it, you’ll see the Post­greSQL shell again — this time logged in as “appuser” in the “appdb” database.

Once you connect suc­cess­ful­ly, Post­greSQL is fully installed on Debian 13. From here, you can create ad­di­tion­al databases, set up tables and build your ap­pli­ca­tions as needed.

Go to Main Menu