Linux Tutorials

Find out how to set up and setup PostgreSQL on RHEL eight

SEOClerks

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 eight server utilizing software 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 find out how to set up PostgreSQL on RHEL eight and configure different elements of the database server.

Find out how to set up and setup PostgreSQL on RHEL eight

Open a terminal WindowFind model of PostgreSQL you wish to set up on RHEL eight:
sudo yum module record | grep postgresqlSet up the default, PostgreSQL model 10 on RHEL eight:
sudo yum set up @postgresqlSubsequent initialize new PostgreSQL database cluster in RHEL eight:
sudo postgresql-setup –initdb

Allow us to see all instructions in particulars.

Find out how to see an inventory of all obtainable PostgreSQL software streams on RHEL eight

Run the next yum command
$ sudo yum module record | grep postgresql
How to see a list of all available PostgreSQL versions or application streams

Find out how to set up and use PostgreSQL on RHEL eight

Within the earlier step, we noticed that RHEL eight shipped with two Functions 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
Install and setup PostgreSQL on RHEL 8Putting in and use PostgreSQL on RHEL eight utilizing software streams (click on to enlarge)

Find out how to 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 create a new PostgreSQL database cluster on RHEL 8Creating a brand new PostgreSQL database cluster on RHEL eight

Find out how to setup a password for postgres account

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

Altering password for consumer 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 worthwhile to 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 ##

Find out how to allow the PostgreSQL server at boot time on RHEL eight

Once more use the systemctl command as follows:
$ sudo systemctl allow postgresql
Start stop restart PostgreSQL server on RHEL 8Begin and allow the PostgreSQL server

How do I log in utilizing psql?

It’s worthwhile to use the psql command. It’s a terminal-based front-end to PostgreSQL server. It allows you to kind in queries interactively. The set up script created a consumer 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
Login to PostgreSQL DatabasesValidating set up of PostgreSQL database server

At postgres=# immediate kind q to give up 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/knowledge/pg_hba.conf
Discover traces that learn as follows:

# IPv4 native connections:
host all all 127.zero.zero.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.zero.zero.1/32 scram-sha-256
# IPv6 native connections:
host all all ::1/128 scram-sha-256

Restart the postgresql server:
$ sudo systemctl restart postgresql

Find out how to create a brand new PostgreSQL consumer account

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

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

The postgres account is nothing however an administrative consumer 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 consumer:
$ createuser –interactive
How to create a new PostgreSQL user or role on RHEL 8Outline a brand new PostgreSQL consumer account named tom
Create a brand new consumer account with password for brand spanking new position:
$ createuser –interactive –pwprompt
Creating user with password on PostgreSQLCreating consumer with password on PostgreSQL
Lastly create a brand new database named jerry for tom consumer by log in as postgres admin consumer:
$ sudo -i -u postgres
$ createdb -O tom jerry

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

How do I hook up with jerry database with tom consumer?

Merely run the next instructions:
$ sudo -i -u tom
$ psql -d jerry -U tom
How to connect to postgresql with the new userConnecting to PostgreSQL server with the brand new consumer named tom for jerry database

Find out how to 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,
title VARCHAR (50) UNIQUE NOT NULL
);

See data in regards to the demo desk:
d
OR
dt
How to create a new PostgreSQL table on RHEL 8
Allow us to add some knowledge to our desk, run the next SQL:

INSERT INTO demo (id, e-mail, title) VALUES (1, ‘webmaster@cyberciti.biz’, ‘Vivek Gite’);
INSERT INTO demo (id, e-mail, title) VALUES (2, ‘foo@bar.com’, ‘Foo Bar’);
INSERT INTO demo (id, e-mail, title) VALUES (three, ‘roja@nixcraft.com’, ‘Roja T’);
INSERT INTO demo (id, e-mail, title) VALUES (four, ‘marlena@gmail.internet.in’, ‘Marlena John’);

View knowledge:

Delete some knowledge:

DELETE FROM demo WHERE id = four;

Replace knowledge:

UPDATE demo SET e-mail = ‘foo@gmail.com’ WHERE id = 2;

How to add, query, delete and Update data in a tableFind out how to add, question, delete and Replace knowledge in a desk (click on to enlarge)

Conclusion

Congratulations. You efficiently arrange PostgreSQL server on RHEL eight server. You additionally discovered find out how to create customers, database and tables. For more information see the official PostgreSQL docs right here.

Posted by: Vivek Gite

The writer 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.

Source link

Related Articles

Leave a Reply

Back to top button