How to install PostgreSQL on Ubuntu 20.04?

Windows Articles

Top 8 features for power users in Windows 10

Hello! Windows 10 is full of features and functions. In fact, that's one of the reasons it's so popular and used. Because it can...

How to access System in Windows 10

Perhaps the title of this post is misleading. In previous versions of Windows, it was enough to enter the Control Panel and from there,...

Microsoft reduces the fragmentation of Windows 10

Windows 10 20H2 has been released as a minor operating system update. As a result, it has managed to reduce platform errors. In addition,...

How to install Nginx and PHP on FreeBSD?

Hello, friends. FreeBSD is a secure system even more than Linux, that's why it's used as the main server. And a server has to...

How to enable local port forwarding using Ubuntu 20.04 and ssh

SSH, a very popular tool found almost with every IT guy. Commonly, when we talk about the insecure network for data, ssh is the...
angeloma
angeloma
Senior Writer and partner

Hi, folks. In this post, you will learn how to install PostgreSQL on Ubuntu 20.04 Perhaps the most advanced open-source relational database management system in the world. So, it’s one of the main options to take into account for the development of applications or to serve data from other compatible applications.

PostgreSQL

PostgreSQL is one of the most advanced and modern relational database managers out there. It is always shown as the immediate competitor of MySQL and MariaDB in the segment of open source and community database managers.

One of the main advantages of using PostgreSQL is that it has extensive documentation and supports powerful features. All this in an open-source and free application.

On the other hand, PostgreSQL has certain features that make it quite complete as is the proper management of resources or its ability to be multi-version. All this together with an experienced development makes it quite powerful.

Install PostgreSQL on Ubuntu 20.04

With every new system, there are lots of software updates. So, at the time of writing this post, PostgreSQL 12 is the latest stable version and is in the Ubuntu 20.04 repositories.

So, open a terminal and refresh the APT cache.

:~$ sudo apt update

Once the process is complete, you can list all PostgreSQL-related packages in the official repositories:

:~$ sudo apt list postgresql*

1.- All PostgreSQL package on Ubuntu 20.04
1.- All PostgreSQL package on Ubuntu 20.04

In the image, you can see that there are many PostgreSQL packages in the repositories. This means that the installation will be easy.

Also, these packages that you probably don’t know, are libraries and add-ons for PostgreSQL. If you are an experienced developer you will probably have to use them eventually.

However, if you are a newcomer, you may feel a bit overwhelmed by the number of packages available, so you can only consult the postgresql meta package

:~$ sudo apt list postgresql
postgresql/focal 12+214 all

So, to install PostgreSQL 12 on Ubuntu 20.04 just run this command:

:~$ sudo apt install postgresql-12
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  libllvm10 libpq5 libsensors-config libsensors5 postgresql-client-12 postgresql-client-common postgresql-common sysstat
Suggested packages:
  lm-sensors postgresql-doc-12 libjson-perl isag
The following NEW packages will be installed:
  libllvm10 libpq5 libsensors-config libsensors5 postgresql-12 postgresql-client-12 postgresql-client-common postgresql-common sysstat
0 upgraded, 9 newly installed, 0 to remove and 0 not upgraded.
Need to get 30.6 MB of archives.
After this operation, 121 MB of additional disk space will be used.
Do you want to continue? [Y/n]

2.- Install PostgreSQL on Ubuntu 20.04
2.- Install PostgreSQL on Ubuntu 20.04

If all goes well, at the end of the screen output you will see some useful information to help you with your PostgreSQL 12.

3.- PostgreSQL installed
3.- PostgreSQL installed

As in other installations of other programs such as MySQL or MariaDB, Ubuntu automatically starts the PostgreSQL service. In case you want to stop it, run this command

:~$ sudo systemctl stop postgresql

Also, Ubuntu enables PostgreSQL to start with the system. If you do not want it to

:~$ sudo systemctl disable postgresql

To reverse these changes, execute these two commands:

:~$ sudo systemctl start postgresql
:~$ sudo systemctl enable postgresql

In short, PostgreSQL is one more service of the system, so you can manage it thanks to the systemctl command.

Finally, check the status of the service to know if it is running correctly:

:~ sudo systemctl status postgresql
● postgresql.service - PostgreSQL RDBMS
     Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
     Active: active (exited) since Tue 2020-05-05 14:57:30 UTC; 35min ago
   Main PID: 2704 (code=exited, status=0/SUCCESS)
      Tasks: 0 (limit: 506)
     Memory: 0B
     CGroup: /system.slice/postgresql.service
May 05 14:57:30 osradar systemd[1]: Starting PostgreSQL RDBMS...
May 05 14:57:30 osradar systemd[1]: Finished PostgreSQL RDBMS.

4.- PostgreSQL service status
4.- PostgreSQL service status

So, PostgreSQL is running correctly and is ready for work.

Testing PostgreSQL on Ubuntu 20.04

The truth is that it is useless to install without at least checking that everything is fine. To do this, you need to at least execute a command in the PostgreSQL console.

PostgreSQL takes security quite seriously so during the installation, it creates a new system user. It is this user called postgres that has access to the PostgreSQL console.

So, to change the user, run the following command:

:~$ sudo -i -u postgres

Then, access the PostgreSQL console with this command:

:~$ psql

And now you can start typing certain commands to prove that PostgreSQL is working correctly. For example, show all the databases that exist:

:~# \l

5.- PostgreSQL on Ubuntu 20.04
5.- PostgreSQL on Ubuntu 20.04

This way, we can be sure that the installation has been a success.

Conclusion

A great application can not be made if it does not have the backing of a great database manager. This is why today we have taught you how to install PostgreSQL on Ubuntu 20.04 because we are sure that an application that uses this database manager is synonymous with security and robustness.

Please share this post and join our Telegram channel.

More articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest article

Top 8 features for power users in Windows 10

Hello! Windows 10 is full of features and functions. In fact, that's one of the reasons it's so popular and used. Because it can...

How to access System in Windows 10

Perhaps the title of this post is misleading. In previous versions of Windows, it was enough to enter the Control Panel and from there,...

Microsoft reduces the fragmentation of Windows 10

Windows 10 20H2 has been released as a minor operating system update. As a result, it has managed to reduce platform errors. In addition,...

How to install Nginx and PHP on FreeBSD?

Hello, friends. FreeBSD is a secure system even more than Linux, that's why it's used as the main server. And a server has to...

How to enable local port forwarding using Ubuntu 20.04 and ssh

SSH, a very popular tool found almost with every IT guy. Commonly, when we talk about the insecure network for data, ssh is the...
x