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:
- 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:
- Add PostgreSQL repo and find the latest version:
- As shown at the previous screenshot, last PostgreSQL version is 15. Let's install it:
NOTE: in case dependancy resolution failed, you should install epel repository then try to install PostgreSQL again:
- Initialize new DB-cluster:
- Enable launch at system boot and run the service:
- Check the status:
Data operations
- To create database you should use built-in administrative account:
su postgres
psql postgres
- Create the user role and test database:
CREATE DATABASE <dbname> WITH OWNER = <username>;
- Login as created user:
- 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)
);
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');
- Check our job:
Instead of final
In this tutorial I showed how to install PostgreSQL on Centos 7 and operate with data "inside" the database.