2. 安裝 PostgreSQL
所有 PostgreSQL 安裝步驟應在所有 PostgreSQL 節點上執行。
在 RHEL 上安裝 Postgres
步驟 1
請參閱 https://www.postgresql.org/download/linux/redhat/ 以找到並下載 PostgreSQL 10 的最新次版本。應相應修改在下列 yum 指令中參考的 rpm。
sudo yum install
https://download.postgresql.org/pub/repos/yum/10.x/redhat/rhel-7-
x86_64/pgdg-redhat94-9.4-3.noarch.rpm
sudo yum install postgresql10.x-server postgresql10.x-contrib
步驟 2
生產資料庫檔案通常儲存在非作業系統磁碟或共用檔案服務上。/db 資料夾將會是此範例中的儲存位置。
在每個 PostgreSQL 節點上建立下列資料夾位置。
* 
與此範例提供的指令集參照了 /db/postgres 位置。修改資料夾位置也需要更新指令集。
sudo mkdir /db
sudo mkdir /db/postgres
sudo mkdir /db/thingworx
sudo mkdir /db/install
sudo mkdir /db/bin
sudo chown -R postgres:postgres /db
建立此範例檔案共用部分所述三個封存資料夾,並確保所有 PostgreSQL 節點都可存取其中的內容。
/db/node0archive
/db/node1archive
/db/node2archive
步驟 3
如之前在資料庫資料夾設定中所述,PostgreSQL 資料庫將位於每個 PostgreSQL 節點上的 /db/postgres 底下。
在初始化資料庫之前,Postgres 使用者設定檔需要先調整到新位置。
sudo su postgres
vim ~/.bash_profile
~/.bash_profile
[ -f /etc/profile ] && source /etc/profile
PGDATA=/db/postgres
export PGDATA
PATH=$PATH:/usr/pgsql-10.x/bin
export PATH
# If you want to customize your settings,
# Use the file below. This is not overridden
# by the RPMS.
[ -f /var/lib/pgsql/.pgsql_profile ] && source
/var/lib/pgsql/.pgsql_profile
的範例
編輯之後,制訂變更:
source ~/.bash_profile
初始化資料庫:
/usr/pgsql-10.x/bin/initdb -D /db/postgres
步驟 4
返回擁有 sudo 權限的使用者並修改 PostgreSQL 服務中的 PGDATA 參數。
編輯 postgresql-10.x.service 檔案
sudo vi /usr/lib/systemd/system/postgresql-10.x.service
以包含新 PGDATA 參數值。
# Location of database directory
#Environment=PGDATA=/var/lib/pgsql/10.x/data/
Environment=PGDATA=/db/postgres
然後重新載入、啟用並啟動服務。
sudo systemctl reload
sudo systemctl enable postgresql-10.x.service
sudo systemctl start postgresql-10.x
步驟 5
驗證初始安裝:
sudo su postgres
psql
使用指令顯示 data_directory 來確保預設資料庫安裝正確。
postgres=# show data_directory;
data_directory
----------------
/db/postgres
(1 row)
這是否有幫助?