yum install -y yum-utils

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

# Install PostgreSQL
yum install -y postgresql14 postgresql14-server postgresql14-contrib

# Initialize PostgreSQL database
/usr/pgsql-14/bin/postgresql-14-setup initdb

# Allow trust connection from localhost
sed -i 's/scram-sha-256/trust/g' /var/lib/pgsql/14/data/pg_hba.conf

# Autostart PostgreSQL
systemctl enable postgresql-14

# Run PostgreSQL
systemctl start postgresql-14