pg_basebackup: could not connect to server: fe_sendauth: no password supplied I'm trying to set up streaming replication between two Postgres servers. The master server's pg_hba.conf file is configured this way:

host    replication     ${REP_USER}     0.0.0.0/0               md5
host    ${DB_NAME}      ${DB_USER}      0.0.0.0/0               md5


And the initializer script in the slave container runs the following at startup to connect to it:

cat &gt; ~/.pgpass &lt;&lt;EOS
${MASTER_PORT_5432_TCP_ADDR}:5432:${REP_USER}:${REP_PASS}
EOS
chmod 0600 ~/.pgpass

echo "Cleaning up old cluster directory"
rm -rf ${PGDATA}/*

echo "Starting base backup as replicator"
pg_basebackup -h ${MASTER_PORT_5432_TCP_ADDR} -D ${PGDATA} -U ${REP_USER} -vPw


All the env values are set. The problem is I keep getting this error:

pg_basebackup: could not connect to server: fe_sendauth: no password supplied


I'm not sure why this keeps happening. I have the password file in place with the right permissions. I also have the password in the recovery file, which doesn't get created because pg_basebackup fails all the time.

Any help would be appreciated...
Your issue is that your .pgpass file is missing the database field, and all fields are required (although you can use it * for any match). As you are using pg_basebackup (that uses the replication protocol), you need supply that as "replication":

cat &gt; ~/.pgpass &lt;&lt;EOS
${MASTER_PORT_5432_TCP_ADDR}:5432:replication:${REP_USER}:${REP_PASS}
EOS
...


Using * for the database field would work too, but replication is more strict.