Thread: Clarification on warning when connecting to 'pgbouncer' database via Pgbouncer

Clarification on warning when connecting to 'pgbouncer' database via Pgbouncer

From
Shaik Mohammad Mujeeb
Date:
Hi Hackers,

I was hoping to get some clarification regarding a behaviour I observed while connecting to the special 'pgbouncer' database used for administering or monitoring Pgbouncer.

After the commit cf0cab868a, introduced in PG15, I noticed that when connecting to the 'pgbouncer' database via Pgbouncer, the following warning is shown:

psql (17.2, server 1.20.1/bouncer)
WARNING: psql major version 17, server major version 1.20.
         Some psql features might not work.


From what I understand, this seems to be due to the lower version check in the connection_warnings() function, where we check if pset.sversion < 90200.

if (pset.sversion / 100 > client_ver / 100 ||
pset.sversion < 90200)
printf(_("WARNING: %s major version %s, server major version %s.\n"
"         Some psql features might not work.\n"),
   pset.progname,
   formatPGVersionNumber(client_ver, false,
cverbuf, sizeof(cverbuf)),
   formatPGVersionNumber(pset.sversion, false,
sverbuf, sizeof(sverbuf)));


In my case, pset.sversion ends up being 12001 (due to PgBouncer v1.20.1), and since that’s less than 90200, the warning gets triggered, which feels misleading. But I was wondering - does it really make sense to compare PgBouncer’s version in this context using the same logic as PostgreSQL server versions?

Is this an expected behaviour, or would it make sense to handle Pgbouncer differently in this check?

Appreciate any insights!



Thanks & Regards,
Shaik Mohammad Mujeeb
Member Technical Staff
Zoho Corp

On Tue, May 27, 2025 at 11:41 AM Shaik Mohammad Mujeeb <mujeeb.sk@zohocorp.com> wrote:
After the commit cf0cab868a, introduced in PG15, I noticed that when connecting to the 'pgbouncer' database via Pgbouncer, the following warning is shown:

psql (17.2, server 1.20.1/bouncer)
WARNING: psql major version 17, server major version 1.20.
         Some psql features might not work.


Is this an expected behaviour, or would it make sense to handle Pgbouncer differently in this check?

psql has zero awareness of pgbouncer or any other non-PostgreSQL server you might be able to point it to and establish a successful connection.  The lack of a warning previously is probably more incorrect than its presence now.

That said, I'd probably try and teach psql to check for whether its remote is a PostgreSQL server and, if not, warn that basically everything but direct query sending is unlikely to work.  Skipping the version processing logic altogether since you are correct it makes no sense to compare the client version to a server version of a non-PostgreSQL server.

David J.

"David G. Johnston" <david.g.johnston@gmail.com> writes:
> psql has zero awareness of pgbouncer or any other non-PostgreSQL server you
> might be able to point it to and establish a successful connection.  The
> lack of a warning previously is probably more incorrect than its presence
> now.

Yeah.  I'd say the fundamental problem is that pgbouncer is abusing
the server_version parameter, which will break plenty of things
besides psql --- pg_dump for instance, and just about any other
application that needs to adjust its queries to suit different
Postgres server versions.  If they feel a need to advertise
pgbouncer's version there, it wouldn't be that hard to make
server_version read out as something like "17.5 (pgbouncer XX.YY)",
which would not confuse libpq/psql (cf. parsing code in
pqSaveParameterStatus).  But apparently they didn't do that.

Anyway, I'm minus quite a lot on silencing this warning, because
it is telling you about real problems you are likely to hit.

            regards, tom lane



On Tue, May 27, 2025 at 3:08 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
"David G. Johnston" <david.g.johnston@gmail.com> writes:
> psql has zero awareness of pgbouncer or any other non-PostgreSQL server you
> might be able to point it to and establish a successful connection.  The
> lack of a warning previously is probably more incorrect than its presence
> now.

Yeah.  I'd say the fundamental problem is that pgbouncer is abusing
the server_version parameter, which will break plenty of things
besides psql --- pg_dump for instance

They proxy over the real server information during actual bouncer work - it's just their local administrative database connection - one that isn't proxied - that is at issue here.


Anyway, I'm minus quite a lot on silencing this warning, because
it is telling you about real problems you are likely to hit.


How about the false-negative that was happening for years when this warning didn't appear even though you were connected to pgbouncer and not PostgreSQL?

David J.

"David G. Johnston" <david.g.johnston@gmail.com> writes:
> On Tue, May 27, 2025 at 3:08 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> Yeah.  I'd say the fundamental problem is that pgbouncer is abusing
>> the server_version parameter, which will break plenty of things
>> besides psql --- pg_dump for instance

> They proxy over the real server information during actual bouncer work -
> it's just their local administrative database connection - one that isn't
> proxied - that is at issue here.

Okay, but they're still abusing the wire protocol: server_version is
supposed to be a Postgres version, not some random number.  My advice
to them would be to make up their mind which PG version they intend
their "local administrative database" to act like, and put that in
server_version.

            regards, tom lane



> Anyway, I'm minus quite a lot on silencing this warning, because
> it is telling you about real problems you are likely to hit.
+1

I just wanted to clarify that the concern here isn’t about the warning itself being shown, but rather about the reason it conveys, which can be a bit misleading.

The current warning suggests that some psql features might not work due to the server version being 1.20. This can lead to confusion - as it did in my case - making it seem like there's an issue with PgBouncer v1.20.1. However, this same warning appears even when we use the latest version of PgBouncer, so the message doesn't accurately reflect the root cause.

