Re: pgpass file in postresql.auto.conf?

From: "Dan Mahoney (Gushi)" <postgres(at)gushi(dot)org>
To: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: pgpass file in postresql.auto.conf?
Date: 2025-09-30 12:34:43
Message-ID: f1e6f98b-27bc-f268-df3d-224c346fd95c@gushi.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, 26 Sep 2025, Laurenz Albe wrote:

> On Fri, 2025-09-26 at 12:05 +0000, Dan Mahoney (Gushi) wrote:
>> In the interest of automation, I've set up a pgpass file for my
>> pg_basebackup between master and standby. This all works, thusly:
>>
>> pg_basebackup -d
>> 'postgres://repuser(at)10(dot)1(dot)1(dot)1:5432/foo?sslmode=verify-ca' -F p
>> --wal-method=stream -P -R -D /var/db/postgres/data17-test3
>>
>> However, instead of the password getting baked into the pgsql.auto.conf,
>> the reference to the passfile gets put in, instead:
>>
>> # Do not edit this file manually!
>> # It will be overwritten by the ALTER SYSTEM command.
>> primary_conninfo = 'user=repuser passfile=''/var/db/postgres/.pgpass''
>> channel_binding=prefer host=10.1.1.1 port=5432 sslmode=''verify-ca''
>> sslnegotiation=postgres sslcompression=0 sslcertmode=allow sslsni=1
>> ssl_min_protocol_version=TLSv1.2 gssencmode=disable krbsrvname=postgres
>> gssdelegation=0 target_session_attrs=any load_balance_hosts=disable
>> dbname=foo'
>
> That happens when "pg_basebackup" used a password file to connect to
> the PostgreSQL server.
>
>> But it seems postgres won't actually read the passfile.
>
> Oh yes, it will, as long as it has permissions 0600, 0400 or 0700 and
> belongs to the database server OS user (commonly "postgres").
> It must have worked for the "pg_basebackup", so PostgreSQL assumes it
> will also work for replication.

I found the problem.

When I did the basebackup, I used a string like:

postgres://repuser(at)10(dot)1(dot)1(dot)1:5432/foo?sslmode=verify-ca

And my .pgpass file on the replica reflects this:

#hostname:port:database:username:password
10.1.1.1:5432:foo:repuser:xxxx

(I read *somewhere* that you can use a dummy databasename in the .pgpass
file for replication purposes, but the actual DB is ignored.)

What I missed was that for replication, the database name in .pgpass
*must* be 'replication', for pgpass to pay attention to it.

As in, while everything else about the connection string allowed
pgbasebackup to find that line, that same fake DB name was not baked in to
the primary_conninfo allow postgres to find the same user.

-Dan

--

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Ron Johnson 2025-09-30 13:12:11 Re: Downgrade pgsql 17 to pgsql 12 question
Previous Message Laurenz Albe 2025-09-30 09:47:00 Re: Downgrade pgsql 17 to pgsql 12 question