Skip to content

Instantly share code, notes, and snippets.

@kenshin17
Created September 4, 2019 09:26
Show Gist options
  • Save kenshin17/b4d710d88cfdcbf3bea147e6b0c575a5 to your computer and use it in GitHub Desktop.
Save kenshin17/b4d710d88cfdcbf3bea147e6b0c575a5 to your computer and use it in GitHub Desktop.
Compile-postgreSQL-10.5-Ubuntu-16.04.LTS.sh
#!/bin/bash
# File : Compile-postgreSQL-10.5-Ubuntu-16.04.LTS.sh
# OS : Ubuntu 16.04.5 LTS
# LastUpdate : 11:55 2019.05.13
# Description : Compile PostgreSQL 10.5 on Ubuntu-16.04
###########################################
export LC_CTYPE=en_US.UTF-8
export LC_ALL=en_US.UTF-8
SETUP_DIR_WORKSPACE="/opt/setup"
COMPILE_DIR_WORKSPACE="/opt/build"
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
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="xxxxxx"
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 wget https://ftp.postgresql.org/pub/source/v10.5/postgresql-10.5.tar.gz
tar -xvf postgresql-10.5.tar.gz
cd postgresql-10.5
chmod +x configure
./configure --prefix=$COMPILE_DIR_WORKSPACE/postgresql-10.5 \
--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/postgresql-10.5/bin/* /usr/sbin/
## Create PostgreSQL Data Dir
# mkdir -p /opt/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