This tutorial provides instructions on how to install the PostgreSQL database software on an Ubuntu 18.04 server.
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 Ubuntu 18.04 with basic database administration.
Before you start to install PostgreSQL on Ubuntu 18.04. You must have the root user account credentials of your system.
To install PostgreSQL on Ubuntu run following command.
As Ubuntu’s official repository contains a package of PostgreSQL, we will use here,
apt package manager to install Postgres on Ubuntu.
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.
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 psql
To exit from here type following in the terminal:
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;
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 ubuntu 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
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 Ubuntu 18.04. If you have any queries please don’t forget to comment below.
Originally published at https://linux4one.com
How to Install PgAdmin 4 on Ubuntu 20.04 - We are going to show you how to install pgAdmin4 on Ubuntu 20.04 LTS in Server Mode as a web application using apache2 and Wsgi module.
Learn how to install PostgreSQL on Ubuntu 20.04. PostgreSQL (aka Postgres) is an open-source object-relational database management system (ORDBMS), developed by PostgreSQL. PostgreSQL is available for Linux, Microsoft Windows, FreeBSD, OpenBSD, Solaris, and Mac OS.
Learn how to install and use PostgreSQL on an Ubuntu 20.04 server. PostgreSQL, or Postgres, is a relational database management system that provides an implementation of the SQL querying language.
In this guide, we will go over how to install client programs for a variety of database management systems (DBMSs), including PostgreSQL, MySQL, and Redis, on an Ubuntu 18.04 server. We’ll also explain how to use these programs to connect to a managed database instance.