How to Install PostgreSQL on Linux Mint 19
Table of Contents
Installing PostgreSQL on Linux Mint 19
PostgreSQL or Postgres is a popular relational database management system. PostgreSQL is also an opensource and general-purpose database system which provides an implementation of SQL querying language. It has many advanced features like reliable transactions and concurrency without read locks. In this tutorial, you are going to learn how to install PostgreSQL on Linux Mint 19 with basic database administration.
Before you start to install PostgreSQL on Linux Mint 19. You must have the root user account credentials of your system.
Install PostgreSQL on Linux Mint
To install PostgreSQL on Linux Mint run following command.
As Linux Mint’s official repository contains a package of PostgreSQL, we will use here,
apt package manager to install Postgres on Linux Mint.
apt package manager index typing following command:
sudo apt update
Now run following command to install PostgreSQL with
-contrib package which adds additional features and functionalities:
sudo apt install postgresql postgresql-contrib
To check the Postgres version and confirm installation run following
sudo -u postgres psql -c "SELECT version();"
psql utility you can interact with the PostgreSQL database easily.
PostgreSQL Roles and Databases
Both user and group are presented as term role in PostgreSQL for handling database access permissions.
Peer are different methods for authentication in PostgreSQL.
Ident method mainly used on TCP/IP connection while
Trust method used to connect without password using given criteria in
You can log in to PostgreSQL using below command:
sudo su - postgres
To exit from here type following in the terminal:
Create PostgreSQL Database and Role
createdb method you can create a database in Postgres and by using
createuser method you can create a new role.
To create new database called
test_db run following command:
sudo su - postgres -c "createdb test_db"
Now create a new role called
test_user run below command:
sudo su - postgres -c "createuser test_user"
Now you should grant permission to the user
test_user for the newly created database
test_db you should execute a query in PostgreSQL Shell to so run following command:
sudo -u postgres psql
Execute the following query to grant permission:
grant all privileges on database test_db to test_user;
Open PostgreSQL Prompt with New Role
To open the PostgreSQl prompt with new role you should have the same Linux user available as PostgreSQL user and database.
To create new Linux user in Linux Mint named
test_user if the matching user is not available by running following command:
sudo adduser test_user
After creating matching user account on the Linux system, you can connect to the database running following command:
sudo -u sammy psql
Enabling Remote Access to PostgreSQL server
Use the following steps to enable remote access to the PostgreSQL server.
/etc/postgresql/10/main/postgresql.conf file and place
listen_addresses = '*' in the CONNECTIONS AND AUTHENTICATION SECTION to do so run following command:
sudo nano /etc/postgresql/10/main/postgresql.conf
Update listen_addresses like given below:
#------------------------------------------------------------------------------ # CONNECTIONS AND AUTHENTICATION #------------------------------------------------------------------------------ # - Connection Settings - listen_addresses = '*'
Now restart the PostgreSQL service with
sudo systemctl restart postgresql
Now confirm and verify the changes typing following in terminal:
ss -nlt | grep 5432
The output should be:
LISTEN 0 128 0.0.0.0:5432 0.0.0.0:* LISTEN 0 128 [::]:5432 [::]:*
pg_hba.conf file to configure server remote connections using below examples:
# TYPE DATABASE USER ADDRESS METHOD # The user test_user will be able access all databases from all locations using a md5 password host all test_user 0.0.0.0/0 md5 # The user test_user will be able access only the test_db from all locations using a md5 password host test_db test_user 0.0.0.0/0 md5 # The user test_user will be able access all databases from a trusted location (192.168.43.106) without a password host all test_user 192.168.1.134 trust
You have successfully learned how to install PostgreSQL on Linux Mint 19. If you have any queries please don’t forget to comment below.
How to Set Up Cron Job on CentOS 8
How to install Laravel PHP Framework With Nginx on Ubuntu 18.04
How to install Node.js with npm on CentOS 7
How to install XAMPP on CentOS 7
How to Install WordPress with LEMP Stack on Ubuntu 18.04
How to Use Tail Command in Linux
How to Install WebStorm on Debian 9
How to Install Arduino IDE on Linux Mint 19
How to Install XAMPP on Manjaro 18
How to Install and Use Docker on CentOS 7
How to Install Yarn on Ubuntu 18.04
How to Install WebStorm on Linux Mint 19