14.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这个参数。

14.1.1. 在Windows服务器安装PostgreSQL

PostgreSQL的正式网站下载最新版的Windows版的PostgreSQL。例如:postgresql-11-windows.exe。然后按指示安装PostgreSQL

Tip

如果PostgreSQL一直无法启动,可以参考Chapter 21,找寻合适的帮助管道。

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.
				

14.1.2. 在DebianUbuntu上面安装PostgreSQL

root帐号下这个指令来安装PostgreSQL

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

14.1.3. 调整PostgreSQL

  1. psql下这道指令以确认使用UNICODE做为database cluster的预设Encoding

    \l
    					

    检查数据库空间Database Cluster Space)是否为UTF8

    Figure 14-1. 确定Database Cluster使用UTF8

    一些较旧版的PostgreSQL for WindowsDebianPostgreSQL安装包可能以预设的SQL_ASCII安装,而非UTF8

    如果Database Cluster不是使用UTF8,那么,在您回存Section 14.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 21

  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 18.2postgresql.conf的预设值20应该足够:

    max_connections = 20			# (change requires restart)
    					

    重新启动PostgreSQL

    • Windows的用户:

      停止postgres服务,再启动它。

    • Debian的用户:

      /etc/init.d/postgresql reload
      							

14.1.4. 确定PostgreSQL接受连接请求

输入postgres的密码之后,如果没有错误信息,则代表:您可以用postgres这个帐号登录PostgreSQL