Serverspace Black Friday
VB
November 13, 2022
Updated November 13, 2022

How to install PostgreSQL on Ubuntu 20.04

Databases Ubuntu

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 processing

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 repository file
  • Install PostgreSQL from system repositories:
apt install postgresql postgresql-contrib -y

pic2

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

pic3

  • Check the status:
service postgresql status

pic4

Data operations

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

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

pic5

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

pic6

  • Let's try to create table into the database:

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

pic7

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

  • Adding data:

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

pic8

  • Show table content:
SELECT <content> from <table_name>

pic9

Conclusion

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

Vote:
5 out of 5
Аverage rating : 5
Rated by: 1
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.