You are on page 1of 9

[root@centos02 opt]# rpm -qa | grep -i postgres

[root@centos02 opt]# yum install


https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-
repo-latest.noarch.rpm -y

Loaded plugins: fastestmirror, langpacks


pgdg-redhat-repo-latest.noarch.rpm
| 6.8 kB 00:00:00
Examining /var/tmp/yum-root-5mMsH8/pgdg-redhat-repo-latest.noarch.rpm: pgdg-redhat-
repo-42.0-14.noarch
Marking /var/tmp/yum-root-5mMsH8/pgdg-redhat-repo-latest.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package pgdg-redhat-repo.noarch 0:42.0-14 will be installed
--> Finished Dependency Resolution
base/7/x86_64
| 3.6 kB 00:00:00
epel/x86_64/metalink
| 14 kB 00:00:00
epel/x86_64
| 4.7 kB 00:00:00
epel/x86_64/updateinfo
| 1.0 MB 00:00:00
epel/x86_64/primary_db
| 6.9 MB 00:00:00
extras/7/x86_64
| 2.9 kB 00:00:00
mariadb-main
| 2.9 kB 00:00:00
mariadb-maxscale
| 2.4 kB 00:00:00
mariadb-tools
| 2.9 kB 00:00:00
mysql-connectors-community/x86_64
| 2.6 kB 00:00:00
mysql-tools-community/x86_64
| 2.6 kB 00:00:00
mysql80-community/x86_64
| 2.6 kB 00:00:00
percona-release-noarch/7
| 2.9 kB 00:00:00
percona-release-x86_64/7
| 2.9 kB 00:00:00
pgdg94
| 2.1 kB 00:00:00
prel-release-noarch/7
| 2.9 kB 00:00:00
updates/7/x86_64
| 2.9 kB 00:00:00

Dependencies Resolved

===================================================================================
===================================================================================
==================
Package Arch
Version Repository
Size
===================================================================================
===================================================================================
==================
Installing:
pgdg-redhat-repo noarch
42.0-14 /pgdg-redhat-repo-latest.noarch
11 k

Transaction Summary
===================================================================================
===================================================================================
==================
Install 1 Package

Total size: 11 k
Installed size: 11 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : pgdg-redhat-repo-42.0-14.noarch
1/1
Verifying : pgdg-redhat-repo-42.0-14.noarch
1/1

Installed:
pgdg-redhat-repo.noarch 0:42.0-14

Complete!

####################################################################

[root@centos02 opt]# yum install postgresql95-server.x86_64 postgresql95.x86_64


postgresql95-contrib.x86_64 postgresql95-libs.x86_64 postgresql95-plperl.x86_64
postgresql95-plpython.x86_64 postgresql95-plpython3.x86_64 -y

Loaded plugins: fastestmirror, langpacks


