1. 程式人生 > >PgSQL基礎之 安裝postgresql資料系統

PgSQL基礎之 安裝postgresql資料系統

參考這位仁兄的文章,真的非常好:https://blog.csdn.net/jerry_sc/article/details/76408116#建立資料目錄

後來我又自己寫了一個shell指令碼,來自動化安裝pgsql10.5版本。

#!/bin/bash
#進入軟體的制定安裝目錄
echo "進入目錄/usr/local,下載pgsql檔案"
cd /usr/local
#判斷是否有postgre版本的安裝包
if [ -d post* ]
then
        rm -rf /usr/local/post*
        echo "安裝包刪除成功"
fi
#開始下載pgsql版本10.5並解壓
if [ ! -d /usr/local/src ]
then mkdir /usr/local/src fi cd /usr/local/src wget https://ftp.postgresql.org/pub/source/v10.5/postgresql-10.5.tar.gz if [ $? == 0 ] thentar -zxf postgresql-10.5.tar.gz -C /usr/local/ fi echo "pgsql檔案解壓成功" #判斷使用者是否存在 id $postgres >& /dev/null echo "使用者postgres已存在" if [ $? -ne 0 ] then echo "使用者不存在,開始建立postgres使用者
" groupadd postgres useradd -g postgres postgres fi echo "重新命名postgresql並且進入安裝目錄" mv /usr/local/post* /usr/local/pgsql cd /usr/local/pgsql #-------------------------------安裝pgsql------------------------------------ echo "安裝一些庫檔案" yum install -y zlib zlib-devel >& /del/null echo "開始執行configure步驟
" ./configure --prefix=/usr/local/pgsql --without-readline if [ $? == 0 ] then echo "configure配置通過,開始進行make編譯" make if [ $? == 0 ] then echo "make編譯通過,開始進行make install安裝步驟" make install if [ $? != 0 ];then echo "make install安裝失敗" fi echo "安裝成功" else echo "make編譯失敗,檢查錯誤。" fi else echo "configure檢查配置失敗,請檢視錯誤進行安裝庫檔案" fi echo "開始進行pgsql的配置" echo "給pgsql建立data目錄" mkdir -p /usr/local/pgsql/data echo "修改使用者組" chown -R postgres:postgres /usr/local/pgsql echo "新增環境變數,進入postgres使用者的家目錄" cd /home/postgres if [ -f .bash_profile ] ;then cp .bash_profile .bash_profile.bak echo "export PGHOME=/usr/local/pgsql" >> .bash_profile echo "export PGDATA=/usr/local/pgsql/data" >> .bash_profile echo "PATH=$PGHOME/bin:$PATH" >> .bash_profile echo "MANPATH=$PGHOME/share/man:$MANPATH" >> .bash_profile echo "LD_LIBRARY_PATH=$PGHOME/lib:$LD_LIBRARY_PATH" >> .bash_profile fi alias pg_start='pg_ctl -D $PGDATA -l /usr/local/pgsql/logfile start' alias ps_stop='pg_ctl -D $PGDATA -l /usr/local/pgsql/logfile stop' echo "切換至postgres使用者來初始化資料庫" su - postgres -c "/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data" echo "---------------------------------------------------------------------------------------" echo "---------------------------------------------------------------------------------------" echo "----------------------------SUCCESS INSTALLATION OF POSTGRESQL-------------------------"