https://www.postgresql.org/docs/10/static/sql-createsubscription.html
CONNECTION 'conninfo' The connection string to the publisher. For
details see
https://www.postgresql.org/docs/10/static/libpq-connect.html#LIBPQ-CONNSTRING
passfile
Specifies the name of the file used to store passwords (see
Section 33.15). Defaults to ~/.pgpass
So yes - it should work. Lets mock up. First I deliberately use bad passfile to see if it's reflected in error:
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
no, it's not, but checking logs does:
-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
ok, try using the default:
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
and this time even no warning! so checking chmod:
-bash-4.2$ ll ~/.pgpass
-r-------- 1 postgres postgres 1227 May 15 15:00 /home/vao/.pgpass
looks good, but aha - no line for this connection, because below asks for password:
-bash-4.2$ psql -h localhost -p 5433 -U vao t
Password for user vao:
so:
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"
aha - now it uses it, so back to 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"
yes, you can use both specified and default pgpassword file for logical replication subscription