Determining fastest mirrors
* base: mirrors.cmich.edu
* epel: mirror.twinlakes.net
* extras: mirror.cs.vt.edu
* updates: mirrors.cmich.edu
pgdg-common
| 2.9 kB 00:00:00
pgdg10
| 3.6 kB 00:00:00
pgdg11
| 3.6 kB 00:00:00
pgdg12
| 3.6 kB 00:00:00
pgdg13
| 3.6 kB 00:00:00
pgdg95
| 3.6 kB 00:00:00
pgdg96
| 3.6 kB 00:00:00
(1/13): pgdg10/7/x86_64/group_gz
| 245 B 00:00:01
(2/13): pgdg12/7/x86_64/group_gz
| 245 B 00:00:00
(3/13): pgdg11/7/x86_64/group_gz
| 245 B 00:00:01
(4/13): pgdg-common/7/x86_64/primary_db
| 123 kB 00:00:01
(5/13): pgdg13/7/x86_64/group_gz
| 246 B 00:00:00
(6/13): pgdg12/7/x86_64/primary_db
| 182 kB 00:00:00
(7/13): pgdg95/7/x86_64/group_gz
| 249 B 00:00:00
(8/13): pgdg10/7/x86_64/primary_db
| 306 kB 00:00:01
(9/13): pgdg13/7/x86_64/primary_db
| 92 kB 00:00:00
(10/13): pgdg96/7/x86_64/group_gz
| 249 B 00:00:00
(11/13): pgdg95/7/x86_64/primary_db
| 272 kB 00:00:00
(12/13): pgdg11/7/x86_64/primary_db
| 320 kB 00:00:02
(13/13): pgdg96/7/x86_64/primary_db
| 299 kB 00:00:00
Resolving Dependencies
--> Running transaction check
---> Package postgresql95.x86_64 0:9.5.25-1PGDG.rhel7 will be installed
---> Package postgresql95-contrib.x86_64 0:9.5.25-1PGDG.rhel7 will be installed
---> Package postgresql95-libs.x86_64 0:9.5.25-1PGDG.rhel7 will be installed
---> Package postgresql95-plperl.x86_64 0:9.5.25-1PGDG.rhel7 will be installed
---> Package postgresql95-plpython.x86_64 0:9.5.25-1PGDG.rhel7 will be installed
---> Package postgresql95-plpython3.x86_64 0:9.5.25-1PGDG.rhel7 will be installed
---> Package postgresql95-server.x86_64 0:9.5.25-1PGDG.rhel7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===================================================================================
===================================================================================
==================
Package Arch
Version Repository
Size
===================================================================================
===================================================================================
==================
Installing:
postgresql95 x86_64
9.5.25-1PGDG.rhel7 pgdg95
1.4 M
postgresql95-contrib x86_64
9.5.25-1PGDG.rhel7 pgdg95
542 k
postgresql95-libs x86_64
9.5.25-1PGDG.rhel7 pgdg95
230 k
postgresql95-plperl x86_64
9.5.25-1PGDG.rhel7 pgdg95
71 k
postgresql95-plpython x86_64
9.5.25-1PGDG.rhel7 pgdg95
86 k
postgresql95-plpython3 x86_64
9.5.25-1PGDG.rhel7 pgdg95
85 k
postgresql95-server x86_64
9.5.25-1PGDG.rhel7 pgdg95
4.2 M

Transaction Summary
===================================================================================
===================================================================================
==================
Install 7 Packages

Total download size: 6.6 M


Installed size: 28 M
Downloading packages:
(1/7): postgresql95-contrib-9.5.25-1PGDG.rhel7.x86_64.rpm
| 542 kB 00:00:03
(2/7): postgresql95-9.5.25-1PGDG.rhel7.x86_64.rpm
| 1.4 MB 00:00:03
(3/7): postgresql95-libs-9.5.25-1PGDG.rhel7.x86_64.rpm
| 230 kB 00:00:00
(4/7): postgresql95-plperl-9.5.25-1PGDG.rhel7.x86_64.rpm
| 71 kB 00:00:00
(5/7): postgresql95-plpython-9.5.25-1PGDG.rhel7.x86_64.rpm
| 86 kB 00:00:00
(6/7): postgresql95-plpython3-9.5.25-1PGDG.rhel7.x86_64.rpm
| 85 kB 00:00:00
(7/7): postgresql95-server-9.5.25-1PGDG.rhel7.x86_64.rpm
| 4.2 MB 00:00:00
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
------------------
Total
1.5 MB/s | 6.6 MB 00:00:04
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : postgresql95-libs-9.5.25-1PGDG.rhel7.x86_64
1/7
Installing : postgresql95-9.5.25-1PGDG.rhel7.x86_64
2/7
Installing : postgresql95-server-9.5.25-1PGDG.rhel7.x86_64
3/7
Installing : postgresql95-contrib-9.5.25-1PGDG.rhel7.x86_64
4/7
Installing : postgresql95-plpython-9.5.25-1PGDG.rhel7.x86_64
5/7
Installing : postgresql95-plpython3-9.5.25-1PGDG.rhel7.x86_64
6/7
Installing : postgresql95-plperl-9.5.25-1PGDG.rhel7.x86_64
7/7
Verifying : postgresql95-contrib-9.5.25-1PGDG.rhel7.x86_64
1/7
Verifying : postgresql95-server-9.5.25-1PGDG.rhel7.x86_64
2/7
Verifying : postgresql95-plpython-9.5.25-1PGDG.rhel7.x86_64
3/7
Verifying : postgresql95-libs-9.5.25-1PGDG.rhel7.x86_64
4/7
Verifying : postgresql95-plpython3-9.5.25-1PGDG.rhel7.x86_64
5/7
Verifying : postgresql95-9.5.25-1PGDG.rhel7.x86_64
6/7
Verifying : postgresql95-plperl-9.5.25-1PGDG.rhel7.x86_64
7/7

