Steps to install postgres SQL on AWS EC2 (RHEL)

1. Connect to Linux EC2 Instance by Using Putty and private keys

We can connect putty by using below link.

Connect to PostgreSQL Server Using Putty

Using username “ec2-user”.
Authenticating with public key “imported-openssh-key”
Register this system with Red Hat Insights: insights-client –register
Create an account or view all your systems at https://red.ht/insights-dashboard
Last login: Wed Feb 8 14:50:03 2023 from 49.36.50.5
[ec2-user@ip-10-0-1-138 ~]$ s

2. Switch to root

[ec2-user@ip-10-0-1-138 ~]$ sudo su – root
Last login: Wed Feb 8 14:50:07 UTC 2023 on pts/1
[root@ip-10-0-1-138 ~]#

3. Install Server Updates

[root@ip-10-0-1-138 ec2-user]# yum update -y
Red Hat Update Infrastructure 3 Client Configuration Server 8 14 kB/s | 3.5 kB 00:00
Red Hat Enterprise Linux 8 for x86_64 – AppStream from RHUI (RPMs) 39 MB/s | 25 MB 00:00
Red Hat Enterprise Linux 8 for x86_64 – BaseOS from RHUI (RPMs) 43 MB/s | 26 MB 00:00

Dependencies resolved.

Package Architecture Version Repository Size

Installing:
kernel x86_64 4.18.0-240.8.1.el8_3 rhel-8-baseos-rhui-rpms 4.3 M
kernel-core x86_64 4.18.0-240.8.1.el8_3 rhel-8-baseos-rhui-rpms 30 M
kernel-modules x86_64 4.18.0-240.8.1.el8_3 rhel-8-baseos-rhui-rpms 26 M
Upgrading:
NetworkManager x86_64 1:1.26.0-12.el8_3 rhel-8-baseos-rhui-rpms 2.4 M
NetworkManager-libnm x86_64 1:1.26.0-12.el8_3 rhel-8-baseos-rhui-rpms 1.8 M
NetworkManager-team x86_64 1:1.26.0-12.el8_3 rhel-8-baseos-rhui-rpms 142 k
NetworkManager-tui x86_64 1:1.26.0-12.el8_3 rhel-8-baseos-rhui-rpms 320 k
cloud-init noarch 19.4-11.el8_3.1 rhel-8-appstream-rhui-rpms 945 k
curl x86_64 7.61.1-14.el8_3.1 rhel-8-baseos-rhui-rpms 353 k
freetype x86_64 2.9.1-4.el8_3.1 rhel-8-baseos-rhui-rpms 394 k
gnutls x86_64 3.6.14-7.el8_3 rhel-8-baseos-rhui-rpms 1.0 M
insights-client noarch 3.1.1-1.el8_3 rhel-8-appstream-rhui-rpms 1.0 M
iptables-libs x86_64 1.8.4-15.el8_3.3 rhel-8-baseos-rhui-rpms 106 k
kernel-tools x86_64 4.18.0-240.8.1.el8_3 rhel-8-baseos-rhui-rpms 4.5 M
kernel-tools-libs x86_64 4.18.0-240.8.1.el8_3 rhel-8-baseos-rhui-rpms 4.3 M
kexec-tools x86_64 2.0.20-34.el8_3.1 rhel-8-baseos-rhui-rpms 496 k
libcurl x86_64 7.61.1-14.el8_3.1 rhel-8-baseos-rhui-rpms 299 k
microcode_ctl x86_64 4:20200609-2.20201112.1.el8_3 rhel-8-baseos-rhui-rpms 4.6 M
openssl x86_64 1:1.1.1g-12.el8_3 rhel-8-baseos-rhui-rpms 707 k
openssl-libs x86_64 1:1.1.1g-12.el8_3 rhel-8-baseos-rhui-rpms 1.5 M
python3-perf x86_64 4.18.0-240.8.1.el8_3 rhel-8-baseos-rhui-rpms 4.4 M
qemu-guest-agent x86_64 15:4.2.0-34.module+el8.3.0+8829+e7a0a3ea.1 rhel-8-appstream-rhui-rpms 228 k
systemd x86_64 239-41.el8_3.1 rhel-8-baseos-rhui-rpms 3.5 M
systemd-libs x86_64 239-41.el8_3.1 rhel-8-baseos-rhui-rpms 1.1 M
systemd-pam x86_64 239-41.el8_3.1 rhel-8-baseos-rhui-rpms 456 k
systemd-udev x86_64 239-41.el8_3.1 rhel-8-baseos-rhui-rpms 1.3 M
tuned noarch 2.14.0-3.el8_3.1 rhel-8-baseos-rhui-rpms 292 k
Installing dependencies:
linux-firmware noarch 20200619-101.git3890db36.el8_3 rhel-8-baseos-rhui-rpms 101 M

Transaction Summary

Install 4 Packages
Upgrade 24 Packages

Total download size: 198 M
Downloading Packages:
(1/28): kernel-4.18.0-240.8.1.el8_3.x86_64.rpm 15 MB/s | 4.3 MB 00:00
(2/28): kernel-core-4.18.0-240.8.1.el8_3.x86_64.rpm 33 MB/s | 30 MB 00:00
(3/28): kernel-modules-4.18.0-240.8.1.el8_3.x86_64.rpm 22 MB/s | 26 MB 00:01
(4/28): cloud-init-19.4-11.el8_3.1.noarch.rpm 3.6 MB/s | 945 kB 00:00
(5/28): qemu-guest-agent-4.2.0-34.module+el8.3.0+8829+e7a0a3ea.1.x86_64.rpm 1.9 MB/s | 228 kB 00:00
(6/28): insights-client-3.1.1-1.el8_3.noarch.rpm 6.8 MB/s | 1.0 MB 00:00
(7/28): NetworkManager-team-1.26.0-12.el8_3.x86_64.rpm 1.3 MB/s | 142 kB 00:00

(8/28): freetype-2.9.1-4.el8_3.1.x86_64.rpm 3.1 MB/s | 394 kB 00:00

Total 64 MB/s | 198 MB 00:03
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Running scriptlet: systemd-libs-239-41.el8_3.1.x86_64 1/1
Upgrading : systemd-libs-239-41.el8_3.1.x86_64 1/52
Running scriptlet: systemd-libs-239-41.el8_3.1.x86_64 1/52
Upgrading : gnutls-3.6.14-7.el8_3.x86_64 2/52
Upgrading : openssl-libs-1:1.1.1g-12.el8_3.x86_64 3/52
Running scriptlet: openssl-libs-1:1.1.1g-12.el8_3.x86_64 3/52
Upgrading : libcurl-7.61.1-14.el8_3.1.x86_64 4/52
Upgrading : NetworkManager-libnm-1:1.26.0-12.el8_3.x86_64 5/52
Running scriptlet: NetworkManager-libnm-1:1.26.0-12.el8_3.x86_64 5/52
Upgrading : iptables-libs-1.8.4-15.el8_3.3.x86_64 6/52
Running scriptlet: systemd-239-41.el8_3.1.x86_64 7/52
Upgrading : systemd-239-41.el8_3.1.x86_64 7/52
Running scriptlet: systemd-239-41.el8_3.1.x86_64 7/52
Upgrading : systemd-pam-239-41.el8_3.1.x86_64 8/52
Verifying : kernel-modules-4.18.0-240.8.1.el8_3.x86_64 1/52
Verifying : kernel-core-4.18.0-240.8.1.el8_3.x86_64 2/52
Verifying : kernel-4.18.0-240.8.1.el8_3.x86_64 3/52
Verifying : linux-firmware-20200619-101.git3890db36.el8_3.noarch 4/52
Verifying : cloud-init-19.4-11.el8_3.1.noarch 5/52
Verifying : cloud-init-19.4-11.el8.noarch 6/52
Verifying : insights-client-3.1.1-1.el8_3.noarch 7/52
Verifying : insights-client-3.1.0-3.el8.noarch 8/52
Upgraded:
NetworkManager-1:1.26.0-12.el8_3.x86_64 NetworkManager-libnm-1:1.26.0-12.el8_3.x86_64 NetworkManager-team-1:1.26.0-12.el8_3.x86_64 NetworkManager-tui-1:1.26.0-12.el8_3.x86_64
cloud-init-19.4-11.el8_3.1.noarch curl-7.61.1-14.el8_3.1.x86_64 freetype-2.9.1-4.el8_3.1.x86_64 gnutls-3.6.14-7.el8_3.x86_64
insights-client-3.1.1-1.el8_3.noarch iptables-libs-1.8.4-15.el8_3.3.x86_64 kernel-tools-4.18.0-240.8.1.el8_3.x86_64 kernel-tools-libs-4.18.0-240.8.1.el8_3.x86_64
kexec-tools-2.0.20-34.el8_3.1.x86_64 libcurl-7.61.1-14.el8_3.1.x86_64 microcode_ctl-4:20200609-2.20201112.1.el8_3.x86_64 openssl-1:1.1.1g-12.el8_3.x86_64
openssl-libs-1:1.1.1g-12.el8_3.x86_64 python3-perf-4.18.0-240.8.1.el8_3.x86_64 qemu-guest-agent-15:4.2.0-34.module+el8.3.0+8829+e7a0a3ea.1.x86_64 systemd-239-41.el8_3.1.x86_64
systemd-libs-239-41.el8_3.1.x86_64 systemd-pam-239-41.el8_3.1.x86_64 systemd-udev-239-41.el8_3.1.x86_64 tuned-2.14.0-3.el8_3.1.noarch

Installed:
kernel-4.18.0-240.8.1.el8_3.x86_64 kernel-core-4.18.0-240.8.1.el8_3.x86_64 kernel-modules-4.18.0-240.8.1.el8_3.x86_64 linux-firmware-20200619-101.git3890db36.el8_3.noarch

Complete!

4. Install wget package 

