我在FreeBSD上运行Postgresql 9.3。 FreeBSD使用pgsql作为Postgresql的默认系统用户。我的/usr/local/pgsql/data/pg_hba.conf看起来像这样:
@H_403_1@# TYPE DATABASE USER ADDRESS METHOD
local all pgsql peer
local all all md5
host all all 127.0.0.1/32 md5
host all all ::1/128 md5
@H_403_1@$ su pgsql
$ psql template1
template1=# \l
List of databases
...
这是按照意图工作的。
在远程机器上,我有一个可执行的任务来在FreeBSD服务器上创建一个数据库。
@H_403_1@- name: Create the postgresql database postgresql_db: name=mydatabase login_user=pgsql @H_403_1@PLAY [web] ******************************************************************** GATHERING FACTS *************************************************************** ok: [host.example.org] TASK: [database | Create the postgresql database] ***************************** Failed: [host.example.org] => {"Failed": true} msg: unable to connect to database: FATAL: Peer authentication Failed for user "pgsql" FATAL: all hosts have already Failed -- aborting