How To Install PostgreSQL 16 on Debian 12

In this guide, we will show you how to install PostgreSQL 16 on Debian 12. Frequently referred to as Postgres, PostgreSQL is a relational database management system (RDBMS) that emphasizes flexibility and SQL conformance. PostgreSQL is capable of handling both relational SQL and non-relational JSON querying.

Features of PostgreSQL 16

  • Subscriptions can be made by non-superusers.
  • The pre-defined collations Unicode and ucs_basic now have support.
  • The effectiveness of relation extension has improved.
  • During replication, data can be filtered according to origin.
  • Allow the analyze/vacuum command to specify a buffer consumption cap.
  • A list of approved authentication procedures can now be specified using the new libpq connection option require_auth.
  • During vacuum, allow freezing at page level.
  • The support for text collations, which establish rules for sorting text, has been enhanced.
  • Delegation of Kerberos credentials is now supported.

Install PostgreSQL 16 on Debian 12

The following procedures will guide on how to install PostgreSQL 16 on Debian 12.

Update Debian 12

Run the following commands to Debian 12 system;

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

Add PostgreSQL repositories on Debian 12

Configure the file repository;

sudo sh -c 'echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'

Import the repository signing key;

wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

Update the package lists;

sudo apt update

Install PostgreSQL 16 on Debian 12

Run the following command to install PostgreSQL 16;

sudo apt install postgresql-16

Accept the installation prompt;

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  libcommon-sense-perl libdpkg-perl libjson-perl libjson-xs-perl libllvm14 libpq5 libtypes-serialiser-perl postgresql-client-16 postgresql-client-common postgresql-common sysstat
Suggested packages:
  debian-keyring gcc | c-compiler binutils patch git bzr postgresql-doc-16 isag
Recommended packages:
  libfile-fcntllock-perl
The following NEW packages will be installed:
  libcommon-sense-perl libjson-perl libjson-xs-perl libllvm14 libpq5 libtypes-serialiser-perl postgresql-16 postgresql-client-16 postgresql-client-common postgresql-common sysstat
The following packages will be upgraded:
  libdpkg-perl
1 upgraded, 11 newly installed, 0 to remove and 5 not upgraded.
Need to get 43.3 MB of archives.
After this operation, 181 MB of additional disk space will be used.
Do you want to continue? [Y/n] y

After successful installation of PostgreSQL, enable and start the service;

sudo systemctl enable --now [email protected]

Check the status of PostgreSQL service;

systemctl status [email protected]

Output;

[email protected] - PostgreSQL Cluster 16-main
     Loaded: loaded (/lib/systemd/system/[email protected]; enabled; preset: enabled)
     Active: active (running) since Fri 2023-09-15 14:55:09 EDT; 1min 21s ago
   Main PID: 16904 (postgres)
      Tasks: 6 (limit: 5827)
     Memory: 19.4M
        CPU: 287ms
     CGroup: /system.slice/system-postgresql.slice/[email protected]
             ├─16904 /usr/lib/postgresql/16/bin/postgres -D /var/lib/postgresql/16/main -c config_file=/etc/postgresql/16/main/postgresql.conf
             ├─16905 "postgres: 16/main: checkpointer "
             ├─16906 "postgres: 16/main: background writer "
             ├─16908 "postgres: 16/main: walwriter "
             ├─16909 "postgres: 16/main: autovacuum launcher "
             └─16910 "postgres: 16/main: logical replication launcher "

Sep 15 14:55:07 itnixpro systemd[1]: Starting [email protected] - PostgreSQL Cluster 16-main...
Sep 15 14:55:09 itnixpro systemd[1]: Started [email protected] - PostgreSQL Cluster 16-main.

You can also stop PostgreSQL service as follows;

systemctl stop [email protected]

Secure PostgreSQL 16 Database on Debian 12

Access the PostgreSQL CLI;

sudo -Hiu postgres psql

Output;

psql (16.0 (Debian 16.0-1.pgdg120+1))
Type "help" for help.

postgres=# 

Set your Strong Password;

postgres=# ALTER USER postgres PASSWORD 'Str0ngPassw0rd';
ALTER ROLE
postgres=# 

Exit PostgreSQL console;

postgres=# \q

Or you can just type “exit” to exit the console.

The End!

This is the end of our guide on how to install PostgreSQL 16 on Debian 12. You have also learned how to perform some of the PostgreSQL 16 service management.

Install PostgreSQL on Rocky Linux

Install PostgreSQL on FreeBSD 13

Install PostgreSQL on Fedora 36

Install PostgreSQL on Ubuntu 22.04

Leave a Comment