AMZ DIGICOM

Digital Communication

AMZ DIGICOM

Digital Communication

Ubuntu 20.04: Install PostgreSQL – easy tutorial

PARTAGEZ

The PostgreSQL database management system (DBMS) can be installed on Ubuntu 20.04 using just a few commands. Discover all the steps to follow, from its installation to the creation of a database.

Prerequisites for an Ubuntu server with PostgreSQL

To create a simple database server with PostgreSQL, a few resources are enough. With a small configuration, it is already possible to obtain good results:

  • 1 GHz processor (CPU)
  • 2 GB RAM
  • 2 GB hard drive space

Depending on the data you want to store, you may need to increase hard drive space.

To build a PostgreSQL server with IONOS, a Cloud RAM M server is a great place to start. This one also allows you to take advantage of Ubuntu as the operating system for the server. What are the benefits of a cloud server? If your needs increase, you can add additional resources at any time, without this having an effect on the progress of your operations.

Before choosing your server, we advise you to study all the options available to you. IONOS offers three different types of servers:

  • Cloud Server: maximum scalability and per-minute billing.
  • Dedicated server: hardware with the best performance, just for you.
  • vServer (VPS): complete virtualization for more independence.

Install PostgreSQL on Ubuntu

A few commands are enough to install PostgreSQL on Ubuntu 20.04. All you need to do is use the terminal of a Linux distribution. To open the console, you can go through the program overview or the search box, or opt for a convenient solution using the keyboard shortcut [Ctrl] + [Alt] + [T].

A wide variety of commands are required to use the terminal effectively. We therefore advise you to learn about the main Linux commands.

Step 1: Download and Install PostgreSQL

Before installing any software under Linux, you should always update package manager. This way you are sure to use the most recent installation packages.

sudo apt update
sudo apt upgrade

All it takes is one command to download and install the PostgreSQL package.

sudo apt install postgresql

You just have to confirm the operation, and the DBMS is then installed.

Step 2: Enable PostgreSQL

Once the database management system is installed, start PostgreSQL :

sudo systemctl start postgresql

You can ask to know the status of PostgreSQL to know if it really works:

sudo systemctl status postgresql

The service should now be listed as « active ». To make the status indicator disappear, then use the key [Q].

Step 3: Use PostgreSQL

After installation, you may find that a regular account named « postgres » already exists in PostgreSQL. To enable it, use the following command:

Ubuntu now works as if you were logged in with the PostgreSQL account. You should now be able to access the DBMS command prompt.

You work with PostgreSQL in this environment. If you want to display the currently active connectionyou can use this command:

For leave the domain againjust use the following command:

Step 4: Create databases

Simultaneously, the system automatically created a database associated with the « postgres » role. However, it is possible to work with several databases at the same time from your PostgreSQL server. Use the command below to create a new databasereplacing « example » with a name of your choice:

This command must imperatively end with a semicolon.

If you want to display the databases you have createdyou can use this command:

The short form « \l » (lowercase « L ») also works.

List of databases in PostgreSQL on Ubuntu 20.04
« \list » allows you to view all databases and get additional information about them.

To work directly in a database, you must select it each time. The active database is displayed in the PostgreSQL console entry line. For change databasefill in the following command specifying the name of the desired database:

Inputs for creating a new PostgreSQL database and accessing it with the commands presented in Ubuntu 20.04's terminal
In the PostgreSQL environment, at the beginning of the line, you can recognize the database you are working in: here it is « postgres » and « example ».

For delete a databaseyou can use this line of code:

Warning: you cannot reverse this deletion. So use this command with caution, and think carefully before you start.

You can also use PostgreSQL on Windows. By installing PostgreSQL on Windows Server 2016, you will enjoy the same DBMS benefits. If you are more comfortable with Microsoft’s operating system than a Linux distribution, you should consider using this approach.

Télécharger notre livre blanc

Comment construire une stratégie de marketing digital ?

Le guide indispensable pour promouvoir votre marque en ligne

En savoir plus

Souhaitez vous Booster votre Business?

écrivez-nous et restez en contact