19.1 C
Texas
Melhttp://www.osradar.com
Guru Unix /Linux and GNU supporter

How to install PostgreSql on Ubuntu18.04

Install and Use PostgreSQL on Ubuntu 18.04

Database management systems are the major components for websites and almost every application uses database to store their data as well as manage this data to produce different results for specific purpose. Basically database provide a structural way to organize and manage data to access information.

Before starting the installation of PostgreSQL on Ubuntu. Let’s have a description about this database. PostgreSQL is a relational database management system in which we use a system that provides the implementation of original SQL (Structure Query Language). PostgreSQL is the most popular choice which provides advanced features in which transactions are reliable data concurrency handles without read locks.

In this article we will learn how to install and use PostgreSQL in our Ubuntu server. So let’s start by the following steps.

STEP1:  Installing PostgreSQL on Ubuntu.

- Advertisement -

The first step for installing PostgreSQL on Ubuntu is to add repository files of Postgres packages into Ubuntu. Note that your server should be configured initially in which there is a non-root user and some basic firewall settings are configured. However, this is your first time, so refresh your local package and then install Postgres package. Following is the process to install the package by command.

Command:  

 $  sudo apt update
 $  sudo apt install postgresql postgresql-contrib 

 

After installing Postgres into Ubuntu server, then you have to check that whether it is listening to the socket on port number 5432. For this purpose, follow the command mentioned below:

Command:

$ ss -nlt

The server will start after the reboot completes. Then you can enable or disable this by using following commands.

Command:

$ sudo systemctl disable postgresql
OR
$ sudo systemctl enable postgresql

 

To configure your server to listen all networks, then you have to change its main configuration file using following command.

Command:

$ sudo nano /etc/postgresql/10/main/postgresql.conf

Step 2: Listening and restarting PostgreSQL.

After configuring Postgresql to listen for all networks, now we have to type the command to check whether it is listening or not. And then later we will restart the server. For this purpose, follow the instructions by typing the commands.

Command:

listen_addresses = ‘*’
$ sudo service postgresql restart

Note: If you have enabled UFW firewall, then you can open the server’s port5432 for any incoming traffic by following command

Command:

$ sudo ufw allow from any to any port 5432 proto tcp

 

Step 3: Connecting to PostgreSQL.

After installing and configuring the PostgreSQL in our server, now it is the time to connect this system to use it and create database, users etc. For connecting to PostgreSQL follow the commands or instruction accordingly to make it successful for you.

Command:

$ sudo su – postgres
$ psql

 

Step 4: Check lists of database in PostgreSQL.

After connecting to the server we are now required to check whether there are databases in the server. For this purpose, perform following steps.

Command:

postgres-# \l

This will give you following results:

In order to list the users in the database type following steps or commands.

Command:

postgres-# \du

 

Step 5: Change user Password in PostgreSQL.

After we have seen databases and users, now we can change user’s password by performing the following step.

Command:

postgres=# ALTER USER postgres WITH PASSWORD  ‘newpass’;

ALTER ROLE

 

For creating new user in database follow the below mentioned steps.

Command:

postgres=# CREATE USER newuser WITH PASSWORD ‘123’;

CREATE ROLE

 

After creating users now we can upgrade and check login info for the users. For this purpose follow the steps.

Command:

postgres=# ALTER USER newuser WITH SUPERUSER;  (For upgrading user)

ALTER ROLE

 

postgres-# \conninfo   (For log-in info)

 

 

After this you can now exit the program by typing following command.

Command:

postgres-# \q

 

Conclusion:

After following all the guideline, you are now able to install PostgreSQL in Ubuntu to use the features of PostgreSQL. And using this DBMS to manage and creating user. However, you should follow the same procedure to make it accurate. If you face any problem, then leave a message or comment. We will help you in every matter.

 

- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

LEAVE A REPLY

Please enter your comment!
Please enter your name here



Latest article