News
Seven days of Black Friday madness — great deal from Serverspace!

THE NEW YEAR
WHEEL OF FORTUNE

Spin the wheel and win a guaranteed prize right now!

By registering, you are signing up to receiving emails.
VB
November 11 2022
Updated June 7 2023

How to install PostgreSQL on Centos 7

CentOS Databases

Using another OS?

Select the desired version or distribution.

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:

  • Server with at least 1 CPU cores, 1Gb of RAM and 10Gb drive space. Real requirements may be some differ and depends of your application needs and optimization;
  • Actual operation system (Centos 7 in this article);
  • Administrative account access.

Setup process

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

  • Update current system software:
yum -y update

pic1-cent

  • Reboot the server to use the newest packages;
  • Add exception to the "base" section of /etc/yum.repos.d/CentOS-Base.repo repository file otherwice old version PostgreSQL will be installed:

pic2-cent

  • Add PostgreSQL repo and find the latest version:
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*

pic3-cent

  • As shown at the previous screenshot, last PostgreSQL version is 15. Let's install it:
yum -y install postgresql15-server

pic5-cent

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

yum -y install epel-release
  • Initialize new DB-cluster:
/usr/pgsql-15/bin/postgresql-15-setup initdb

pic6-cent

  • Enable launch at system boot and run the service:
systemctl enable postgresql-15; service postgresql-15 start

pic7-cent

  • Check the status:
service postgresql status

pic8-cent

Data operations

  • To create database you should use built-in administrative account:

su postgres

psql postgres

  • Create the user role and test database:
CREATE ROLE  <username> LOGIN PASSWORD '<password>';
CREATE DATABASE <dbname> WITH OWNER = <username>;

pic9-cent

  • Login as created user:
psql -h <host> -d <dbname> -U <username> -p <PostgreSQL_port>

pic10-cent

  • Let's try to create table into our new database:

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)

);

pic11-cent

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

  • Data insert:

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');

pic12-cent

  • Check our job:
SELECT <content> from <table_name>

pic13-cent

Instead of final

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

Vote:
4 out of 5
Аverage rating : 4.7
Rated by: 3
1101 CT Amsterdam The Netherlands, Herikerbergweg 292
+31 20 262-58-98
700 300
ITGLOBAL.COM NL
700 300
We use cookies to make your experience on the Serverspace better. By continuing to browse our website, you agree to our
Use of Cookies and Privacy Policy.