Connect with us

Hi, what are you looking for?

Latest

How to install and setup PostgreSQL on RHEL 8

How to install and setup PostgreSQL on RHEL 8

 

How to install and setup PostgreSQL on RHEL 8

How do I set up PostgreSQL relational database administration on RHEL Eight utilizing the command line? How do I set up and setup PostgreSQL on RHEL 8 (Pink Hat Enterprise Linux) server utilizing utility streams?

Introduction: PostgreSQL is a free and open supply ORDBMS ( object-relational database administration system). It’s the world’s most superior open supply database. This web page exhibits set up PostgreSQL on RHEL Eight and configure different elements of the database server.

ADVERTISEMENTS

 

How one can set up and setup PostgreSQL on RHEL 8

  1. Open a terminal Window
  2. Discover model of PostgreSQL you need to set up on RHEL 8:
    sudo yum module record | grep postgresql
  3. Set up the default, PostgreSQL model 10 on RHEL 8:
    sudo yum set up @postgresql
  4. Subsequent initialize new PostgreSQL database cluster in RHEL 8:
    sudo postgresql-setup –initdb

Allow us to see all instructions in particulars.

How one can see an inventory of all out there PostgreSQL utility streams on RHEL 8

Run the next yum command
$ sudo yum module record | grep postgresql

How to install and setup PostgreSQL on RHEL 8

How one can set up and use PostgreSQL on RHEL 8

Within the earlier step, we noticed that RHEL Eight shipped with two Purposes streams for PostgreSQL server. To put in PostgreSQL 9.6, run:
$ sudo yum set up @postgresql:9.6
The default is PostgreSQL 10, so operating the next yum command installs the newest secure model:
$ sudo yum set up @postgresql
How to install and setup PostgreSQL on RHEL 8Putting in and use PostgreSQL on RHEL Eight utilizing utility streams (click on to enlarge)

How one can initialize new PostgreSQL database cluster

The primary motion you carry out after PostgreSQL server set up is to run the next command:
$ sudo postgresql-setup –initdb
How to install and setup PostgreSQL on RHEL 8Creating a brand new PostgreSQL database cluster on RHEL 8

How one can setup a password for postgres account

Run the next passwd command to setup a password:
$ sudo passwd postgres
Pattern outputs:

Altering password for person postgres.
New password:
Retype new password:
passwd: all authentication tokens up to date efficiently.

How do I begin/cease/restart the PostgreSQL server

It’s essential use the systemctl command:
sudo systemctl begin postgresql ## <– begin the server ##
sudo systemctl cease postgresql ## <– cease the server ##
sudo systemctl restart postgresql ## <– resstart the server ##
sudo systemctl standing postgresql ## <– get standing of the server ##

How one can allow the PostgreSQL server at boot time on RHEL 8

Once more use the systemctl command as follows:
$ sudo systemctl allow postgresql
How to install and setup PostgreSQL on RHEL 8Begin and allow the PostgreSQL server

How do I log in utilizing psql?

It’s essential use the psql command. It’s a terminal-based front-end to PostgreSQL server. It allows you to sort in queries interactively. The set up script created a person named postgres. That’s the default account for default database and roles. Allow us to log in as postgres utilizing the sudo command:
$ sudo -i -u postgres
Run it:
$ psql
How to install and setup PostgreSQL on RHEL 8Validating set up of PostgreSQL database server

At postgres=# immediate sort q to stop from the command-line interface to PostgreSQL server. Did you discover you logged into PostgreSQL with none password? Allow us to repair this by creating HBA config:
$ sudo vi /var/lib/pgsql/information/pg_hba.conf
Discover traces that learn as follows:

# IPv4 native connections:
host all all 127.0.0.1/32 ident
# IPv6 native connections:
host all all ::1/128 ident

Substitute ident with scram-sha-256:

# IPv4 native connections:
host all all 127.0.0.1/32 scram-sha-256
# IPv6 native connections:
host all all ::1/128 scram-sha-256

Restart the postgresql server:
$ sudo systemctl restart postgresql

How one can create a brand new PostgreSQL person account

First create a Linux person account named tom:
$ sudo useradd tom
$ sudo passwd tom
Pattern outputs:

Altering password for person tom.
New password:
Retype new password:
passwd: all authentication tokens up to date efficiently.

The postgres account is nothing however an administrative person for PostgreSQL server. So log in as postgres:
$ sudo -i -u postgres
Run the next createuser command to creates a brand new PostgreSQL position for tom Linux person:
$ createuser –interactive
How to install and setup PostgreSQL on RHEL 8Outline a brand new PostgreSQL person account named tom
Create a brand new person account with password for brand new position:
$ createuser –interactive –pwprompt
How to install and setup PostgreSQL on RHEL 8Creating person with password on PostgreSQL
Lastly create a brand new database named jerry for tom person by log in as postgres admin person:
$ sudo -i -u postgres
$ createdb -O tom jerry

Associated: PostgreSQL add or create a person account and grant permission for database

How do I connect with jerry database with tom person?

Merely run the next instructions:
$ sudo -i -u tom
$ psql -d jerry -U tom
How to install and setup PostgreSQL on RHEL 8Connecting to PostgreSQL server with the brand new person named tom for jerry database

How one can create a brand new desk

Log in:
$ psql -d jerry -U tom
Kind the next SQL to create demo desk:

CREATE TABLE demo(
id serial PRIMARY KEY,
e-mail VARCHAR (100) UNIQUE NOT NULL,
identify VARCHAR (50) UNIQUE NOT NULL
);

See data in regards to the demo desk:
d
OR
dt

How to install and setup PostgreSQL on RHEL 8
Allow us to add some information to our desk, run the next SQL:

INSERT INTO demo (id, e-mail, identify) VALUES (1, ‘[email protected]’, ‘Vivek Gite’);
INSERT INTO demo (id, e-mail, identify) VALUES (2, ‘[email protected]’, ‘Foo Bar’);
INSERT INTO demo (id, e-mail, identify) VALUES (3, ‘[email protected]’, ‘Roja T’);
INSERT INTO demo (id, e-mail, identify) VALUES (4, ‘[email protected]’, ‘Marlena John’);

View information:

Delete some information:

DELETE FROM demo WHERE id = 4;

Replace information:

UPDATE demo SET e-mail = ‘[email protected]’ WHERE id = 2;

How to install and setup PostgreSQL on RHEL 8How one can add, question, delete and Replace information in a desk (click on to enlarge)

Conclusion

Congratulations. You efficiently arrange PostgreSQL server on RHEL Eight server. You additionally realized create customers, database and tables. For more information see the official PostgreSQL docs right here.

Posted by: Vivek Gite

The creator is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a coach for the Linux working system/Unix shell scripting. Get the newest tutorials on SysAdmin, Linux/Unix and open supply matters through RSS/XML feed or weekly e-mail e-newsletter.

ADVERTISEMENTS

You May Also Like

Hosting

The latest round of MITRE ATT&CK evaluations proved yet again that Microsoft customers can trust they are fully protected even in the face of...

Hosting

On Thursday, April 23rd, 2020, Canonical Ltd, the makers of Ubuntu Linux distribution officially released the long-awaited Ubuntu 20.04 version code-named “Focal Fossa”, it...

Hosting

As the robot process automation (RPA) market becomes more and more dynamic, more and more companies are trying to integrate RPA into their business...

Latest

One of the most discussed new features in Ubuntu 20.04 is the dark mode. You can install a dark theme in any version of...