https://www.postgresql.org/docs/10/static/sql-createsubscription.html
CONNECTION 'conninfo' 发布者的连接字符串。详情见
https://www.postgresql.org/docs/10/static/libpq-connect.html#LIBPQ-CONNSTRING
密码文件
指定用于存储密码的文件的名称(参见第 33.15 节)。默认为 ~/.pgpass
所以是的 - 它应该工作。让我们模拟一下。首先,我故意使用 bad passfile 来查看它是否反映在错误中:
t=# CREATE SUBSCRIPTION mysub CONNECTION 'host=localhost port=5433 passfile=/tmp/p user=vao dbname=t' PUBLICATION mypub;
ERROR: could not connect to the publisher: fe_sendauth: no password supplied
不,不是,但检查日志可以:
-bash-4.2$ tail /pg/d10/log/postgresql-Tue.log | grep WARN | tail -n 1
WARNING: password file "/tmp/p" has group or world access; permissions should be u=rw (0600) or less
好的,尝试使用默认值:
t=# CREATE SUBSCRIPTION mysub CONNECTION 'host=localhost port=5433 user=vao dbname=t' PUBLICATION mypub;
ERROR: could not connect to the publisher: fe_sendauth: no password supplied
而这一次甚至没有任何警告!所以检查chmod:
-bash-4.2$ ll ~/.pgpass
-r-------- 1 postgres postgres 1227 May 15 15:00 /home/vao/.pgpass
看起来不错,但是啊哈 - 此连接没有线路,因为下面要求输入密码:
-bash-4.2$ psql -h localhost -p 5433 -U vao t
Password for user vao:
所以:
echo '*:*:*:vao:blah' > ~/.pgpass
-bash-4.2$ psql -h localhost -p 5433 -U vao t
psql: FATAL: password authentication failed for user "vao"
password retrieved from file "/var/lib/pgsql93/.pgpass"
啊哈 - 现在它使用它,所以回到 SQL:
t=# CREATE SUBSCRIPTION mysub CONNECTION 'host=localhost port=5433 user=vao dbname=t' PUBLICATION mypub;
ERROR: could not connect to the publisher: FATAL: password authentication failed for user "vao"
password retrieved from file "/var/lib/pgsql93/.pgpass"
是的,您可以使用指定的和默认的 pgpassword 文件进行逻辑复制订阅