Search This Blog

Thursday 4 February 2021

Install and configure PostgreSQL Data Base

PostgreSQL Installation and configuration on Linux (CentOS)

yum install postgresql-server postgresql-contrib -y

systemctl enable postgresql 

postgresql-setup initdb

systemctl start postgresql

systemctl status postgresql

su - postgres

psql postgres

CREATE USER sample_top WITH ENCRYPTED PASSWORD 'dCV3szSGNA';

CREATE DATABASE sample_db4 OWNER sample_top;

GRANT ALL PRIVILEGES ON DATABASE sample_db4 TO sample_top;


vi /var/lib/pgsql/data/pg_hba.conf

local all all md5

host sample_db4 sample_top 127.0.0.1/32 md5

host sample_db4 sample_top ::1/128 md5


vi /var/lib/pgsql/data/postgresql.conf

listen_addresses= '*'

systemctl restart postgresql

systemctl status postgresql


#Authentication

psql -U sample_top -d sample_db4 -h 127.0.0.1 -W


Installation Log:



 login as: osboxes

osboxes@192.168.1.198's password:

Web console: https://localhost:9090/ or https://192.168.1.198:9090/

Last login: Sat Jan 30 19:18:42 2021 from 192.168.1.5

[osboxes@master ~]$ sudo su -

[sudo] password for osboxes:

[root@master ~]# yum install postgresql-server postgresql-contrib

Last metadata expiration check: 0:26:09 ago on Thu 04 Feb 2021 02:11:21 AM EST.

Dependencies resolved.

=============================================================================================================================================================

 Package                               Architecture              Version                                                  Repository                    Size

=============================================================================================================================================================

Installing:

 postgresql-contrib                    x86_64                    10.15-1.module_el8.3.0+619+dbc95fbc                      AppStream                    805 k

 postgresql-server                     x86_64                    10.15-1.module_el8.3.0+619+dbc95fbc                      AppStream                    5.0 M

Installing dependencies:

 libpq                                 x86_64                    12.4-1.el8_2                                             AppStream                    195 k

 postgresql                            x86_64                    10.15-1.module_el8.3.0+619+dbc95fbc                      AppStream                    1.5 M

 uuid                                  x86_64                    1.6.2-42.el8                                             AppStream                     63 k

Enabling module streams:

 postgresql                                                      10



Transaction Summary

=============================================================================================================================================================

Install  5 Packages



Total download size: 7.6 M

Installed size: 29 M

Is this ok [y/N]: y

Downloading Packages:

(1/5): libpq-12.4-1.el8_2.x86_64.rpm                                                                                         672 kB/s | 195 kB     00:00

(2/5): postgresql-contrib-10.15-1.module_el8.3.0+619+dbc95fbc.x86_64.rpm                                                     1.8 MB/s | 805 kB     00:00

(3/5): uuid-1.6.2-42.el8.x86_64.rpm                                                                                          1.2 MB/s |  63 kB     00:00

(4/5): postgresql-10.15-1.module_el8.3.0+619+dbc95fbc.x86_64.rpm                                                             3.0 MB/s | 1.5 MB     00:00

(5/5): postgresql-server-10.15-1.module_el8.3.0+619+dbc95fbc.x86_64.rpm                                                      4.6 MB/s | 5.0 MB     00:01

-------------------------------------------------------------------------------------------------------------------------------------------------------------

Total                                                                                                                        4.8 MB/s | 7.6 MB     00:01

Running transaction check

Transaction check succeeded.

Running transaction test

Transaction test succeeded.

Running transaction

  Preparing        :                                                                                                                                     1/1

  Installing       : libpq-12.4-1.el8_2.x86_64                                                                                                           1/5

  Installing       : postgresql-10.15-1.module_el8.3.0+619+dbc95fbc.x86_64                                                                               2/5

  Installing       : uuid-1.6.2-42.el8.x86_64                                                                                                            3/5

  Running scriptlet: uuid-1.6.2-42.el8.x86_64                                                                                                            3/5

  Installing       : postgresql-contrib-10.15-1.module_el8.3.0+619+dbc95fbc.x86_64                                                                       4/5

  Running scriptlet: postgresql-server-10.15-1.module_el8.3.0+619+dbc95fbc.x86_64                                                                        5/5

  Installing       : postgresql-server-10.15-1.module_el8.3.0+619+dbc95fbc.x86_64                                                                        5/5

  Running scriptlet: postgresql-server-10.15-1.module_el8.3.0+619+dbc95fbc.x86_64                                                                        5/5

  Verifying        : libpq-12.4-1.el8_2.x86_64                                                                                                           1/5

  Verifying        : postgresql-10.15-1.module_el8.3.0+619+dbc95fbc.x86_64                                                                               2/5

  Verifying        : postgresql-contrib-10.15-1.module_el8.3.0+619+dbc95fbc.x86_64                                                                       3/5

  Verifying        : postgresql-server-10.15-1.module_el8.3.0+619+dbc95fbc.x86_64                                                                        4/5

  Verifying        : uuid-1.6.2-42.el8.x86_64                                                                                                            5/5

Installed products updated.



Installed:

  libpq-12.4-1.el8_2.x86_64                                                     postgresql-10.15-1.module_el8.3.0+619+dbc95fbc.x86_64

  postgresql-contrib-10.15-1.module_el8.3.0+619+dbc95fbc.x86_64                 postgresql-server-10.15-1.module_el8.3.0+619+dbc95fbc.x86_64

  uuid-1.6.2-42.el8.x86_64



Complete!



