【轉】postgresql 9.4 在linux環境的安裝步驟詳解


本文章來為各位介紹一篇關於postgresql 9.4 在linux環境的安裝步驟詳解,希望文章能夠對各位新手朋友帶來幫助的哦。

環境說明
系統:centos 6.4 64位
軟件:postgresql 9.4.1
 
 
軟件下載
cd /usr/local/src/
wget https://ftp.postgresql.org/pub/source/v9.4.1/postgresql-9.4.1.tar.gz
 
安裝依賴包
yum install -y perl-ExtUtils-Embed readline-devel zlib-devel pam-devel libxml2-devel libxslt-devel openldap-devel python-devel gcc-c++   openssl-devel cmake
 
 
安裝postgresql
tar xf postgresql-9.4.1.tar.gz
cd postgresql-9.4.1
./configure --prefix=/usr/local/pgsql --with-perl --with-python --with-libxml --with-libxslt
gamke
gamke install
 
 
安裝PG插件
cd /usr/local/src/postgresql-9.4.1/contrib
gmake
gmake install
加載動態庫
echo "/usr/local/pgsql/lib" >> /etc/ld.so.conf.d/pgsql.conf
ldconfig
初始化數據庫
創建用戶postgres
useradd postgres
echo "postgres"|passwd --stdin postgres
 
創建PG數據目錄
mkdir -p /data/pg/data
chown -R postgres:postgres /data/pg
/usr/local/pgsql/bin/initdb --no-locale -U postgres -E utf8 -D /data/pg/data -W
(在初始化的時候,看提示添加超級用戶的密碼)
 
備注
  initdb [選項]... [DATADIR]
  -A, --auth=METHOD         本地連接的默認認證方法
  -D, --pgdata=DATADIR       當前數據庫簇的位置
  -E, --encoding=ENCODING   為新數據庫設置默認編碼
      --locale=LOCALE      為新數據庫設置默認語言環境
  --lc-collate, --lc-ctype, --lc-messages=LOCALE
  --lc-monetary, --lc-numeric, --lc-time=LOCALE
                            為新的數據庫簇在各自的目錄中分別
                   設定缺省語言環境(默認使用環境變
                   量)
  --no-locale               等同於 --locale=C
  --pwfile=文件名           對於新的超級用戶從文件讀取口令
  -T, --text-search-config=CFG
                   缺省的文本搜索配置
  -U, --username=NAME       數據庫超級用戶名
  -W, --pwprompt              對於新的超級用戶提示輸入口令
  -X, --xlogdir=XLOGDIR        當前事務日志目錄的位置
 
非普通使用選項:
  -d, --debug               產生大量的除錯信息
  -L DIRECTORY              輸入文件的位置
  -n, --noclean             出錯后不清理
  -s, --show                顯示內部設置
 
其它選項:
  -?, --help                顯示此幫助, 然后退出
  -V, --version             輸出版本信息, 然后退出
 
如果沒有指定數據目錄, 將使用環境變量 PGDATA
 
 
 
配置運行環境變量(方便管理)
切換到root
vim /etc/profile
 
添加以下代碼:
PGDATA=/data/pg/data
PGHOST=127.0.0.1
PGDATABASE=postgres
PGUSER=postgres
PGPORT=5432
PATH=/usr/local/pgsql/bin:$PATH
export PATH
export PGDATA PGHOST PGDATABASE PGUSER PGPORT
 
執行生效
source /etc/profile
 
postgresql服務管理
啟動:
pg_ctl start -D /data/pg/data
 
重啟:
pg_ctl restart -D /data/pg/data
 
停止:
pg_ctl stop -D /data/pg/data
 
強制重啟:
pg_ctl restart -D /data/pg/data -m f
 
強制停止:
pg_ctl stop -D /data/pg/data -m f
-m f 指定快速關閉
 
加載配置:
pg_ctl reload -D  /data/pg/data
 
顯示服務狀態:
pg_ctl status -D  /data/pg/data
 
 
連接數據庫
psql -h 127.0.0.1 -U postgres -p 5432 -d postgres -W
-d 指定數據庫 ,-W 輸入密碼 , -U 指定用戶,-p 指定端口,-h 指定IP
 
復制PostgreSQL執行腳本
cp /usr/local/src/postgresql-9.4.1/contrib/start-scripts/linux /etc/init.d/postgresql
chmod +x /etc/init.d/postgresql
 
修改/etc/init.d/postgresql  
把PGDATA改成PGDATA=/data/pg/data
 
加入開機啟動
chkconfig postgresql on
 
 
管理PG服務時也可以直接用上面啟動腳本
啟動:service postgresql start
停止:service postgresql stop
重啟:service postgresql restart
加載:service postgresql reload
狀態:serivce postgresql status


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM