How to Install PostgreSQL on Debian 13

How to Install PostgreSQL on Debian 13

This blog post will show you how to install PostgreSQL on Debian 13 OS. PostgreSQL, or Postgres, is a free and open-source relational database management system (RDBMS) for storing data. It is also supported on operating systems such as Windows, macOS, OpenBSD, and Linux. PostgreSQL offers many features, such as consistency, isolation, durability, and atomicity. This tutorial will cover the installation, service management, and some basic PostgreSQL commands in the Postgres terminal.

Installing PostgreSQL is a straightforward procedure that takes a few minutes. Let’s get started!

Prerequisites

Update the system

Before installing PostgreSQL, we will update the packages to the latest available versions. To do that, execute the following command:

sudo apt update -y && sudo apt upgrade -y

Install the PostgreSQL database server

The PostgreSQL package is already added to the repository of Debian 13. To install PostgreSQL, execute the following command:

sudo apt install postgresql -y

Once installed, check the PostgreSQL version with the command below:

psql --version

You should receive output similar to this:

root@host:~# psql --version
psql (PostgreSQL) 17.4 (Debian 17.4-2)

Manage the PostgreSQL service

To start and enable the PostgreSQL service for an automatic start after the system boot, execute the following command:

sudo systemctl start postgresql && sudo systemctl enable postgresql

Once the service is enabled, you should see the following output:

Synchronizing state of postgresql.service with SysV service script with /usr/lib/systemd/systemd-sysv-install.
Executing: /usr/lib/systemd/systemd-sysv-install enable postgresql

To check the status of the PostgreSQL service, you can use the following command:

sudo systemctl status postgresql

You should get output similar to this:

root@host:~# sudo systemctl status postgresql
● postgresql.service - PostgreSQL RDBMS
     Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; preset: enabled)
     Active: active (exited) since Fri 2025-05-02 17:51:53 CDT; 19s ago
 Invocation: 9bbafb1bbbd4445f904e054e010fee8c
   Main PID: 32969 (code=exited, status=0/SUCCESS)
   Mem peak: 1.5M
        CPU: 20ms

May 02 17:51:53 host.test.vps systemd[1]: Starting postgresql.service - PostgreSQL RDBMS...
May 02 17:51:53 host.test.vps systemd[1]: Finished postgresql.service - PostgreSQL RDBMS.

The PostgreSQL service can be restarted with the command below:

sudo systemctl restart postgresql

To stop the PostgreSQL service, you can use the following command:

sudo systemctl stop postgresql

That’s all for managing the PostgreSQL service. In the following paragraph, you will learn some basic PostgreSQL commands.

PostgreSQL Commands

To log in to the PostgreSQL command line with the main “postgres” user, execute the following command:

sudo -u postgres psql

Once logged in, you will be redirected to the PostgreSQL terminal:

root@host:~# sudo -u postgres psql
psql (17.4 (Debian 17.4-2))
Type "help" for help.

postgres=#

Once logged in, you can start to use the PostgreSQL commands. For example, to list the databases, you can use the \l command:

postgres=# \l
                                                     List of databases
   Name    |  Owner   | Encoding | Locale Provider |   Collate   |    Ctype    | Locale | ICU Rules |   Access privileges
-----------+----------+----------+-----------------+-------------+-------------+--------+-----------+-----------------------
 postgres  | postgres | UTF8     | libc            | en_US.UTF-8 | en_US.UTF-8 |        |           |
 template0 | postgres | UTF8     | libc            | en_US.UTF-8 | en_US.UTF-8 |        |           | =c/postgres          +
           |          |          |                 |             |             |        |           | postgres=CTc/postgres
 template1 | postgres | UTF8     | libc            | en_US.UTF-8 | en_US.UTF-8 |        |           | =c/postgres          +
           |          |          |                 |             |             |        |           | postgres=CTc/postgres
(3 rows)

postgres=#

To create a new database, execute the command below:

create database rhdb;

If the database is successfully created, you will get the following output:

postgres=# create database rhdb;
CREATE DATABASE

To create the user and set a password for that user, execute the command below:

CREATE USER rhuser WITH PASSWORD 'StrongPasswordHere';

After successful creation, you will receive the following:

postgres=# CREATE USER rhtest WITH PASSWORD 'StrongPasswordHere';
CREATE ROLE

To grant permissions on the database for the user, you can use the following command:

grant all privileges on database rhdb to rhuser;

After successfully granting permissions, you will receive the following:

postgres=# grant all privileges on database rhdb to rhuser;
GRANT

That’s it. You successfully installed PostgreSQL on Debian 13 OS. Of course, you do not have to install it yourself if you are unfamiliar with databases and Linux. You can always contact our technical support, which will help you with any PostgreSQL installation and configuration aspect. You just need to sign up for one of our NVMe VPS hosting plans and submit a support ticket. We are available 24/7.

PS. If you liked this post on installing PostgreSQL on Debian 13, please share it with your friends or leave a comment below. Thanks.

Leave a Comment