apt install -y gcc make zlib1g-dev libreadline-dev
mkdir -p /opt/package && cd /opt/package
wget https://ftp.postgresql.org/pub/source/v12.13/postgresql-12.13.tar.gz
tar xf postgresql-12.13.tar.gz
cd postgresql-12.13
mkdir build_dir && cd build_dir
../configure --prefix=/opt/software/postgresql/12.13
make && make install
adduser --disabled-password --gecos "" postgres
mkdir -p /opt/software/postgresql/12.13/data
chown postgres:postgres /opt/software/postgresql/12.13/data
cat >> /home/postgres/.bashrc << "EOF"
export PGHOME=/opt/software/postgresql/12.13
export PATH=$PGHOME/bin:$PATH
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PGHOME/lib
export PGDATA=$PGHOME/data
EOF