# How to install PostgreSQL on Debian 13 step by step

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.

## 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](https://www.ionos.com/digitalguide/server/configuration/linux-sudo-command/) 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](https://www.ionos.com/digitalguide/server/know-how/postgresql/) packages.

Note If you are not running Debian 13, you can either perform a new [Debian 13 installation](https://www.ionos.com/digitalguide/server/configuration/install-debian-13/) or upgrade from Debian 12 to [Debian 13](https://www.ionos.com/digitalguide/server/configuration/debian-13-upgrade/).

## 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:

```bash
sudo apt update
sudo apt upgrade -y
```

`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:

```bash
sudo apt install -y postgresql postgresql-contrib
```

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:

```bash
sudo systemctl status postgresql
```

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](https://www.ionos.com/digitalguide/fileadmin/_processed_/0/1/csm_debian-13-postgresql-status_c36d69f11f.webp "Image: Screenshot of the PostgreSQL service status")](https://www.ionos.com/digitalguide/fileadmin/DigitalGuide/Screenshots_2025/debian-13-postgresql-status.jpg) 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:

```bash
sudo systemctl enable postgresql
```

## 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:

```bash
sudo -i -u postgres
psql
```

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](https://www.ionos.com/digitalguide/server/know-how/what-is-sql/) commands.

[![Image: Image: Screenshot of the PostgreSQL Shell](https://www.ionos.com/digitalguide/fileadmin/_processed_/9/4/csm_debian-13-postgresql-shell-en_0b0e911bb2.webp "Image: Screenshot of the PostgreSQL Shell")](https://www.ionos.com/digitalguide/fileadmin/DigitalGuide/Screenshots_2025/debian-13-postgresql-shell-en.jpg) 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](https://www.ionos.com/digitalguide/server/security/protect-sensitive-data-with-a-strong-password/):

```sql
CREATE ROLE appuser WITH LOGIN PASSWORD 'SecurePassword123';
```

Next, create a database owned by this user:

```sql
CREATE DATABASE appdb OWNER appuser;
```

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:

```bash
psql -U appuser -d appdb
```

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.


This is a markdown version of: [https://www.ionos.com/digitalguide/server/configuration/how-to-install-postgresql-on-debian-13/](https://www.ionos.com/digitalguide/server/configuration/how-to-install-postgresql-on-debian-13/) for AI/LLM consumption.