pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
strange behavior of .pgpass file
5+ messages / 3 participants
[nested] [flat]

* strange behavior of .pgpass file
@ 2023-06-20 18:59  Atul Kumar <akumar14871@gmail.com>
  0 siblings, 2 replies; 5+ messages in thread

From: Atul Kumar @ 2023-06-20 18:59 UTC (permalink / raw)
  To: pgsql-general <pgsql-general@lists.postgresql.org>

Hi,

I found some strange behaviour of postgres superuser password in my
existing cluster, below is the basic outline of the setup.
1. version - postgres 12
2. replication - streaming replication async
3. OS- centos7
4. One Master, One Standby

I have identical pgpass files on both server postgres home directory.

So when I execute below command on slave node:
psql -h slave_hostname/ip -U postgres -d postgres -p 5432 -c "select
pg_is_in_recovery"

I get error of password authentication:

psql: error: FATAL:  password authentication failed for user "postgres"

password retrieved from file "/homedirectorypath/.pgpass"


But when I run the same command on master node:

psql -h slave_hostname/ip -U postgres -d postgres -p 5432 -c "select
pg_is_in_recovery"


I don't get any errors and get the expected output as "t".


*Note: the passwords in and path of both pgpass files are identical.*


then why am I getting errors on the slave node for the same command even
after having everything the same ?


Also, I tried the -W to enforce the password of postgres user but got the
same issue on slave and no issue on master although the password is the
same.


What am I missing here ? Please suggest.




Regards,
Atul

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: strange behavior of .pgpass file
@ 2023-06-20 20:08  Adrian Klaver <adrian.klaver@aklaver.com>
  parent: Atul Kumar <akumar14871@gmail.com>
  1 sibling, 2 replies; 5+ messages in thread

From: Adrian Klaver @ 2023-06-20 20:08 UTC (permalink / raw)
  To: Atul Kumar <akumar14871@gmail.com>; pgsql-general <pgsql-general@lists.postgresql.org>

On 6/20/23 11:59, Atul Kumar wrote:
> Hi,
> 
> I found some strange behaviour of postgres superuser password in my 
> existing cluster, below is the basic outline of the setup.
> 1. version - postgres 12
> 2. replication - streaming replication async
> 3. OS- centos7
> 4. One Master, One Standby
> 
> I have identical pgpass files on both server postgres home directory.
> 
> So when I execute below command on slave node:
> psql -h slave_hostname/ip -U postgres -d postgres -p 5432 -c "select 
> pg_is_in_recovery"
> 
> I get error of password authentication:
> 
> psql: error: FATAL:  password authentication failed for user "postgres"
> 
> password retrieved from file "/homedirectorypath/.pgpass"

I'm going to say this is failing because per:

https://www.postgresql.org/docs/15/libpq-pgpass.html

hostname:port:database:username:password

and when you are running it the hostname is not matching what you think 
it is and the wrong password is being returned. Whereas the example 
below is matching correctly.

> 
> 
> But when I run the same command on master node:
> 
> psql -h slave_hostname/ip -U postgres -d postgres -p 5432 -c "select 
> pg_is_in_recovery"
> 
> 
> I don't get any errors and get the expected output as "t".
> 
> 
> *_Note: the passwords in and path of both pgpass files are identical._*
> 
> 
> then why am I getting errors on the slave node for the same command even 
> after having everything the same ?
> 
> 
> Also, I tried the -W to enforce the password of postgres user but got 
> the same issue on slave and no issue on master although the password is 
> the same.
> 
> 
> What am I missing here ? Please suggest.
> 
> 
> 
> 
> Regards,
> Atul
> 
> 
> 
> 

-- 
Adrian Klaver
adrian.klaver@aklaver.com






^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: strange behavior of .pgpass file
@ 2023-06-20 22:29  Atul Kumar <akumar14871@gmail.com>
  parent: Adrian Klaver <adrian.klaver@aklaver.com>
  1 sibling, 0 replies; 5+ messages in thread

From: Atul Kumar @ 2023-06-20 22:29 UTC (permalink / raw)
  To: Adrian Klaver <adrian.klaver@aklaver.com>; pgsql-general <pgsql-general@lists.postgresql.org>

Please suggest.

On Wed, 21 Jun 2023, 02:02 Atul Kumar, <akumar14871@gmail.com> wrote:

> Th both pgpass files contains details as below:
>
> *:5432:*:postgres:<postgrespassword>
>
> I couldn't find anything wrong there in pgpass.
>
> and if the issue would have been with .pgpass file only then I would not
> have got the same error with -W option.
>
> But I am getting the same issue when I use -W option as well on standby
> side only.
>
> While on master node I don't get any error while using the -W option along
> with standby host name.
>
>
> What could be the reason for this? As same passwords are replicating to
> standby.
>
>
>
> Regards
> Atul
>
>
>
> On Wed, 21 Jun 2023, 01:38 Adrian Klaver, <adrian.klaver@aklaver.com>
> wrote:
>
>> On 6/20/23 11:59, Atul Kumar wrote:
>> > Hi,
>> >
>> > I found some strange behaviour of postgres superuser password in my
>> > existing cluster, below is the basic outline of the setup.
>> > 1. version - postgres 12
>> > 2. replication - streaming replication async
>> > 3. OS- centos7
>> > 4. One Master, One Standby
>> >
>> > I have identical pgpass files on both server postgres home directory.
>> >
>> > So when I execute below command on slave node:
>> > psql -h slave_hostname/ip -U postgres -d postgres -p 5432 -c "select
>> > pg_is_in_recovery"
>> >
>> > I get error of password authentication:
>> >
>> > psql: error: FATAL:  password authentication failed for user "postgres"
>> >
>> > password retrieved from file "/homedirectorypath/.pgpass"
>>
>> I'm going to say this is failing because per:
>>
>> https://www.postgresql.org/docs/15/libpq-pgpass.html
>>
>> hostname:port:database:username:password
>>
>> and when you are running it the hostname is not matching what you think
>> it is and the wrong password is being returned. Whereas the example
>> below is matching correctly.
>>
>> >
>> >
>> > But when I run the same command on master node:
>> >
>> > psql -h slave_hostname/ip -U postgres -d postgres -p 5432 -c "select
>> > pg_is_in_recovery"
>> >
>> >
>> > I don't get any errors and get the expected output as "t".
>> >
>> >
>> > *_Note: the passwords in and path of both pgpass files are identical._*
>> >
>> >
>> > then why am I getting errors on the slave node for the same command
>> even
>> > after having everything the same ?
>> >
>> >
>> > Also, I tried the -W to enforce the password of postgres user but got
>> > the same issue on slave and no issue on master although the password is
>> > the same.
>> >
>> >
>> > What am I missing here ? Please suggest.
>> >
>> >
>> >
>> >
>> > Regards,
>> > Atul
>> >
>> >
>> >
>> >
>>
>> --
>> Adrian Klaver
>> adrian.klaver@aklaver.com
>>
>>

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: strange behavior of .pgpass file
@ 2023-06-20 22:32  Adrian Klaver <adrian.klaver@aklaver.com>
  parent: Adrian Klaver <adrian.klaver@aklaver.com>
  1 sibling, 0 replies; 5+ messages in thread

From: Adrian Klaver @ 2023-06-20 22:32 UTC (permalink / raw)
  To: Atul Kumar <akumar14871@gmail.com>; +Cc: pgsql-general

On 6/20/23 13:32, Atul Kumar wrote:

Please reply to list also.
Ccing list.

> Th both pgpass files contains details as below:
> 
> *:5432:*:postgres:<postgrespassword>

There are no other lines in the file?

More information below.

> 
> I couldn't find anything wrong there in pgpass.
> 
> and if the issue would have been with .pgpass file only then I would not 
> have got the same error with -W option.
> 
> But I am getting the same issue when I use -W option as well on standby 
> side only.
> 
> While on master node I don't get any error while using the -W option 
> along with standby host name.
> 
> 
> What could be the reason for this? As same passwords are replicating to 
> standby.

 From here:

https://www.postgresql.org/docs/12/runtime-config-connection.html#RUNTIME-CONFIG-CONNECTION-AUTHENTI...

password_encryption (enum)

     When a password is specified in CREATE ROLE or ALTER ROLE, this 
parameter determines the algorithm to use to encrypt the password. The 
default value is md5, which stores the password as an MD5 hash (on is 
also accepted, as alias for md5). Setting this parameter to 
scram-sha-256 will encrypt the password with SCRAM-SHA-256.

     Note that older clients might lack support for the SCRAM 
authentication mechanism, and hence not work with passwords encrypted 
with SCRAM-SHA-256. See Section 20.5 for more details.


1) Verify what the password method is on both servers.

2) Check the version of psql you are using in each case.