Installed:
postgresql95.x86_64 0:9.5.25-1PGDG.rhel7 postgresql95-
contrib.x86_64 0:9.5.25-1PGDG.rhel7 postgresql95-libs.x86_64 0:9.5.25-
1PGDG.rhel7
postgresql95-plperl.x86_64 0:9.5.25-1PGDG.rhel7 postgresql95-
plpython.x86_64 0:9.5.25-1PGDG.rhel7 postgresql95-plpython3.x86_64
0:9.5.25-1PGDG.rhel7
postgresql95-server.x86_64 0:9.5.25-1PGDG.rhel7

Complete!

############################################

[root@centos02 opt]# rpm -qa | grep -i postgres

postgresql95-libs-9.5.25-1PGDG.rhel7.x86_64
postgresql95-contrib-9.5.25-1PGDG.rhel7.x86_64
postgresql95-plperl-9.5.25-1PGDG.rhel7.x86_64
postgresql95-9.5.25-1PGDG.rhel7.x86_64
postgresql95-plpython-9.5.25-1PGDG.rhel7.x86_64
postgresql95-server-9.5.25-1PGDG.rhel7.x86_64
postgresql95-plpython3-9.5.25-1PGDG.rhel7.x86_64

#################################################### Investigate the server Package

[root@centos02 opt]# rpm -ql postgresql95-server-9.5.25-1PGDG.rhel7.x86_64


/etc/pam.d/postgresql
/etc/sysconfig/pgsql
/usr/lib/systemd/system/postgresql-9.5.service
/usr/lib/tmpfiles.d/postgresql-9.5.conf
/usr/pgsql-9.5/bin/initdb

#################################################### Login as the postgres user and


initialize your database:

[root@centos02 opt]# su - postgres


-bash-4.2$ /usr/pgsql-9.5/bin/initdb -D /var/lib/pgsql/9.5/data

The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".


The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /var/lib/pgsql/9.5/data ... ok


creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default timezone ... America/New_York
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
creating template1 database in /var/lib/pgsql/9.5/data/base/1 ... ok
initializing pg_authid ... ok
initializing dependencies ... ok
creating system views ... ok
loading system objects' descriptions ... ok
creating collations ... ok
creating conversions ... ok
creating dictionaries ... ok
setting privileges on built-in objects ... ok
creating information schema ... ok
loading PL/pgSQL server-side language ... ok
vacuuming database template1 ... ok
copying template1 to template0 ... ok
copying template1 to postgres ... ok
syncing data to disk ... ok

WARNING: enabling "trust" authentication for local connections


You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

/usr/pgsql-9.5/bin/pg_ctl -D /var/lib/pgsql/9.5/data -l logfile start

######################### I will start the server and create an error log in the
data directory called pgerror-logfile with the -l option and also run the command
in the background with &

/usr/pgsql-9.5/bin/pg_ctl -D /var/lib/pgsql/9.5/data -l
/var/lib/pgsql/9.5/data/pgerror-logfile start &

-bash-4.2$ /usr/pgsql-9.5/bin/pg_ctl -D /var/lib/pgsql/9.5/data -l


/var/lib/pgsql/9.5/data/pgerror-logfile start &
[1] 456
-bash-4.2$ server starting

[1]+ Done /usr/pgsql-9.5/bin/pg_ctl -D /var/lib/pgsql/9.5/data


-l /var/lib/pgsql/9.5/data/pgerror-logfile start

################################################# Check the server status

-bash-4.2$ /usr/pgsql-9.5/bin/pg_ctl -D /var/lib/pgsql/9.5/data status


