PostgreSQL is a powerful, open source object-relational database system ( ORDBMS ). Unlike other relational database systems, PostgreSQL allows users to create unique operators, complex data types, aggregate functions, data type conversion character, and other various database objects through the SQL function.
In this article, we are going to show you how to install PostgreSQL 13 database on CentOS 7.
Installation PostgreSQL 13
1- Add the PostgreSQL repository:
$ sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
2- Install PostgreSQL 13:
$ sudo yum install -y postgresql13-server
3- Initialize the database:
$ sudo /usr/pgsql-13/bin/postgresql-13-setup initdb
4- Enable and start the PostgreSQL service:
$ sudo systemctl enable --now postgresql-13
PostgreSQL Usage Examples
1- PostgreSQL by default creates a user named postgres. Access the PostgreSQL Database Server:
- Switch into the postgres user:
$ su – postgres
- Connect to the PostgreSQL terminal:
$ psql
2- List all the databases:
# \list
3- Create a new PosgreSQL Database named yallalabs:
# CREATE DATABASE yallalabs;
4- Connect to an existant PosgreSQL database named yallalabs:
# \c yallalabs
5- Create a table named employees:
# create table employees (name varchar(25), surname varchar(25));
6- List all the tables:
# \d
7- Insert a couple of rows into the new table named employees:
# INSERT INTO employees VALUES ('Lotfi','Waderni'); # INSERT INTO employees VALUES ('Adam','Pipo');
8- Query all rows from the table named employees:
# SELECT * FROM employees;
9- Exit from PosgreSQL prompt:
# \q
Conclusion
You have learned how to set up PostgreSQL13 on your CentOS 7 server. However, there is still much more to learn with Postgres. For more information visit the PostgreSQL Documentation
Here are some more guides that may interest you: