Deploy RDS@PostgreSQL-16 & Connect Via PSQL From Another Host
Deploy RDS@PostgreSQL-16 & Connect Via PSQL From Another Host
Validate the Security group has incoming port to Ec2 having psql
Set the password like this (YPdhPmKhfvXXeKx16gcM ) for simplicity else keep
autogenerated
sudo su -
vi /tmp/install_source_pg16.sh
#!/bin/sh
echo "Start of the script . It installs postgres 16 & adds postgres OS user to sudoers list
"
echo " updating hostname in /etc/hosts"
echo " replace below IP with Private IP of EC2 INSTANCE "
export source_IP="172.31.41.251"
#export target_IP="172.31.46.96"
echo "$source_IP source" >> /etc/hosts
echo "$target_IP target" >> /etc/hosts
echo " Setting hostname of source host"
sudo hostnamectl set-hostname source
echo " Installing postgres 16"
sudo sh -c 'echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg
main" > /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key
add -
sudo apt-get update
sudo apt-get -y install postgresql-16
echo " Add postgres OS user to sudoers file "
echo "postgres ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
echo " end of the installation script"
echo " execute the script to install binaries "
sh -x /tmp/install_source_pg16.sh
sudo su - postgres
vi /tmp/postgres_setting_pg_source.sh
sudo su - postgres
sh -x /tmp/postgres_setting_pg_source.sh
Note : Ensure RDS must have SG with inbound rules allow for port 5432 to SG of
Ec2
shell
export PGPASSWORD=YPdhPmKhfvXXeKx16gcM