How to install PostgreSQL in Debian

PostgreSQL is a powerful object-relational database system with more than 30 years of active development that has gained a high reputation for reliability, robustness and performance.

Before installing PostgreSQL, check the value of the LC_ALL environment variable by typing:

$ echo $LC_ALL

If the variable is empty edit the file /etc/environment and adjust the value according to your needs.

LC_ALL="en_US.UTF-8"
export LC_AL

Do a Login/logout to make the change effective and now we will proceed to install PostgreSQL.

Install

$ sudo apt install postgresql

After the installation is finished, we verify if the PostgreSQL server is running.

Check status

$ sudo systemctl status postgresql
● postgresql.service - PostgreSQL RDBMS
Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
Active: active (exited) since Tue 2019-05-07 21:20:41 EDT; 20min ago
Process: 2620 ExecStart = / bin / true (code = exited, status = 0 / SUCCESS)
Main PID: 2620 (code = exited, status = 0 / SUCCESS)

May 07 21:20:41 debian systemd [1]: Starting PostgreSQL RDBMS ...
May 07 21:20:41 debian systemd [1]: Started PostgreSQL RDBMS.

The above information indicates that the PostgreSQL server is running correctly.

Now we can connect to the database server using the default user.

Connect to the server

$ sudo -u postgres psql
psql (9.6.12)
Type "help" for help.
postgres = #

We can exit from the Postgres console with

Exit

\ q

Stop the Postgres server

 $ sudo systemctl stop postgresql 

Start the Postgres server

$ sudo systemctl start postgresql

Verify that the server starts with the Operating System

$ sudo systemctl is-enabled postgresql
enabled

enabled means that it starts with the Operating System otherwise we can:

Start the service with the Operating System

 $ sudo systemctl enable postgresql
Synchronizing state of postgresql.service with SysV service script with / lib / systemd / systemd-sysv-install.
Executing: / lib / systemd / systemd-sysv-install enable postgresql

If we do not want to start with the Operating System then.

Disable the service

$ sudo systemctl disable postgresql
Synchronizing state of postgresql.service with SysV service script with / lib / systemd / systemd-sysv-install.
Executing: / lib / systemd / systemd-sysv-install disable postgresql

YouTube video

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.