13.1. 安裝資料庫管理系統:PostgreSQL

這裏簡介PostgreSQL的安裝手續。詳細說明,請參考PostgreSQL的正式手冊。

Note

本節假設:

  • PostgreSQL的版本是11

  • 貴公司的內部網路區段是192.168.0.0/24。

  • 運行PostgreSQL的這部主機的網路卡的IP地址是192.168.0.1

  • 運行PostERP伺服器主機的這部主機的網路卡的IP地址是192.168.0.2

請根據實際情況替代上述IP地址與PostgreSQL的版本數字。(本機的IP地址通常是127.0.0.1

Important

注意事項:

  • 要把主機的BIOS的timer設為UTC,Coordinated Universal Time0」(近似舊稱的格林威治時間,GMT0)的時間,並且指定好作業系統的時區。

    以臺北和北京為例:假設現在的當地時間是14:00,那麼,我們就把BIOS的時間設定成06:00

    然後把Windows時區設定成臺北時區北京時區。如果是Unix,則設定localtimetimezone

  • PostgreSQL必須能處理UNICODE。如果您是自行make PostgreSQL的原始碼,則在configure時,一定要含--enable-multibyte=UNICODE這個參數。

13.1.1. 在Windows主機安裝PostgreSQL

PostgreSQL的正式網站下載最新版的Windows版的PostgreSQL。例如:postgresql-11-windows.exe。然後按指示安裝PostgreSQL

Tip

如果PostgreSQL一直無法啟動,可以參考Chapter 20,找尋合適的幫助管道。

Tip

我們的買斷版PostERP不一定要在Windows上面跑。使用Linux,並且在WINE version 2.0裡上面跑我們的應用俟服器,也運行得十分順暢。把server.exelibpq.dll放在一起,然後在X window的環境裡下wine server.exe &這道指令。

同理,如果要執行瘦客戶程式的話,改下wine tc.exe &這道指令。

Tip

如果您是在Windows上面安裝PostgreSQL而且刪除C:\Program Files\PostgreSQL\11\data目錄,然後用C:\Program Files\PostgreSQL\11\bin\initdb.exe指令重建C:\Program Files\PostgreSQL\11\data,但是再也無法啟動PostgreSQL的service,而且Windows的event log指出could not create lock file "postmaster.pid": Permission denied的話,那麼,也許摘自http://forumserver.twoplustwo.com/114/pokertracker/cant-connect-db-422617/的下面建議可能對您有幫助:

Click Start, and then click My Computer. On the Tools menu, click Folder Options and click the View tab. In the Advanced Settings section, click to clear the Use simple file sharing (Recommended) check box. Click OK.

Then click Start --> Run type C:\Program Files\ and hit enter. Right click on PostgreSQL, click Properties. Go to the Security tab, click Add up top, then click Advanced, and Find Now. Find the postgres user at the bottom and click 'ok' twice. Then with the postgres user highlighted up top, check the Full Access checkbox on the bottom and click OK.

Then you should be able to start the PostgreSQL service properly.
				

13.1.2. 在DebianUbuntu上面安裝PostgreSQL

root帳號下這個指令來安裝PostgreSQL

apt-get install postgresql-11
apt-get install postgresql-client-11
			

13.1.3. 調整PostgreSQL

  1. psql下這道指令以確認使用UNICODE做為database cluster的預設Encoding

    \l
    					

    檢查資料庫空間Database Cluster Space)是否為UTF8

    Figure 13-1. 確定Database Cluster使用UTF8

    一些較舊版的PostgreSQL for WindowsDebianPostgreSQL安裝套件可能以預設的SQL_ASCII安裝,而非UTF8

    如果Database Cluster不是使用UTF8,那麼,在您回存Section 13.2 PostERP資料庫的時候會出現大量錯誤訊息!Debian的用戶可以徹底刪除這個SQL_ASCII database cluster然後再重新開設UTF8 database cluster

    pg_dropcluster --stop 11 main
    pg_createcluster -u postgres -e UTF8 11 main
    					

    如果您是在Windows上面安裝PostgreSQL而且刪除C:\Program Files\PostgreSQL\11\data目錄,然後用C:\Program Files\PostgreSQL\11\bin\initdb.exe指令重建C:\Program Files\PostgreSQL\11\data,但是再也無法啟動PostgreSQL的service,而且Windows的event log指出could not create lock file "postmaster.pid": Permission denied的話,那麼,請參考Chapter 20

  2. 設置postgres這個role的連接權限

    你需要以postgres這個role連接PostgreSQL來做這些事:

    • 回存我們提供的資料庫。

    • 管理PostgreSQL。例如:備份您的資料庫。

    • PostERP透過TCP/IP連接PostgreSQL,並且用密碼登入PostgreSQL,無阻礙地操作PostgreSQL的資料。

  3. Important

    PostERP使用三層架構:PostERP透過TCP/IP與資料庫俟服器通訊。PostERP瘦客戶通訊。所以IT人員應僅開放pg_hba.conf必要的連接權限給PostERP不要允許其餘電腦直接連接到資料庫

    設定連接權限檔案。

    • Windows版的PostgreSQL連接權限檔案:"C:\Program Files\PostgreSQL\11\data\pg_hba.conf"

    • DebianUbuntu版的PostgreSQL連接權限檔案:/etc/postgresql/11/main/pg_hba.conf"

    務必提供TCP/IP供PostgreSQLpostgres這個role連接。例如下列三列之一:

    host	all		postgres	127.0.0.1/32	md5
    host	all		postgres	192.168.0.2/32	password
    host	all		postgres	192.168.0.2/32	trust
    					

    並且令PostgreSQL server全部介面都接受TCP/IP的連接請求。也就是在postgresql.conf設定:

    listen_addresses = "*"
    					

    PostERP應用俟服器為每一種語言開啟一定數目的資料庫連接。如果PostgreSQL的連接數設定太低,則PostERP應用俟服器可能無法啟動。關於精確連接數,詳見Section 17.2postgresql.conf的預設值20應該足夠:

    max_connections = 20			# (change requires restart)
    					

    重新啟動PostgreSQL

    • Windows的用戶:

      停止postgres服務,再啟動它。

    • Debian的用戶:

      /etc/init.d/postgresql reload
      							

13.1.4. 確定PostgreSQL接受連接請求

輸入postgres的密碼之後,如果沒有錯誤訊息,則代表:您可以用postgres這個帳號登入PostgreSQL