Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kenshin17/61798a0997b90f1b362bb5ca40e43465 to your computer and use it in GitHub Desktop.
Save kenshin17/61798a0997b90f1b362bb5ca40e43465 to your computer and use it in GitHub Desktop.
Compile PostgreSQL 11.5 on Ubuntu
#!/bin/bash
# File : compile-postgreSQL-11.5-Ubuntu-16.04.LTS.sh
# OS : Ubuntu 16.04.6 LTS
# LastUpdate : 10:06 2019.10.07
# Description : Compile PostgreSQL 11.5 on Ubuntu
###########################################
##POSTGRESQL : /postgres/pgscript/postgres-stop.sh | /postgres/pgscript/postgres-restart.sh <<<<<RESTART>>>>>
# | CONFIG FILE : /postgres/pgdata/{postgresql.conf,pg_hba.conf}
# | CONNECT DBA : /postgres/pgscript/postgres-connect-dba.sh
# | BIN LOCATION : /postgres/bin
# | PGARCHIVED : /postgres/pgarchived/
# | PGDATA : /postgres/pgdata/
# | PGLOG : /postgres/pglog/
# | PGSCRIPT : /postgres/pgscript/
# | PGSQL : /postgres/pgsql/
# | LOG : postgres-log-realtime.sh
mkdir -p /postgres/{pgdata,pgscript,bin,pgarchived,pglog,pgsql,pgsource}
export LC_CTYPE=en_US.UTF-8
export LC_ALL=en_US.UTF-8
SETUP_DIR_WORKSPACE="/postgres/pgsource/"
COMPILE_DIR_WORKSPACE="/postgres/"
mkdir -p $SETUP_DIR_WORKSPACE
## Install dependencies package
echo "####################################################################"
echo "# Install dependencies package #"
echo "####################################################################"
export DEBIAN_FRONTEND=noninteractive
apt-get -y install build-essential --fix-missing
apt-get -y install libreadline-dev --fix-missing
apt-get -y install zlib1g-dev --fix-missing
apt-get -y install flex
apt-get -y install bison
apt-get -y install libxml2-dev
apt-get -y install libxslt-dev
apt-get -y install libssl-dev
apt-get -y install libxslt-dev
userdel -r postgres
groupadd -g 5000 postgres
useradd -u 5000 -s /bin/bash -d /home/postgres -c "POSTGRES.SUPER.ADMIN" -g postgres postgres
mkdir -p /home/postgres/
chown -R postgres.postgres /home/postgres/
#check group, user xem da tao duoc chua:
cat /etc/group | grep postgres;cat /etc/passwd | grep postgres
#
#Dat mat khau cho user "postgres":
#echo "#Dat mat khau cho user \"postgres\":"
user_name="postgres"
pass_word="310212QwwQ"
passwd "$user_name" <<<"$pass_word"$'\n'"$pass_word"
## Complie PostgreSQL
echo "####################################################################"
echo "# Complie PostgreSQL #"
echo "####################################################################"
cd $SETUP_DIR_WORKSPACE
rm -rf postgresql-10.5.tar.gz
wget https://ftp.postgresql.org/pub/source/v11.5/postgresql-11.5.tar.gz
tar -xvf postgresql-11.5.tar.gz
cd postgresql-11.5
chmod +x configure
./configure --prefix=$COMPILE_DIR_WORKSPACE \
--with-libxml \
--with-libxslt \
--with-openssl > log-config.txt
#make:
make > log-make.txt
#make install:
make install > log-makeinstall.txt
## Clear Old Data PostgreSQL
rm -rf /usr/sbin/pg_*
/bin/rm -rf /usr/sbin/clusterdb
/bin/rm -rf /usr/sbin/createdb
/bin/rm -rf /usr/sbin/createlang
/bin/rm -rf /usr/sbin/createuser
/bin/rm -rf /usr/sbin/dropdb
/bin/rm -rf /usr/sbin/droplang
/bin/rm -rf /usr/sbin/dropuser
/bin/rm -rf /usr/sbin/initdb
/bin/rm -rf /usr/sbin/oid2name
/bin/rm -rf /usr/sbin/pgbench
/bin/rm -rf /usr/sbin/postgres
/bin/rm -rf /usr/sbin/postmaster
/bin/rm -rf /usr/sbin/psql
/bin/rm -rf /usr/sbin/reindexdb
/bin/rm -rf /usr/sbin/vacuumdb
/bin/rm -rf /usr/sbin/vacuumlo
/bin/rm -rf /usr/sbin/ecpg
## Symlink Binary PostgreSQL
ln -s $COMPILE_DIR_WORKSPACE/bin/* /usr/sbin/
## Create PostgreSQL Data Dir
# mkdir -p /postgres/pg_data
## Set default EDITOR
export EDITOR=$(which vim)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment