Hi, friends, in this post, I’ll show you how to install PostgreSQL 12 on Debian 10.
PostgreSQL 12 is the latest stable version of what is perhaps the most advanced open-source relational database manager. So many sysadmin need to have it on the different servers.
If you want to know all the news or at least the most important ones, you can read our post
Well, PostgreSQL 12 comes with many important improvements and it’s a good time to install it. That’s what this post is about.
So let’s go for it.
Install PostgreSQL 12 on Debian
PostgreSQL is included in the official Debian repositories, but not in version 12 but in version 11.
The installation of PostgreSQL 12 is possible thanks to the repository it has for APT package managers that is used by Debian, Ubuntu, Linux Mint and derivatives.
So let’s start.
First, open a terminal session or connect to your server using SSH. Then, install some necessary packages:
:~$ sudo apt install gnupg gnupg2
At the end, the PostgreSQL 12 repository should be added to the list of Debian software sources. To do this, create the following file:
:~$ sudo nano /etc/apt/sources.list.d/pgdg.list
And in it he adds the following:
deb http://apt.postgresql.org/pub/repos/apt/ buster-pgdg main
Then save the changes by pressing CTRL + O and close the file by pressing CTRL + X.
For the repository to be accepted by the system, you need to add the gpg key to it. To do this, use the following command:
:~$ wget --quiet -O - https://www.postgresql.org/media /keys/ACCC4CF8.asc | sudo apt-key add - OK
Once the process has been completed, simply update the APT cache.
:~$ sudo apt update
You can now view all the packages related to PostgreSQL 12 by typing
:~$ sudo apt install postgresql12
But don’t press enter, just press the TAB key and you’ll see the following:
As you can see in the image, we have PostgreSQL 12 available. So to install it run the following command:
:~$ sudo apt install postgresql-12 Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: libpq5 libxslt1.1 pgdg-keyring postgresql-client-12 postgresql-client-common postgresql-common sysstat Suggested packages: postgresql-doc-12 libjson-perl isag The following NEW packages will be installed: libpq5 libxslt1.1 pgdg-keyring postgresql-12 postgresql-client-12 postgresql-client-common postgresql-common sysstat 0 upgraded, 8 newly installed, 0 to remove and 51 not upgraded. Need to get 17.3 MB of archives. After this operation, 56.7 MB of additional disk space will be used. Do you want to continue? [Y/n]
Now we’ll see if everything went well.
Testing the installation
By default, Debian when installing PostgreSQL starts and enables the service. Therefore, it is ready to be tested. However, if you want to stop the service, you can use this command:
:~$ sudo systemctl stop postgresql
On the other hand, the best way to know if PostgreSQL is ready for work is to execute some command from the console. So we’ll access it first:
:~$ sudo -i -u postgres
Remember that the PostgreSQL console is accessed through the postgres user.
And finally, we access with this command:
Once inside, we can, for example, display all the databases in the system:
And so we can work without problems with PostgreSQL.
PostgreSQL 12 is a powerful database manager that is used in many projects worldwide. This makes many people want to have the latest stable versions to take even more advantage of the tool.
Please share this post and join our Telegram channel.