Post­gr­eSQL is an open-source database man­age­ment system. It’s used for everything from small apps to large-scale en­ter­prise systems that require high re­li­ab­il­ity and strong data integrity. In­stalling Post­gr­eSQL on Debian 13 only takes a few steps.

Dedicated Server
Per­form­ance through in­nov­a­tion
  • En­ter­prise hardware
  • Con­fig­ur­able hardware equipment
  • ISO-certified data centres

Step 1: Check the pre­requis­ites

To follow this guide, you’ll need a computer or server running Debian 13 and a user account with either root priv­ileges or with access to ad­min­is­trat­or 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­gr­eSQL packages.

Note

If you are not running Debian 13, you can either perform a new Debian 13 in­stall­a­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 re­pos­it­or­ies. apt upgrade -y updates all installed packages. This helps avoid errors or conflicts when in­stalling Post­gr­eSQL.

Step 3: Install Post­gr­eSQL on Debian 13

With your system updated, install Post­gr­eSQL from the Debian re­pos­it­or­ies:

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 stat­ist­ic­al functions. In­stall­a­tion usually takes just a few seconds.

Step 4: Check the service is running

To confirm that Post­gr­eSQL started suc­cess­fully, 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­gr­eSQL service is running.

To make sure Post­gr­eSQL starts auto­mat­ic­ally whenever the system boots, enable auto-start using:

sudo systemctl enable postgresql
bash

Step 5: Open the Post­gr­eSQL shell

During in­stall­a­tion, Debian auto­mat­ic­ally creates a special Linux user called postgres. This account is the default Post­gr­eSQL ad­min­is­trat­or. 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­gr­eSQL 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­gr­eSQL shell.

Step 6: Create a new user and database

Inside the Post­gr­eSQL 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­fully, Post­gr­eSQL returns the CREATE ROLE and CREATE DATABASE messages.

Step 7: Test the setup

To check if the new user works, exit the Post­gr­eSQL 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­gr­eSQL shell again – this time logged in as ‘appuser’ in the ‘appdb’ database.

Once you connect suc­cess­fully, Post­gr­eSQL is fully installed on Debian 13. From here, you can create ad­di­tion­al databases, define tables and build your ap­plic­a­tions as required.

Go to Main Menu