PostgreSQL is an open source, powerful, resilient and fault tolerant relational database management system powering many mission critical applications. PostgreSQL database is based on POSTGRES 4.2. As of this article update the latest stable release of PostgreSQL is version 13. All the new features, improvements and bug fixes report for PostgreSQL 13 is available in the official release page. In this article we will perform the installation of PostgreSQL 13 on Debian 12/11/10.

Here are some notable new features:

  • Improvements from de-duplication of B-tree index entries – Space savings and performance gains from
  • Queries that use aggregates or partitioned tables gets improved performance.
  • Incremental sorting
  • Better query planning when using extended statistics
  • Parallelized vacuuming of indexes

Install PostgreSQL 13 on Debian 12/11/10

If you follow the next steps outlined in this article you should get a running and working installation of PostgreSQL 13 on Debian Linux machine.

It is recommended to update your system and all installed packages before you proceed.

sudo apt update && sudo apt -y upgrade

Reboot the server thereafter.

sudo reboot

Step 1: Add PostgreSQL 13 repository

Before configuring the APT repository import the GPG key used for signing packages:

sudo apt update && sudo apt -y install gnupg2
curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc|sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/postgresql.gpg

After importing GPG key, add PostgreSQL repository to your Debian system.

echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" |sudo tee  /etc/apt/sources.list.d/pgdg.list

Cat the file created to check its contents:

$ cat /etc/apt/sources.list.d/pgdg.list
deb http://apt.postgresql.org/pub/repos/apt/ buster-pgdg main

Step 2: Install PostgreSQL 13 on Debian

Now that the repository has been added successfully update the package list and install PostgreSQL 13 on Debian Linux machine. The server can be running in the cloud, on premise hardware or any other valid virtualization environment.

sudo apt update

And lastly initiate the installation of PostgreSQL 13 on Debian:

sudo apt -y install postgresql-13 postgresql-client-13

Start the database server using the following command:

sudo pg_ctlcluster 13 main start

Confirm service status and the configuration file being used.

$ sudo pg_ctlcluster 13 main status
pg_ctl: server is running (PID: 4209)
/usr/lib/postgresql/13/bin/postgres "-D" "/var/lib/postgresql/13/main" "-c" "config_file=/etc/postgresql/13/main/postgresql.conf"

You can also use systemctl command to check status of the service.

$ systemctl status [email protected]
 [email protected] - PostgreSQL Cluster 13-main
     Loaded: loaded (/lib/systemd/system/[email protected]; enabled-runtime; preset: enabled)
     Active: active (running) since Fri 2024-02-23 07:28:01 UTC; 1min 30s ago
    Process: 4613 ExecStart=/usr/bin/pg_ctlcluster --skip-systemctl-redirect 13-main start (code=exited, status=0/SUCCESS)
   Main PID: 4618 (postgres)
      Tasks: 7 (limit: 2251)
     Memory: 17.7M
        CPU: 369ms
     CGroup: /system.slice/system-postgresql.slice/[email protected]
             ├─4618 /usr/lib/postgresql/13/bin/postgres -D /var/lib/postgresql/13/main -c config_file=/etc/postgresql/13/main/postgresql.conf
             ├─4620 "postgres: 13/main: checkpointer "
             ├─4621 "postgres: 13/main: background writer "
             ├─4622 "postgres: 13/main: walwriter "
             ├─4623 "postgres: 13/main: autovacuum launcher "
             ├─4624 "postgres: 13/main: stats collector "
             └─4625 "postgres: 13/main: logical replication launcher "

Feb 23 07:27:59 deb12 systemd[1]: Starting [email protected] - PostgreSQL Cluster 13-main...
Feb 23 07:28:01 deb12 systemd[1]: Started [email protected] - PostgreSQL Cluster 13-main.

Step 3: Access PostgreSQL shell

Start PostgreSQL prompt by using the command:

$ sudo su - postgres
postgres@debian:~$ psql
psql (13.14 (Debian 13.14-1.pgdg120+2))
Type "help" for help.

postgres=#

Perform test operations:

postgres=# exit
postgres@debian:~$ createuser c4geeks
postgres@debian:~$ createdb testdb -O c4geeks

postgres@debian:~$ psql -l
                                  List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
 postgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
 template0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 testdb    | c4geeks  | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
(4 rows)

Connect to the database:

postgres@debian:~$ psql testdb
psql (13.14 (Debian 13.14-1.pgdg120+2))
Type "help" for help.

testdb=#

Set user password:

testdb=# alter user c4geeks with password 'StrongDBPassw0rd';
ALTER ROLE

Drop the database:

testdb=# \q
postgres@debian:~$ dropdb testdb
postgres@debian:~$ exit
logout

I hope you have a blast developing with PostgreSQL 13 database server on Debian Linux machine.

Recommended books:

More articles on Debian:

Install and Configure Zabbix Server on Debian 10 (Buster)

Install Oracle Java 14 (OpenJDK 14) on UbuntuDebian

How To Join Ubuntu / Debian To Active Directory (AD) domain

2 COMMENTS

LEAVE A REPLY

Please enter your comment!
Please enter your name here