07.06.2023

How to install PostgreSQL on Ubuntu 20.04

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 processing

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

yum -y update

apt install postgresql postgresql-contrib -y

systemctl enable postgresql.service; service postgresql 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 test_table (
item_id integer NOT NULL,
item_name character varying(80) NOT NULL,
item_desc character varying(80) DEFAULT NULL,
PRIMARY KEY (item_id)
);

I created a table with three columns, item_id (digit),  item_name (text row) and item_desc (text, optional).

INSERT INTO test_table (item_id, item_name, item_desc)
VALUES('1','toy car','Red sportcar model');

INSERT INTO test_table (item_id, item_name, item_desc)
VALUES('2','toy soldier','tin soldier figure');

INSERT INTO test_table (item_id, item_name, item_desc)
VALUES('3','ball','Original soccer ball');

SELECT <content> from <table_name>

Conclusion

In this article I described how to install PostgreSQL on Ubuntu 20.04 LTS and expained some base SQL operations.