> 
> 
> 
> Regards
> Atul
> 
> 
> 
> On Wed, 21 Jun 2023, 01:38 Adrian Klaver, <adrian.klaver@aklaver.com 
> <mailto:adrian.klaver@aklaver.com>> wrote:
> 
>     On 6/20/23 11:59, Atul Kumar wrote:
>      > Hi,
>      >
>      > I found some strange behaviour of postgres superuser password in my
>      > existing cluster, below is the basic outline of the setup.
>      > 1. version - postgres 12
>      > 2. replication - streaming replication async
>      > 3. OS- centos7
>      > 4. One Master, One Standby
>      >
>      > I have identical pgpass files on both server postgres home directory.
>      >
>      > So when I execute below command on slave node:
>      > psql -h slave_hostname/ip -U postgres -d postgres -p 5432 -c "select
>      > pg_is_in_recovery"
>      >
>      > I get error of password authentication:
>      >
>      > psql: error: FATAL:  password authentication failed for user
>     "postgres"
>      >
>      > password retrieved from file "/homedirectorypath/.pgpass"
> 
>     I'm going to say this is failing because per:
> 
>     https://www.postgresql.org/docs/15/libpq-pgpass.html
>     <https://www.postgresql.org/docs/15/libpq-pgpass.html;
> 
>     hostname:port:database:username:password
> 
>     and when you are running it the hostname is not matching what you think
>     it is and the wrong password is being returned. Whereas the example
>     below is matching correctly.
> 
>      >
>      >
>      > But when I run the same command on master node:
>      >
>      > psql -h slave_hostname/ip -U postgres -d postgres -p 5432 -c "select
>      > pg_is_in_recovery"
>      >
>      >
>      > I don't get any errors and get the expected output as "t".
>      >
>      >
>      > *_Note: the passwords in and path of both pgpass files are
>     identical._*
>      >
>      >
>      > then why am I getting errors on the slave node for the same
>     command even
>      > after having everything the same ?
>      >
>      >
>      > Also, I tried the -W to enforce the password of postgres user but
>     got
>      > the same issue on slave and no issue on master although the
>     password is
>      > the same.
>      >
>      >
>      > What am I missing here ? Please suggest.
>      >
>      >
>      >
>      >
>      > Regards,
>      > Atul
>      >
>      >
>      >
>      >
> 
>     -- 
>     Adrian Klaver
>     adrian.klaver@aklaver.com <mailto:adrian.klaver@aklaver.com>
> 

-- 
Adrian Klaver
adrian.klaver@aklaver.com






^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: strange behavior of .pgpass file
@ 2023-06-21 08:40  Laurenz Albe <laurenz.albe@cybertec.at>
  parent: Atul Kumar <akumar14871@gmail.com>
  1 sibling, 0 replies; 5+ messages in thread

From: Laurenz Albe @ 2023-06-21 08:40 UTC (permalink / raw)
  To: Atul Kumar <akumar14871@gmail.com>; pgsql-general <pgsql-general@lists.postgresql.org>

On Wed, 2023-06-21 at 00:29 +0530, Atul Kumar wrote:
> I found some strange behaviour of postgres superuser password in my existing cluster, below is the basic outline of the setup.
> 1. version - postgres 12
> 2. replication - streaming replication async
> 3. OS- centos7
> 4. One Master, One Standby
> 
> I have identical pgpass files on both server postgres home directory.
> 
> So when I execute below command on slave node:
> psql -h slave_hostname/ip -U postgres -d postgres -p 5432 -c "select pg_is_in_recovery"
> 
> I get error of password authentication:
> 
> psql: error: FATAL:  password authentication failed for user "postgres"
> password retrieved from file "/homedirectorypath/.pgpass"
> 
> But when I run the same command on master node:
> psql -h slave_hostname/ip -U postgres -d postgres -p 5432 -c "select pg_is_in_recovery"
> 
> I don't get any errors and get the expected output as "t".
> 
> Note: the passwords in and path of both pgpass files are identical.
> 
> then why am I getting errors on the slave node for the same command even after having everything the same ?

pg_hba.conf could be different on both servers.

Yours,
Laurenz Albe





^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2023-06-21 08:40 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2023-06-20 18:59 strange behavior of .pgpass file Atul Kumar <akumar14871@gmail.com>
2023-06-20 20:08 ` Adrian Klaver <adrian.klaver@aklaver.com>
2023-06-20 22:29   ` Atul Kumar <akumar14871@gmail.com>
2023-06-20 22:32   ` Adrian Klaver <adrian.klaver@aklaver.com>
2023-06-21 08:40 ` Laurenz Albe <laurenz.albe@cybertec.at>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox