aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2023-09-07 14:12:18 +0900
committerMichael Paquier <michael@paquier.xyz>2023-09-07 14:12:18 +0900
commite1c6db6309292827fc6baf7cf7df87d49254c7e1 (patch)
tree90b759c9da3ff7f00932155ff0a1435bcef3ab03
parent0174c2d213f69a4ba87932de706eedf3fbb5979e (diff)
downloadpostgresql-e1c6db6309292827fc6baf7cf7df87d49254c7e1.tar.gz
postgresql-e1c6db6309292827fc6baf7cf7df87d49254c7e1.zip
pg_basebackup: Generate valid temporary slot names under PQbackendPID()
pgbouncer can cause PQbackendPID() to return negative values due to it filling be_pid with random bytes (even these days pid_max can only be set up to 2^22 on 64b machines on Linux, for example, so this cannot happen with normal PID numbers). When this happens, pg_basebackup may generate a temporary slot name that may not be accepted by the parser, leading to spurious failures, like: pg_basebackup: error: could not send replication command ERROR: replication slot name "pg_basebackup_-1201966863" contains invalid character This commit fixes that problem by formatting the result from PQbackendPID() as an unsigned integer when creating the temporary replication slot name, so as the invalid character is gone and the command can be parsed. Author: Jelte Fennema Reviewed-by: Daniel Gustafsson, Nishant Sharma Discussion: https://postgr.es/m/CAGECzQQOGvYfp8ziF4fWQ_o8s2K7ppaoWBQnTmdakn3s-4Z=5g@mail.gmail.com Backpatch-through: 11
-rw-r--r--src/bin/pg_basebackup/pg_basebackup.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c
index 74f5332e956..1a8cef345dc 100644
--- a/src/bin/pg_basebackup/pg_basebackup.c
+++ b/src/bin/pg_basebackup/pg_basebackup.c
@@ -654,7 +654,8 @@ StartLogStreamer(char *startpos, uint32 timeline, char *sysidentifier,
* Create replication slot if requested
*/
if (temp_replication_slot && !replication_slot)
- replication_slot = psprintf("pg_basebackup_%d", (int) PQbackendPID(param->bgconn));
+ replication_slot = psprintf("pg_basebackup_%u",
+ (unsigned int) PQbackendPID(param->bgconn));
if (temp_replication_slot || create_slot)
{
if (!CreateReplicationSlot(param->bgconn, replication_slot, NULL,