Install PostgreSQL 13 on Debian 10 | Debian 9

You can download this article in PDF format via the link below to support us.
Download the guide in PDF formatturn off

PostgreSQL is an open source, powerful, resilient and fault-tolerant relational database management system that can provide support for many mission-critical applications. The PostgreSQL database is based on POSTGRES 4.2. As of the update of this article, the latest stable version of PostgreSQL is version 13. All new features, improvements and bug fix reports of PostgreSQL 13 are provided in the official version. freed page.

Here are some notable new features:

  • Improvements brought by deduplication of B-tree index entries-space saving and performance improvement
  • Queries that use aggregate tables or partitioned tables can improve performance.
  • Incremental sort
  • Better query plans when using extended statistics
  • Parallel cleanup of indexes

Install PostgreSQL 13 on Debian 10 | Debian 9

If you follow the next steps outlined in this article, you should get a working and runnable PostgreSQL 13 installation on Debian 10. Debian 9 Linux machine.

It is recommended that you update the system and all installed packages before proceeding.

sudo apt update
sudo apt -y upgrade

Restart the server afterwards.

sudo reboot

Step 2: Add PostgreSQL 12 repository

Before configuring the APT repository, import the GPG key used to sign the package:

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

After importing the GPG key, add the 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

Organize the created file to check its content:

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

Step 3: Install PostgreSQL 13 on Debian 10 | Debian 9

Now that the repository has been successfully added, the package list has been updated, and PostgreSQL 13 has been installed on the Debian 10 / Debian 9 Linux machine. The server can run in the cloud, local hardware or any other effective virtualized environment.

sudo apt update

Finally, start the installation of PostgreSQL 13 on Debian 10 | Debian 9:

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

Start the database server with the following command:

sudo pg_ctlcluster 13 main start

Confirm the service status and the profile 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 the systemctl command to check the service status.

$ 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 2020-10-30 11:27:01 CET; 2min 11s ago
 Main PID: 4209 (postgres)
    Tasks: 7 (limit: 4580)
   Memory: 18.1M
   CGroup: /system.slice/system-postgresql.slice/[email protected]
           ├─4209 /usr/lib/postgresql/13/bin/postgres -D /var/lib/postgresql/13/main -c config_file=/etc/postgresql/13/main/postgresql.conf
           ├─4211 postgres: 13/main: checkpointer
           ├─4212 postgres: 13/main: background writer
           ├─4213 postgres: 13/main: walwriter
           ├─4214 postgres: 13/main: autovacuum launcher
           ├─4215 postgres: 13/main: stats collector
           └─4216 postgres: 13/main: logical replication launcher

Oct 30 11:26:59 debian systemd[1]: Starting PostgreSQL Cluster 13-main...
Oct 30 11:27:01 debian systemd[1]: Started PostgreSQL Cluster 13-main.

Start the PostgreSQL prompt with the following command:

$ sudo su - postgres
[email protected]:~$ psql
psql (13.0 (Debian 13.0-1.pgdg100+1))
Type "help" for help.

postgres=#

Perform test operations:

postgres=# exit
[email protected]:~$ createuser c4geeks
[email protected]:~$ createdb testdb -O c4geeks

[email protected]:~$ 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:

[email protected]:~$ psql testdb
psql (13.0 (Debian 13.0-1.pgdg100+1))
Type "help" for help.

testdb=#

Set user password:

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

Delete the database:

testdb=# q
[email protected]:~$ dropdb testdb

I hope you use PostgreSQL 13 database server for development on Debian Linux machine.

More articles about 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

You can download this article in PDF format via the link below to support us.
Download the guide in PDF formatturn off

Sidebar