欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

linux postgresql 安装

程序员文章站 2022-05-27 16:18:41
...

对多个PG版本测试兼容性,匆忙写了脚本。 

在root用户下执行

./***.sh 用户 群组 安装包tar包名字 安装目录

例如在当前目录下有 postgresql-13.2.tar.gz 安装包 将安装在/opt/pg13目录 使用pg13用户

linux postgresql 安装

./install.sh pg13 pg13 postgresql-13.2.tar.gz /opt/pg13

本地测试通过,有问题请不吝赐教。

依赖包

yum install bison \
flex \
readline-devel \
zlib-devel \
openssl-devel \
libxml2-devel \
libxslt-devel \
uuid-devel \
openldap-devel \
python-devel \
krb5-devel \
tcl-devel \
pam-devel \
gettext-devel \
gcc \
gcc-c++ \
gtk2-devel \
automake \
gettext\
perl-ExtUtils-Embed \
readline-devel

shell

#!/bin/bash

user_name=$1
user_group=$2
install_file_name=$3
install_path=$4

temp_path=$install_file_name
dir=${temp_path%.*}
result=${dir%.*}

echo "begin"

#del 
userdel -r $user_name
groupdel $user_group
rm -rf $install_path
rm -rf /home/$user_name/$result

#create user
groupadd $user_group
useradd $user_name -g $user_group
echo "create "$user_name"done"

#create dir
mkdir $install_path
chown -R  $user_name:$user_group $install_path
echo "create dir done"

#copy file
cp ./$install_file_name /home/$user_name
sleep 1
chown -R  $user_name:$user_group /home/$user_name/$install_file_name
echo "copy file done"


temp_path=$install_file_name
dir=${temp_path%.*}
result=${dir%.*}
#gzip file
su - $user_name<<EOF
cd ~
tar -zxvf $install_file_name
echo "tar file done"

#config
cd $result
sed -i 's/\-O2//g' configure*
./configure --prefix=$install_path --enable-debug 
echo "config done"

#install
make
slepp 5
make install
echo "done"

#source bashrc
echo "export PGHOME=$install_path" >> ~/.bashrc
echo "export PGDATA=$install_path/data" >> ~/.bashrc
echo "export PGLIB=$install_path/lib" >> ~/.bashrc
echo "export PATH=$install_path/bin:$PATH" >> ~/.bashrc
source ~/.bashrc
echo "source done"

#initdb
initdb
echo "host    all    all    0.0.0.0/0    trust" >> $install_path/data/pg_hba.conf
echo "listen_addresses = '*' " >> $install_path/data/postgresql.conf
echo "port = 5432 " >> $install_path/data/postgresql.conf
echo "initdb done"

#test database
pg_ctl start -D $install_path/data -l logfile
createdb test_database
psql -dtest_database -h127.0.0.1 <<EXIT
\x
\d
\dx
select * from pg_class limit 5;
\q
EXIT
exit;
EOF

echo "done"

 

相关标签: XXXX