[root@ip-10-0-1-138 ec2-user]# yum install wget -y

Last metadata expiration check: 0:04:39 ago on Mon 28 Dec 2020 08:06:57 AM UTC.

Dependencies resolved.

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

Package                                  Architecture                               Version                                             Repository                                                      Size

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

Installing:

wget                                     x86_64                                     1.19.5-10.el8                                       rhel-8-appstream-rhui-rpms                                     734 k

Transaction Summary

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

Install  1 Package

Total download size: 734 k

Installed size: 2.8 M

Downloading Packages:

wget-1.19.5-10.el8.x86_64.rpm                                                                                                                                                 5.0 MB/s | 734 kB     00:00

————————————————————————————————————————————————————————————————————–

Total                                                                                                                                                                         3.9 MB/s | 734 kB     00:00

Running transaction check

Transaction check succeeded.

Running transaction test

Transaction test succeeded.

Running transaction

  Preparing        :                                                                                                                                                                                      1/1

  Installing       : wget-1.19.5-10.el8.x86_64                                                                                                                                                            1/1

  Running scriptlet: wget-1.19.5-10.el8.x86_64                                                                                                                                                            1/1

  Verifying        : wget-1.19.5-10.el8.x86_64                                                                                                                                                            1/1

Installed:

  wget-1.19.5-10.el8.x86_64

Complete!

5. Install wget package 

[root@ip-10-0-1-138 ec2-user]# yum install wget -y

Last metadata expiration check: 0:04:39 ago on Mon 28 Dec 2020 08:06:57 AM UTC.

Dependencies resolved.

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

Package                                  Architecture                               Version                                             Repository                                                      Size

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

Installing:

wget                                     x86_64                                     1.19.5-10.el8                                       rhel-8-appstream-rhui-rpms                                     734 k

Transaction Summary

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

Install  1 Package

Total download size: 734 k

Installed size: 2.8 M

Downloading Packages:

wget-1.19.5-10.el8.x86_64.rpm                                                                                                                                                 5.0 MB/s | 734 kB     00:00

————————————————————————————————————————————————————————————————————–

Total                                                                                                                                                                         3.9 MB/s | 734 kB     00:00

Running transaction check

Transaction check succeeded.

Running transaction test

Transaction test succeeded.

Running transaction

  Preparing        :                                                                                                                                                                                      1/1

  Installing       : wget-1.19.5-10.el8.x86_64                                                                                                                                                            1/1

  Running scriptlet: wget-1.19.5-10.el8.x86_64                                                                                                                                                            1/1

  Verifying        : wget-1.19.5-10.el8.x86_64                                                                                                                                                            1/1

Installed:

  wget-1.19.5-10.el8.x86_64

Complete!

5. Install the Repository (RPM)

[root@ip-10-0-1-138 ec2-user]# dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm

Last metadata expiration check: 2:55:26 ago on Thu 31 Dec 2020 08:17:06 AM UTC.

pgdg-redhat-repo-latest.noarch.rpm                                                                                                                                             16 kB/s |  11 kB     00:00

Dependencies resolved.

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

Package                                                Architecture                                 Version                                         Repository                                          Size

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

Installing:

pgdg-redhat-repo                                       noarch                                       42.0-14                                         @commandline                                        11 k

Transaction Summary

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

Install  1 Package

Total size: 11 k

Installed size: 11 k

Downloading Packages:

Running transaction check

Transaction check succeeded.

Running transaction test

Transaction test succeeded.

Running transaction

  Preparing        :                                                                                                                                                                                      1/1

  Installing       : pgdg-redhat-repo-42.0-14.noarch                                                                                                                                                      1/1

  Verifying        : pgdg-redhat-repo-42.0-14.noarch                                                                                                                                                      1/1

Installed:

  pgdg-redhat-repo-42.0-14.noarch

Complete!

6. Install the Repository (RPM)

[root@ip-10-0-1-138 ec2-user]# dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
Last metadata expiration check: 2:55:26 ago on Thu 31 Dec 2020 08:17:06 AM UTC.
pgdg-redhat-repo-latest.noarch.rpm 16 kB/s | 11 kB 00:00

Dependencies resolved.

Package Architecture Version Repository Size

Installing:
pgdg-redhat-repo noarch 42.0-14 @commandline 11 k

Transaction Summary

Install 1 Package

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

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

Complete!

7. Disable the built-in PostgreSQL module

[root@ip-10-0-1-138 ec2-user]# dnf -qy module disable postgresql-15

8. Install PostgreSQL 15

[root@ip-10-0-1-138 ec2-user]# dnf install -y postgresql15-server

9. Initialize the Database

[root@ip-10-0-1-138 ec2-user]# /usr/pgsql-12/bin/postgresql-15-setup initdb

Initializing database … OK

10. Enable PostgreSQL 

[root@ip-10-0-1-138 ec2-user]# systemctl enable postgresql-15

11.  Start PostgreSQL 

[root@ip-10-0-1-138 ec2-user]# systemctl start postgresql-15

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s