[root@master ~]# systemctl enable postgresql && systemctl start postgresql

Created symlink /etc/systemd/system/multi-user.target.wants/postgresql.service → /usr/lib/systemd/system/postgresql.service.


[root@master ~]# systemctl status postgresql

● postgresql.service - PostgreSQL database server

   Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; vendor preset: disabled)

   Active: active (running) since Thu 2021-02-04 02:38:35 EST; 8s ago

  Process: 3789 ExecStartPre=/usr/libexec/postgresql-check-db-dir postgresql (code=exited, status=0/SUCCESS)

 Main PID: 3791 (postmaster)

    Tasks: 8 (limit: 11343)

   Memory: 16.1M

   CGroup: /system.slice/postgresql.service

           ├─3791 /usr/bin/postmaster -D /var/lib/pgsql/data

           ├─3793 postgres: logger process

           ├─3795 postgres: checkpointer process

           ├─3796 postgres: writer process

           ├─3797 postgres: wal writer process

           ├─3798 postgres: autovacuum launcher process

           ├─3799 postgres: stats collector process

           └─3800 postgres: bgworker: logical replication launcher



Feb 04 02:38:35 master systemd[1]: Starting PostgreSQL database server...

Feb 04 02:38:35 master postmaster[3791]: 2021-02-04 02:38:35.875 EST [3791] LOG:  listening on IPv6 address "::1", port 5432

Feb 04 02:38:35 master postmaster[3791]: 2021-02-04 02:38:35.875 EST [3791] LOG:  listening on IPv4 address "127.0.0.1", port 5432

Feb 04 02:38:35 master postmaster[3791]: 2021-02-04 02:38:35.877 EST [3791] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"

Feb 04 02:38:35 master postmaster[3791]: 2021-02-04 02:38:35.879 EST [3791] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"

Feb 04 02:38:35 master postmaster[3791]: 2021-02-04 02:38:35.893 EST [3791] LOG:  redirecting log output to logging collector process

Feb 04 02:38:35 master postmaster[3791]: 2021-02-04 02:38:35.893 EST [3791] HINT:  Future log output will appear in directory "log".

Feb 04 02:38:35 master systemd[1]: Started PostgreSQL database server.



[root@master ~]# su - postgres

[postgres@master ~]$ psql postgres

psql (10.15)

Type "help" for help.

postgres=# CREATE USER sample_top WITH ENCRYPTED PASSWORD 'dCV3szSGNA';

CREATE ROLE

postgres=# CREATE DATABASE sample_db4 OWNER sample_tim;

ERROR:  role "sample_tim" does not exist

postgres=# CREATE DATABASE sample_db4 OWNER sample_top;

CREATE DATABASE

postgres=# GRANT ALL PRIVILEGES ON DATABASE sample_db4 TO sample_top;

GRANT

postgres=# \q

[postgres@master ~]$ vi /var/lib/pgsql/data/pg_hba.conf

[postgres@master ~]$ vi /var/lib/pgsql/data/postgresql.conf

[postgres@master ~]$ systemctl restart postgresql.service

==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ====

Authentication is required to restart 'postgresql.service'.

Authenticating as: osboxes.org (osboxes)

Password:

[postgres@master ~]$ exit

logout

[root@master ~]# systemctl restart postgresql.service

[root@master ~]# systemctl status postgresql.service

● postgresql.service - PostgreSQL database server

   Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; vendor preset: disabled)

   Active: active (running) since Thu 2021-02-04 02:46:55 EST; 8s ago

  Process: 4121 ExecStartPre=/usr/libexec/postgresql-check-db-dir postgresql (code=exited, status=0/SUCCESS)

 Main PID: 4124 (postmaster)

    Tasks: 8 (limit: 11343)

   Memory: 16.1M

   CGroup: /system.slice/postgresql.service

           ├─4124 /usr/bin/postmaster -D /var/lib/pgsql/data

           ├─4126 postgres: logger process

           ├─4128 postgres: checkpointer process

           ├─4129 postgres: writer process

           ├─4130 postgres: wal writer process

           ├─4131 postgres: autovacuum launcher process

           ├─4132 postgres: stats collector process

           └─4133 postgres: bgworker: logical replication launcher



Feb 04 02:46:55 master systemd[1]: Stopped PostgreSQL database server.

Feb 04 02:46:55 master systemd[1]: Starting PostgreSQL database server...

Feb 04 02:46:55 master postmaster[4124]: 2021-02-04 02:46:55.294 EST [4124] LOG:  listening on IPv4 address "0.0.0.0", port 5432

Feb 04 02:46:55 master postmaster[4124]: 2021-02-04 02:46:55.294 EST [4124] LOG:  listening on IPv6 address "::", port 5432

Feb 04 02:46:55 master postmaster[4124]: 2021-02-04 02:46:55.296 EST [4124] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"

Feb 04 02:46:55 master postmaster[4124]: 2021-02-04 02:46:55.297 EST [4124] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"

Feb 04 02:46:55 master postmaster[4124]: 2021-02-04 02:46:55.312 EST [4124] LOG:  redirecting log output to logging collector process

Feb 04 02:46:55 master postmaster[4124]: 2021-02-04 02:46:55.312 EST [4124] HINT:  Future log output will appear in directory "log".

Feb 04 02:46:55 master systemd[1]: Started PostgreSQL database server.

[root@master ~]# psql -U sample_top -d sample_db4 -h 127.0.0.1 -W

Password for user sample_top:

psql (10.15)

Type "help" for help.



sample_db4=>


No comments: