Centos7安裝EDB/PPAS/EPAS

Centos7安裝EDB/PPAS/EPAS

企業級PG:EnterpriseDB/EDB/PPAS/EPAS

企業級PG(EnterpriseDB)
EDB官網:www.enterprisedb.com
數據庫官網下載鏈接:www.enterprisedb.com/software-downloads-postgres
官網下載有兩個版本:EDB Postgres Advanced Server 和 PostgreSQL。
阿里的雲數據庫PPAS版:基於PostgreSQL,高度兼容Oracle語法,由阿里雲與EnterpriseDB公司合作提供。

EnterpriseDB是全球唯一一家提供基於PostgreSQL企業級產品與服務的廠商。
EnterpriseDB是PostgreSQL的一個分支,在PostgreSQL基礎上,針對企業級應用進行了專門的優化,同時,增加了一系列如動態 性能調優(DynaTune)、EDB Loader、高效批量SQL處理等高級特性
EnterpriseDB的兼容性尤爲突出,能兼容Oracle的數據庫。

安裝

安裝前的準備
1.關閉firewalld防火牆和Selinux

#查看firwalld的狀態
systemctl status firewalld   #也可以執行 firewall-cmd --state

#停止firewalld
systemctl stop firewalld 

#禁用firewalld
systemctl disable firewalld 

#查看Selinux狀態
getenforce

#關閉Selinux
vim /etc/selinux/config
SELINUX=disabled

#重啓服務器、立即生效配置
reboot

2.系統參數調整優化

#系統級別的最大文件句柄數量調整
cat /proc/sys/fs/file-max
383676
一般不同的系統版本,默認值會有差別,有的是383676,有的是592409,一般系統的默認值夠用,不用修改,我這裏永久性的調整爲100萬:
vim /etc/sysctl.conf
fs.file-max = 1000000

#立即生效
sysctl -p

#查看用戶的所有進程級別的限制
ulimit  -a
core file size  (blocks, -c) 0  //內核文件的大小限制
data seg size   (kbytes, -d) unlimited  //最大數據大小限制,建議用戶設置爲unlimited
scheduling priority     (-e) 0  //調度優先級,一般根據nice設置
file size   (blocks, -f) unlimited  //最大文件大小限制,建議用戶設置爲unlimited
pending signals     (-i) 15086  //信號可以被掛起的最大數,這個值針對所有用戶,表示可以被掛起/阻塞的最大信號數量
max locked memory   (kbytes, -l) 64  //內存鎖定值的限制
max memory size     (kbytes, -m) unlimited  //最大可以使用內存限制
open files      (-n) 65535  //進程打開文件數的限制。默認值是1024,默認值太小、通常需要調整該值爲65535或unlimited
pipe size    (512 bytes, -p) 8  //管道文件大小限制
POSIX message queues (bytes, -q) 819200  //可以創建使用POSIX消息隊列的最大值,單位爲bytes
real-time priority      (-r) 0  //限制程序實時優先級的範圍,只針對普通用戶
stack size      (kbytes, -s) 8192  //限制進程使用堆棧段的大小
cpu time   (seconds, -t) unlimited  //程序佔用CPU的時間,單位是秒
max user processes      (-u) 15086  //限制程序可以fork的進程數,只對普通用戶有效
virtual memory  (kbytes, -v) unlimited  //限制進程使用虛擬內存的大小,建議用戶設置爲unlimited
file locks      (-x) unlimited  //鎖定文件大小限制

#用戶進程級別的限制修改:可以通過修改/etc/security/limits.conf文件實現永久生效的修改
#修改表達式解釋:
<domain>    <type>  <item>  <value>

<domain>:
   ftpuser //用戶
   @student //組
   * //通配符,所有用戶
   % //通配符,用在組的語法
   
<type>:
  soft //軟限制。警告的設定,可以超過這個設定值,但是若超過則有警告信息
  hard //硬限制。嚴格的設定,必定不能超過這個設定的數值
   
<item>:
  core //限制內核文件的大小
  data //最大數據大小限制
  fsize //最大文件大小限制
  memlock //最大鎖內存地址空間
  nofile //進程打開文件數的限制
  rss //最大持久駐留內存
  stack //最大堆棧大小
  cpu //最大CPU運行時間
  nproc //最大進程數
  as //地址空間限制
  maxlogins //最大登錄次數,用戶
  maxsyslogins //最大登錄次數,登錄此係統的最大次數
  priority //用戶運行的優先級
  locks //用戶鎖定文件數限制
  sigpending //信號可以被掛起的最大數
  msgqueue //可以創建使用POSIX消息隊列的最大值
  nice //可以設置的優先級,nice [-20, 19]
  rtprio //實時優先級,數字大的優先級高

#進程級打開文件句柄數量
#在文件末尾添加配置內容:

echo "
* soft nofile 65535
* hard nofile 70000
" >> /etc/security/limits.conf

注意:
1)修改後用戶需要重新登錄才能生效
2)如果調整用戶進程級限制達到系統級的最大數時,還需要調整系統級的最大值


拷貝安裝包解壓
mkdir -p /opt/edb
cp edb-as10-server-10.12.20-1-linux-x64.run /opt/edb
cd /opt/edb

安裝時,可以選擇先編輯好配置文件後進行無人值守安裝,也可以step by step命令行交互式安裝。我採用命令行交互式安裝。

創建安裝目錄:
mkdir -p /opt/edb/as10
注意:這裏只需要創建安裝目錄就行了。
剛開始我以root身份還創建了2個子目錄 /opt/edb/as10/data 和 /opt/edb/as10/data/pg_wal 用於後面的指定的數據目錄和REDO(WAL)目錄。結果導致安裝失敗。

初步分析了一下,懷疑可能是root創建的這兩個目錄後續安裝是自動創建的postgres無法寫這兩個目錄導致問題。
所以提前不要創建目錄,安裝的時候自動創建postgres用戶後,會以該用戶來創建對應的目錄和文件。否則/opt/edb/as10/data/下面的目錄和文件的用戶和組有問題。
[root@localhost edb]# ls -l /opt/edb/as10/data/
total 64
drwx------ 5 postgres postgres    38 Apr 18 20:17 base
-rw------- 1 postgres postgres    46 Apr 18 20:17 current_logfiles
drwx------ 2 postgres postgres     6 Apr 18 20:17 dbms_pipe
drwx------ 2 postgres postgres  4096 Apr 18 20:17 global
drwxr-xr-x 2 postgres postgres    67 Apr 18 20:17 log
drwx------ 2 postgres postgres     6 Apr 18 20:17 pg_commit_ts
................

數據目錄(Data Directory)、REDO(WAL)目錄(Write-Ahead Log (WAL) Directory)

 

執行安裝腳本
cd /opt/edb
chmod u+x edb-as10-server-10.12.20-1-linux-x64.run
./edb-as10-server-10.12.20-1-linux-x64.run


Press [Enter] to continue:    #前面License閱讀,直接回車繼續

Do you accept this license? [y/n]: y   #同意它的License

Installation Directory [/opt/edb/as10]:   #我這裏不指定,直接回車使用默認的安裝路徑/opt/edb/as10

安裝組件的選擇配置
EDB Postgres Advanced Server [Y/n] :Y
pgAdmin 4 [Y/n] :n    #是否安裝客戶端連接工具。pgAdmin是一個很好的PG圖形化管理工具
StackBuilder Plus [Y/n] :n     
Command Line Tools [Y/n] :Y     
Is the selection above correct? [Y/n]: Y  

數據目錄和REDO(WAL)目錄,建議兩者使用不同的塊設備分區,並確保使用足夠大的空間。WAL的目錄建議IOPS極好。我只是測試環境,無特殊要求,不獨立塊設備。
Additional Directories     
Please select a directory under which to store your data.     
Data Directory [/opt/edb/as10/data]:     #一般不建議使用默認配置,我只是測試環境,直接使用默認值
Please select a directory under which to store your Write-Ahead Logs.     
Write-Ahead Log (WAL) Directory [/opt/edb/as10/data/pg_wal]:   #一般不建議使用默認配置,我只是測試環境,直接使用默認值


