07.06.2023

How to install PostgreSQL on Centos 7

What is PostgreSQL

PostgreSQL - relational database system founded on SQL-queries language. Common standards following and possibility to make high performance systems is reason why PostgreSQL is popular today.

Before installation

To install PostgreSQL you should have:

Setup process

To install PostgreSQL on your server please do all steps below:

yum -y update

yum -y install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm; yum list -y postgre*-server*

yum -y install postgresql15-server

NOTE: in case dependancy resolution failed, you should install epel repository then try to install PostgreSQL again:

yum -y install epel-release
/usr/pgsql-15/bin/postgresql-15-setup initdb

systemctl enable postgresql-15; service postgresql-15 start

service postgresql status

Data operations

su postgres

psql postgres

CREATE ROLE  <username> LOGIN PASSWORD '<password>';
CREATE DATABASE <dbname> WITH OWNER = <username>;

psql -h <host> -d <dbname> -U <username> -p <PostgreSQL_port>

CREATE TABLE testtable (
item_num integer NOT NULL,
item_name character varying(50) NOT NULL,
item_detail character varying(50) DEFAULT NULL,
PRIMARY KEY (item_num)

);

I created a table with three columns, item_num (digit),  item_name (text) and item_detail (text, may be empty).

INSERT INTO testtable (item_num, item_name, item_detail)
VALUES('1','Ship','Warship Model');

INSERT INTO testtable (item_num, item_name)
VALUES('2','Doll');

INSERT INTO testtable (item_num, item_name, item_detail)
VALUES('3','Kitchen','Toy Kitchen');

SELECT <content> from <table_name>

Instead of final

In this tutorial I showed how to install PostgreSQL on Centos 7 and operate with data "inside" the database.