pg_ctl: server is running (PID: 458)
/usr/pgsql-9.5/bin/postgres "-D" "/var/lib/pgsql/9.5/data"

###################### Verify all the server processes are running:

-bash-4.2$ ps -ef | grep -i postgres


postgres 458 1 0 17:55 pts/1 00:00:00 /usr/pgsql-9.5/bin/postgres -D
/var/lib/pgsql/9.5/data
postgres 459 458 0 17:55 ? 00:00:00 postgres: logger process
postgres 461 458 0 17:55 ? 00:00:00 postgres: checkpointer process
postgres 462 458 0 17:55 ? 00:00:00 postgres: writer process
postgres 463 458 0 17:55 ? 00:00:00 postgres: wal writer process
postgres 464 458 0 17:55 ? 00:00:00 postgres: autovacuum launcher
process
postgres 465 458 0 17:55 ? 00:00:00 postgres: stats collector process
postgres 466 32765 0 17:56 pts/1 00:00:00 ps -ef
postgres 467 32765 0 17:56 pts/1 00:00:00 grep --color=auto -i postgres
root 32764 31163 0 17:50 pts/1 00:00:00 su - postgres
postgres 32765 32764 0 17:50 pts/1 00:00:00 -bash
-bash-4.2$

########################## Test stopping and starting the server:

-bash-4.2$ /usr/pgsql-9.5/bin/pg_ctl stop


waiting for server to shut down.... done
server stopped

-bash-4.2$ /usr/pgsql-9.5/bin/pg_ctl start


server starting

-bash-4.2$ < 2021-03-15 17:59:41.200 EDT >LOG: redirecting log output to logging
collector process
< 2021-03-15 17:59:41.200 EDT >HINT: Future log output will appear in directory
"pg_log".

-bash-4.2$ ps -ef | grep -i postgres


postgres 506 1 0 17:59 pts/1 00:00:00 /usr/pgsql-9.5/bin/postgres
postgres 507 506 0 17:59 ? 00:00:00 postgres: logger process
postgres 509 506 0 17:59 ? 00:00:00 postgres: checkpointer process
postgres 510 506 0 17:59 ? 00:00:00 postgres: writer process
postgres 511 506 0 17:59 ? 00:00:00 postgres: wal writer process
postgres 512 506 0 17:59 ? 00:00:00 postgres: autovacuum launcher
process
postgres 513 506 0 17:59 ? 00:00:00 postgres: stats collector process
postgres 514 32765 0 17:59 pts/1 00:00:00 ps -ef
postgres 516 32765 0 17:59 pts/1 00:00:00 grep --color=auto -i postgres
root 32764 31163 0 17:50 pts/1 00:00:00 su - postgres
postgres 32765 32764 0 17:50 pts/1 00:00:00 -bash
-bash-4.2$
######################################### Get certification notes and load sample
databases:

https://github.com/ropable/foundation_postgres

cd /opt

git clone https://github.com/ropable/foundation_postgres

http://www.postgresqltutorial.com/postgresql-sample-database/

cd /opt
wget http://www.postgresqltutorial.com/wp-content/uploads/2019/05/dvdrental.zip

unzip dvdrental.zip

ls -ali

su - postgres

createdb dvdrental;

pg_restore -Ft -d dvdrental -U postgres /opt/dvdrental.tar

or

[root@centos01 opt]# mkdir -p /postgres-education


[root@centos01 opt]# cd /postgres-education/
[root@centos01 postgres-education]#
[root@centos01 opt]# git clone https://github.com/ropable/foundation_postgres
Cloning into 'foundation_postgres'...
remote: Enumerating objects: 219, done.
remote: Total 219 (delta 0), reused 0 (delta 0), pack-reused 219
Receiving objects: 100% (219/219), 2.41 MiB | 0 bytes/s, done.
Resolving deltas: 100% (120/120), done.

[root@centos01 postgres-education]# pg_restore -Ft -d dvdrental -U postgres


dvdrental.tar

-bash-4.2$ psql -l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+-------------+-------------
+-----------------------
dvdrental | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres
+
| | | | |
postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres
+
| | | | |
postgres=CTc/postgres
(4 rows)

You might also like