PostgreSQL is an open-source database management system. It’s used for everything from small apps to large-scale enterprise systems that require high reliability and strong data integrity. Installing PostgreSQL on Debian 13 only takes a few steps.

Dedicated Servers
Performance through innovation
  • Dedicated enterprise hardware
  • Configurable hardware equipment
  • ISO-certified data centers

Step 1: Check the prerequisites

To follow this guide, you’ll need a computer or server running Debian 13 and a user account with either root privileges or with access to administrator 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 connection to download the necessary PostgreSQL packages.

Note

If you are not running Debian 13, you can either perform a new Debian 13 installation or upgrade from Debian 12 to Debian 13.

Step 2: Update the system

Since you are installing 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 repositories. apt upgrade -y updates all installed packages. This helps avoid errors or conflicts when installing PostgreSQL.

Step 3: Install PostgreSQL on Debian 13

With your system updated, install PostgreSQL from the Debian repositories:

sudo apt install -y postgresql postgresql-contrib
bash

The postgresql package contains the database server itself. postgresql-contrib includes useful extensions like advanced text search and statistical functions. Installation usually takes just a few seconds.

Step 4: Check the service is running

To confirm that PostgreSQL started successfully, 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 PostgreSQL service is running.

To make sure PostgreSQL starts automatically whenever the system boots, enable auto-start using:

sudo systemctl enable postgresql
bash
VPS Hosting
VPS hosting at unbeatable prices on Dell Enterprise Servers
  • 1 Gbit/s bandwidth & unlimited traffic
  • Minimum 99.99% uptime & ISO-certified data centers
  • 24/7 premium support with a personal consultant

Step 5: Open the PostgreSQL shell

During installation, Debian automatically creates a special Linux user called postgres. This account is the default PostgreSQL administrator. 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 PostgreSQL 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 PostgreSQL shell.

Step 6: Create a new user and database

Inside the PostgreSQL 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 successfully, PostgreSQL returns the CREATE ROLE and CREATE DATABASE messages.

Step 7: Test your setup

To check if the new user works, exit the PostgreSQL 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 PostgreSQL shell again — this time logged in as “appuser” in the “appdb” database.

Once you connect successfully, PostgreSQL is fully installed on Debian 13. From here, you can create additional databases, set up tables and build your applications as needed.

Was this article helpful?
Go to Main Menu