Instead, a clearer message like:

"WARNING: non-PostgreSQL server. Some psql features might not work."

would be more appropriate. It immediately communicates that the server is not PostgreSQL (as in the case of PgBouncer), which would naturally explain why some psql features (like \d commands, as Euler mentioned) may not function as expected. This avoids unnecessary suspicion about the PgBouncer version being used.

The main goal here is not to suppress the warning altogether, but to make the message more meaningful and reflective of the actual scenario.

If we can reliably detect that it’s a non-PostgreSQL server, we could adjust the warning accordingly and avoid doing a (client-server)version comparison that doesn’t apply in this context.



Thanks & Regards,
Shaik Mohammad Mujeeb
Member Technical Staff
Zoho Corp




---- On Wed, 28 May 2025 03:38:12 +0530 Tom Lane <tgl@sss.pgh.pa.us> wrote ---

"David G. Johnston" <david.g.johnston@gmail.com> writes:
> psql has zero awareness of pgbouncer or any other non-PostgreSQL server you
> might be able to point it to and establish a successful connection. The
> lack of a warning previously is probably more incorrect than its presence
> now.

Yeah. I'd say the fundamental problem is that pgbouncer is abusing
the server_version parameter, which will break plenty of things
besides psql --- pg_dump for instance, and just about any other
application that needs to adjust its queries to suit different
Postgres server versions. If they feel a need to advertise
pgbouncer's version there, it wouldn't be that hard to make
server_version read out as something like "17.5 (pgbouncer XX.YY)",
which would not confuse libpq/psql (cf. parsing code in
pqSaveParameterStatus). But apparently they didn't do that.

Anyway, I'm minus quite a lot on silencing this warning, because
it is telling you about real problems you are likely to hit.

            regards, tom lane


Also, let’s say hypothetically that PgBouncer had a version like 17.2 - matching the psql (client) major version. In that case, the warning wouldn’t be shown at all, which might not be accurate either.

So, I feel that if we can reliably detect when the backend is a non-PostgreSQL server, it might be better to adjust the warning accordingly, rather than relying on a client-server version comparison in such cases.



Thanks & Regards,
Shaik Mohammad Mujeeb
Member Technical Staff
Zoho Corp





---- On Wed, 28 May 2025 04:07:40 +0530 Shaik Mohammad Mujeeb <mujeeb.sk@zohocorp.com> wrote ---

> Anyway, I'm minus quite a lot on silencing this warning, because
> it is telling you about real problems you are likely to hit.
+1

I just wanted to clarify that the concern here isn’t about the warning itself being shown, but rather about the reason it conveys, which can be a bit misleading.

The current warning suggests that some psql features might not work due to the server version being 1.20. This can lead to confusion - as it did in my case - making it seem like there's an issue with PgBouncer v1.20.1. However, this same warning appears even when we use the latest version of PgBouncer, so the message doesn't accurately reflect the root cause.

Instead, a clearer message like:

"WARNING: non-PostgreSQL server. Some psql features might not work."

would be more appropriate. It immediately communicates that the server is not PostgreSQL (as in the case of PgBouncer), which would naturally explain why some psql features (like \d commands, as Euler mentioned) may not function as expected. This avoids unnecessary suspicion about the PgBouncer version being used.

The main goal here is not to suppress the warning altogether, but to make the message more meaningful and reflective of the actual scenario.

If we can reliably detect that it’s a non-PostgreSQL server, we could adjust the warning accordingly and avoid doing a (client-server)version comparison that doesn’t apply in this context.



Thanks & Regards,
Shaik Mohammad Mujeeb
Member Technical Staff
Zoho Corp




---- On Wed, 28 May 2025 03:38:12 +0530 Tom Lane <tgl@sss.pgh.pa.us> wrote ---




"David G. Johnston" <david.g.johnston@gmail.com> writes:
> psql has zero awareness of pgbouncer or any other non-PostgreSQL server you
> might be able to point it to and establish a successful connection. The
> lack of a warning previously is probably more incorrect than its presence
> now.

Yeah. I'd say the fundamental problem is that pgbouncer is abusing
the server_version parameter, which will break plenty of things
besides psql --- pg_dump for instance, and just about any other
application that needs to adjust its queries to suit different
Postgres server versions. If they feel a need to advertise
pgbouncer's version there, it wouldn't be that hard to make
server_version read out as something like "17.5 (pgbouncer XX.YY)",
which would not confuse libpq/psql (cf. parsing code in
pqSaveParameterStatus). But apparently they didn't do that.

Anyway, I'm minus quite a lot on silencing this warning, because
it is telling you about real problems you are likely to hit.

            regards, tom lane


On Wed, 28 May 2025, 07:21 Tom Lane, <tgl@sss.pgh.pa.us> wrote:
Shaik Mohammad Mujeeb <mujeeb.sk@zohocorp.com> writes:
> So, I feel that if we can reliably detect when the backend is a non-PostgreSQL server, it might be better to adjust the warning accordingly, rather than relying on a client-server version comparison in such cases.

The entire point of having a wire protocol is that you can't/don't
need to detect that.  The short answer here is that this is
pgbouncer's bug and you should be nagging them to change, not us.

maybe I'm missing something but it seems like it's behaving as expected. pgbouncer advertises a version that both seems to be understood by the protocol and is incompatible with any real postgres version.  since such connection only allows plain SHOW statement, the warning about some psql features seems perfectly accurate, if not wildly an understatement as literally no psql feature will work.