選擇你需要兼容Oracle還是PostgreSQL,選擇Oracle的話,會安裝Oracle的一些兼容類型、包、視圖、函數等,同時數據類型的顯示會兼容Oracle的風格。
如果不需要Oracle的兼容性,建議選擇兼容PostgreSQL。更方便的逃離Oracle。

Advanced Server Dialect     
[1] Compatible with Oracle     
[2] Compatible with Postgres     
Please choose an option [1] : 2     # 根據實際需要選擇,選擇你需要兼容Oracle還是PostgreSQL。
                                    # 選擇Oracle的話,會安裝Oracle的一些兼容類型、包、視圖、函數等,同時數據類型的顯示會兼容Oracle的風格。
                                    # 如果不需要Oracle的兼容性,建議選擇兼容PostgreSQL。

Please provide a password for the database superuser (postgres). A locked Unix user account (postgres) will be created if not present.
Password : 1q2w3e        # 數據庫初始超級用戶postgres的密碼、不同的edb版本提供的默認超級用戶不同,有些版本默認初始化的超級用戶是enterprisedb
Retype Password : 1q2w3e 

Please select the port number the server should listen on.     
Port [5432]:  # 使用默認的監聽端口、不同的edb版本的默認端口也不同、有的版本可能是5444,不修改,使用默認端口

...     
[763] zh_CN.utf8     
...          
Please choose an option [1] : 763  # 指定數據庫的字符集編碼zh_CN.utf8。注意不同的edb版本字符集對應的編號不同,選擇zh_CN.utf8對應的編號。

Install sample tables and procedures. [Y/n]: Y  # 是否安裝示範表和存儲過程,一般可以不安裝,我這裏選擇安裝

