PostgreSQL編譯安裝

PostgreSQL編譯安裝

  • 安裝語言包
### PostgreSQL 初始化過程當中,會讀取操做系統字符編碼,
### 若程序須要使用zh_CN.utf-8字符編碼,須要在PostgreSQL 初始化以前安裝中文包,再初始化PostgreSQL,
### 不然未安裝中文包初始化數據庫,會致使數據庫字符編碼格式沒有h_CN.utf-8字符編碼格式,影響程序後期使用

# sudo apt-get install language-pack-zh*
# sudo apt-get install language-pack-en*
  • 安裝編譯所需依賴包:
# sudo apt-get install -y libtool libapr1 make gcc libexpat1-dev
# sudo apt install libreadline5-dev 
# sudo apt install libreadline-gplv2-dev
# sudo apt install zlib1g-dev
# sudo apt install uuid-dev libossp-uuid-dev
  • 編譯PostgreSQL:
# cd /Sioeye/SioApps/Environment/
# wget https://ftp.postgresql.org/pub/source/v10.6/postgresql-10.6.tar.gz

# tar -zxvf postgresql-10.6.tar.gz
# cd postgresql-10.6/

# ./configure --prefix=/Sioeye/SioApps/Environment/postgresql --with-ossp-uuid
# make
# make install

# cd contrib/
# make
# make install
  • 建立postgres用戶
### 建立postgres用戶
# groupadd postgres
# useradd -g postgres -m postgres

### 設置用戶密碼
# passwd postgres

### 建立數據存儲目錄,並受權postgres用戶所屬權限
# mkdir -pv /Sioeye/Data/postgresql/data
# chown postgres:postgres /Sioeye/SioApps/Environment/postgresql -R
# chown postgres:postgres /Sioeye/Data/postgresql/data -R
  • 初始化PostgreSQL
### 切換用戶,並設置基礎環境變量。
# su - postgres
# vim ~/.bash_profile

### 在其文件最底下追加如下配置
export PGHOME=/Sioeye/SioApps/Environment/postgresql
export PGDATA=/Sioeye/Data/postgresql/data/
export PATH=$PGHOME/bin:$PATH
export MANPATH=$PGHOME/share/man:$MANPATH
export LANG=en_US.utf8
export LD_LIBRARY_PATH=$PGHOME/lib:$LD_LIBRARY_PATH

# source ~/.bash_profile

### 初始化數據庫
# initdb -D /Sioeye/Data/postgresql/data

### 建立日誌存儲目錄,啓動數據庫
# mkdir /Sioeye/Data/logs/postgresql
# pg_ctl -D /Sioeye/Data/postgresql/data -l /Sioeye/Data/logs/postgresql/start_logs.log start
  • 設置postgres用戶密碼
### 此處設置數據庫用戶密碼,而非操做系統用戶密碼
# psql
postgres=# alter user postgres with password '123456';
  • 設置開機啓動
### 從源碼中拷貝啓動腳本到/etc/init.d/目錄
# cd /Sioeye/SioApps/Environment/postgresql-10.6/start-scripts/
# cp linux /etc/init.d/postgresql

### 修改默認配置
# vim /etc/init.d/postgresql

##############################################
# Installation prefix
prefix=/Sioeye/SioApps/Environment/postgresql

# Data directory
PGDATA="/Sioeye/Data/postgresql/data/"

# Who to run the postmaster as, usually "postgres".  (NOT "root")
PGUSER=postgres

PGLOG="/Sioeye/Data/logs/postgresql/"

# Where to keep a log file
PGLOG="$PGLOG/serverlog"
##############################################

# chmod a+x /etc/init.d/postgresql
# chkconfig  --add postgresql
# update-rc.d postgresql defaults 98
  • 按需修改pg_hba.conf,postgresql.conf文件
### /Sioeye/Data/postgresql/data/pg_hba.conf 文件最後追加
host all all 0.0.0.0 0.0.0.0 md5
### /Sioeye/Data/postgresql/data/postgresql.conf 文件修改
listen_addresses = '0.0.0.0'
port = 5432
相關文章
相關標籤/搜索