In this we will explain how to install postgres 14.( Though installation steps are same for all versions).
1. Download the postgres server rpms.
https://yum.postgresql.org/rpmchart/
2.Install the rpms( in the below sequence).
Make sure to follow the below order while installing the rpm, Otherwise dependency error will come.
total 16128
-rwxr-xr-x 1 root root 698212 Jul 10 12:17 postgresql14-contrib-14.2-1PGDG.rhel7.x86_64.rpm
-rwxr-xr-x 1 root root 1556440 Jul 10 12:17 postgresql14-14.2-1PGDG.rhel7.x86_64.rpm
-rwxr-xr-x 1 root root 273192 Jul 10 12:17 postgresql14-libs-14.2-1PGDG.rhel7.x86_64.rpm
-rwxr-xr-x 1 root root 5783224 Jul 10 12:17 postgresql14-server-14.2-1PGDG.rhel7.x86_64.rpm
[root@]# <span style="color: #993300;"><strong>rpm -ivh postgresql14-libs-14.2-1PGDG.rhel7.x86_64.rpm</strong></span>
warning: postgresql14-libs-14.2-1PGDG.rhel7.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:postgresql14-libs-14.2-1PGDG.rhel################################# [100%]
[root@ ]# <span style="color: #993300;"><strong>rpm -ivh postgresql14-14.2-1PGDG.rhel7.x86_64.rpm</strong></span>
warning: postgresql14-14.2-1PGDG.rhel7.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:postgresql14-14.2-1PGDG.rhel7 ################################# [100%]
[root@ ]#<span style="color: #993300;"><strong> rpm -ivh postgresql14-server-14.2-1PGDG.rhel7.x86_64.rpm</strong></span>
warning: postgresql14-server-14.2-1PGDG.rhel7.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:postgresql14-server-14.2-1PGDG.rh################################# [100%]
[root@]# <span style="color: #993300;"><strong>rpm -ivh postgresql14-contrib-14.2-1PGDG.rhel7.x86_64.rpm</strong></span>
warning: postgresql14-contrib-14.2-1PGDG.rhel7.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:postgresql14-contrib-14.2-1PGDG.r################################# [100%]
Once the rpms are installed, an osuser postgres user will be created and postgres binaries will be created /usr directory.
3. Initialize the postgres cluster:
--Create a data directory and log_directory
mkdir -p /oracle/pg_data
mkdir -p /oracle/pg_data/log
--- Initialize the cluster:
[postgres bin]$ <span style="color: #993300;"><strong>/usr/pgsql-14/bin/initdb --pgdata /oracle/pg_data</strong></span>
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 /oracle/pg_data ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Asia/Riyadh
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok
initdb: 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-14/bin/pg_ctl -D /oracle/pg_data -l logfile start
4. Start postgres cluster;
[postgres@pg_data]$ <span style="color: #993300;"><strong>/usr/pgsql-14/bin/pg_ctl -D /oracle/pg_data -l logfile start</strong></span>
waiting for server to start.... done
server started
[postgres@pg_data]$<span style="color: #993300;"><strong> psql -d postgres -p 5432</strong></span>
psql (14.2)
Type "help" for help.
postgres=# <span style="color: #993300;"><strong>\list</strong></span>
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
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
(3 rows)
postgres=#
If you want to be able to connect to this server remotely , then modify listen_addresses parameter in postgres.conf file and restart the cluster.
vi /oracle/pg_data/postgres.conf
<span style="color: #993300;"><strong>listen_addresses='*'</strong></span>
postgres$ <span style="color: #993300;"><strong>/usr/pgsql-14/bin/pg_ctl stop -D /oracle/pg_data</strong></span>
postgres$ <span style="color: #993300;"><strong>/usr/pgsql-14/bin/pg_ctl start -D /oracle/pg_data</strong></span>