Please select the type of server to determine the amount of system resources      
that may be utilized:   
[1] Development (e.g. a developer's laptop)     
[2] General Purpose (e.g. a web or application server)     
[3] Dedicated (a server running only Advanced Server)     
Please choose an option [2] : 2    # EDB動態優化,我測試使用,選General

Please select the type of workload this server will be used for:     
[1] Transaction Processing (OLTP systems)     
[2] General Purpose (OLTP and reporting workloads)     
[3] Reporting (Complex queries or OLAP workloads)     
Please choose an option [1] :   # 數據庫用於什麼業務場景(oltp事務型/htap混合型/olap分析型)。我默認OLTP事務型。


配置好後會顯示確認配置信息是否正確:
Pre Installation Summary
The following settings will be used for the installation::
Installation Directory: /opt/edb/as10
Server Installation Directory: /opt/edb/as10
Data Directory: /opt/edb/as10/data
WAL Directory: /opt/edb/as10/data/pg_wal
Database Port: 5432
Database Superuser: postgres
Operating System Account: postgres
Database Service: edb-as-10
Command Line Tools Installation Directory: /opt/edb/as10

確認配置後OK後回車,然後Y繼續安裝。安裝結束後,會自動創建一個系統用戶postgres和數據庫超級用戶postgres,同時新增一個隨操作系統自動啓動數據庫的服務。


如果安裝後報下面錯誤,請檢查是否是數據目錄、WAL目錄權限的問題,可能是提前用root身份創建的、導致postgres無法寫。請不要創建,系統會自動創建。
Please wait while Setup installs EDB Postgres Advanced Server on your computer.

 Installing EDB Postgres Advanced Server 
 0% ______________ 50% ______________ 100%
 ########################################Warning: Problem running post-install step. Installation may not complete 
correctly
 The database cluster initialisation failed.
Press [Enter] to continue:
#

----------------------------------------------------------------------------
Setup has finished installing EDB Postgres Advanced Server on your computer.

如果安裝失敗,就嘗試卸載重裝。
cd /opt/edb/ens10/
./uninstall-edb-as10-server

Please choose an option [1] : 1  #整體卸載
Info: The data directory (/opt/edb/as10/data) and service user account (postgres) have not been removed.
#
Info: Uninstallation completed

刪除用戶和目錄data:
userdel  postgres
rm /opt/edb/ens10/data
然後重新安裝。

安裝後進行配置

如果是選擇的兼容Oracle,則安裝完成以後,需要安裝Oracle OCI。我選擇的兼容PostgreSQL,所以這裏不介紹Oracle OCI的安裝。

安裝後切換到數據庫用戶,進行安裝後的環境配置。用戶root身份來配置postgres用戶的環境變量。

數據庫安裝完成後會自動生成環境變量文件:/opt/edb/pgplus_env.sh。可以直接拷貝內容,寫到數據庫用戶的環境變量文件中/opt/edb/as10/.bash_profile。

cat /opt/edb/pgplus_env.sh

export PATH=/opt/edb/as10/bin:$PATH
export PGHOME=/opt/edb/as10
export PGDATA=/opt/edb/as10/data
export PGDATABASE=postgres
# export PGUSER=postgres
export PGPORT=5432
export PGLOCALEDIR=/opt/edb/as10/share/locale

也可以手動編輯用下面的內容創建環境變量文件(下面變量更全)

vi /opt/edb/as10/.bash_profile

export LANG=zh_CN.utf8
export PGDATA=/opt/edb/as10/data
export PGHOME=/opt/edb/as10 
export PATH=$PGHOME/bin:$PATH
export MANPATH=$PGHOME/share/man:$MANPATH 
export LD_LIBRARY_PATH=$PGHOME/lib:$LD_LIBRARY_PATH
export PGHOST=$PGDATA
export PGUSER=postgres
export PGDATABASE=postgres
alias rm='rm -i' 
alias ll='ls -lh' 
unalias vi

su - postgres
pwd
/opt/edb/as10 #發現用戶被鎖定再該目錄下

如果要調整優化數據庫的配置參數,則可以通過修改postgresql.conf配置文件
su - enterprisedb
cd $PGDATA
vi postgresql.conf
參數調優這裏不介紹了


修改數據庫防火牆(ACL),開放安全限制、允許外部連接
cd $PGDATA
vi pg_hba.conf
# TYPE  DATABASE        USER            ADDRESS                 METHOD     

# "local" is for Unix domain socket connections only     
local   all             all                                    trust     
# IPv4 local connections:     
host    all             all             127.0.0.1/32            md5     
# IPv6 local connections:     
host    all             all             ::1/128                 md5     
# Allow replication connections from localhost, by a user with the     
# replication privilege.     
local   replication     all                                     md5     
host    replication     all             127.0.0.1/32            md5     
host    replication     all             ::1/128                 md5     
host    all             all             0.0.0.0/0               md5 

主要:
local   all             all                                    trust 
host    all             all             0.0.0.0/0               md5 


重啓數據庫
pg_ctl restart -m fast 

常用命令
基本操作命令和postgresql相同

啓動數據庫: pg_ctl start
重啓數據庫: pg_ctl restart -m fast
停止數據庫: pg_ctl stop
查看服務狀態: pg_ctl  status  或者  ps aux |grep postgres


查看數據庫是否正常: psql -Upostgres
postgres=# 
postgres=# help //可查看幫助信息
postgres=# \d  //List of relations
postgres=# \l  //List of databases
postgres=# \q  //quit

遠程登錄、連接數據庫

psql -h host -p port PGDATABASE PGUSER
psql -h host -p port -U PGUSER PGDATABASE

psql -h 127.0.0.1 -p 5432 postgres postgres
psql -h 127.0.0.1 -p 5432 testdb ppas
psql -h 127.0.0.1 -p 5432 -U ppas testdb


創建用戶ppas
create role ppas login encrypted password '1q2w3e'; 

創建數據庫testdb
create database testdb with template template1;
#create database testdb02 with template template1 onwer ppas;
grant all on database testdb to ppas;
grant all on database testdb to postgres;

獲取當前db的所有表信息
select * from pg_tables;

查看用戶的所有表(用戶自定義的表,如果未經特殊處理,默認都是放在名爲public的schema下)
select tablename from pg_tables where schemaname='public';

創建表:
create table test01( 
id integer not null, 
name character(255),
price decimal(8,2),
primary key(id)
);

插入數據
insert into test01(id,name,price) values (1,'a',11.5),(2,'b',20.3);

查看錶結構
\d test01;

查看錶的數據
select * from test01;

刪除表
drop table test01;


查看Server版本信息:
psql --version;
SHOW server_version;
SELECT version();

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章