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 2: Add PostgreSQL 13 repository to Debian 11/10/9
Before configuring the APT repository import the GPG key used for signing packages:
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 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 3: Install PostgreSQL 13 on Debian 11/10/9
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 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 PostgreSQL prompt by using the command:
$ sudo su - postgres
[email protected]:~$ psql
psql (13.4 (Debian 13.4-1.pgdg110+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.4 (Debian 13.4-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
[email protected]:~$ dropdb testdb
[email protected]:~$ exit
logout
I hope you have a blast developing with PostgreSQL 13 database server on Debian 11/10/9 Linux machine.