Configure which Postgres version+cluster PHP should connect to (2 versions installed)

时间:2016-04-04 18:06:36

标签: php postgresql

I went through multiple posts here and elsewhere, couldn't find answer that applies to my situation.

I have one Ubuntu installation of Postgres 9.5 (not configured, dormant) and one of Postgres 9.1 (configured with users and databases). The 9.1 had to be manually re-installed after I upgraded to LTS 14.04 but my PHP applications lost their connection to the 9.1 clusters. 9.1 still runs on the default port (I manually stop the 9.5 instance on 5433):

9.1/main (port 5432): online

I can log in via psql and see all my databases in the 9.1 cluster, but I can't log in via phpPgAdmin (on port 5432), I see lots of pg_connect() warnings/errors, none of my PHP applications work (like ownCloud etc.) and they all stopped working after 9.1 was re-installed.

For various reasons, I'd like to keep working with 9.1 until I'm ready to upgrade to 9.5.

How can I get my connections back in my Apache/PHP? I know it's probably a simple thing, I just can't find which configuration option is responsible for that. Can you help?

[EDIT]: After further reading, my first guess is that it's pg_hba.conf related. I'll take a look what my values should be, I suspect it was reset to default on re-install, and now local TCP clients can't connect, only SSH seems to work.

1 个答案:

答案 0 :(得分:0)

在Ubuntu升级和Postgres 9.1重新安装之后,9.1/main/pg_hba.conf仅包含此行,缩小了通过SSH访问postgres用户的权限:

local all postgres ident

而我的9.5集群上的默认配置是这样的:

local   all             all                                     peer
host    all             all             127.0.0.1/32            md5
host    all             all             ::1/128                 md5

第一组参数不是很安全,但在我的测试环境中很好 - 我肯定会在生产服务器上强化它。添加上面的localhost配置行并重新启动服务修复了所有内容。