pg_basebackup: Always return valid temporary slot names

From: Jelte Fennema <me(at)jeltef(dot)nl>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Cc: Jim Jones <jim(dot)jones(at)uni-muenster(dot)de>
Subject: pg_basebackup: Always return valid temporary slot names
Date: 2023-08-31 09:13:00
Message-ID: CAGECzQQOGvYfp8ziF4fWQ_o8s2K7ppaoWBQnTmdakn3s-4Z=5g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

With PgBouncer in the middle PQbackendPID can return negative values
due to it filling all 32 bits of the be_pid with random bits.

When this happens it results in pg_basebackup generating an invalid slot
name (when no specific slot name is passed in) and thus throwing an
error like this:

pg_basebackup: error: could not send replication command
"CREATE_REPLICATION_SLOT "pg_basebackup_-1201966863" TEMPORARY
PHYSICAL ( RESERVE_WAL)": ERROR: replication slot name
"pg_basebackup_-1201966863" contains invalid character
HINT: Replication slot names may only contain lower case letters,
numbers, and the underscore character.

This patch fixes that problem by formatting the result from PQbackendPID
as an unsigned integer when creating the temporary replication slot
name.

I think it would be good to backport this fix too.

Replication connection support for PgBouncer is not merged yet, but
it's pretty much ready:
https://github.com/pgbouncer/pgbouncer/pull/876

The reason PgBouncer does not pass on the actual Postgres backend PID
is that it doesn't have an associated server connection yet when it
needs to send the startup message to the client. It also cannot use
it's own PID, because that would be the same for all clients, since
pgbouncer is a single process.

Attachment Content-Type Size
v1-0001-pg_basebackup-Always-return-valid-temporary-slot-.patch application/octet-stream 1.8 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2023-08-31 09:22:47 Re: persist logical slots to disk during shutdown checkpoint
Previous Message Andy Fan 2023-08-31 09:10:39 Re: Extract numeric filed in JSONB more effectively