Wednesday, July 3, 2024
HomeOperating SystemsDebianHow To Install PostgreSQL 13 on Debian 11/10/9

How To Install PostgreSQL 13 on Debian 11/10/9

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 11/10/9.

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 11/10/9

If you follow the next steps outlined in this article you should get a running and working installation of PostgreSQL 13 on Debian 10 | Debian 9 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 11/10/9 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 11/10/9:

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; vendor preset: enabled)
     Active: active (running) since Fri 2023-05-26 17:49:01 UTC; 8s ago
    Process: 15304 ExecStart=/usr/bin/pg_ctlcluster --skip-systemctl-redirect 13-main start (code=exited, status=0/SUCCESS)
   Main PID: 15309 (postgres)
      Tasks: 7 (limit: 4553)
     Memory: 17.0M
        CPU: 235ms
     CGroup: /system.slice/system-postgresql.slice/[email protected]
             ├─15309 /usr/lib/postgresql/13/bin/postgres -D /var/lib/postgresql/13/main -c config_file=/etc/postgresql/13/main/postgresql.conf
             ├─15311 postgres: 13/main: checkpointer
             ├─15312 postgres: 13/main: background writer
             ├─15313 postgres: 13/main: walwriter
             ├─15314 postgres: 13/main: autovacuum launcher
             ├─15315 postgres: 13/main: stats collector
             └─15316 postgres: 13/main: logical replication launcher

May 26 17:48:58 debian11 systemd[1]: Starting PostgreSQL Cluster 13-main...
May 26 17:49:01 debian11 systemd[1]: Started PostgreSQL Cluster 13-main.

Step 3: Access PostgreSQL shell

Start PostgreSQL prompt by using the command:

$ sudo su - postgres
postgres@debian:~$ psql
psql (13.11 (Debian 13.11-1.pgdg110+1))
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.11 (Debian 13.11-1.pgdg110+1))
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 11/10/9 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

Nicole Veronica Rubhabha
Nicole Veronica Rubhabha
A highly competent and organized individual DotNet developer with a track record of architecting and developing web client-server applications. Recognized as a personable, dedicated performer who demonstrates innovation, communication, and teamwork to ensure quality and timely project completion. Expertise in C#, ASP.Net, MVC, LINQ, EF 6, Web Services, SQL Server, MySql, Web development,
RELATED ARTICLES

Most Popular

Recent Comments