# Create the file repository configuration:
sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'

# Import the repository signing key:
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

# Update the package lists:
apt-get update

# Install PostgreSQL
apt-get install -y postgresql-16 postgresql-client-16 postgresql-contrib-16

# Allow trust connection from localhost
sed -i 's/scram-sha-256/trust/g' /etc/postgresql/16/main/pg_hba.conf
su - postgres -c "/usr/lib/postgresql/16/bin/pg_ctl reload -D /var/lib/postgresql/16/main"
