Skip to content

Commit 1057958

Browse files
committed
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
1 parent 8d1cf96 commit 1057958

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/bin/pg_basebackup/pg_basebackup.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,8 @@ StartLogStreamer(char *startpos, uint32 timeline, char *sysidentifier,
651651
* Create replication slot if requested
652652
*/
653653
if (temp_replication_slot && !replication_slot)
654-
replication_slot = psprintf("pg_basebackup_%d", (int) PQbackendPID(param->bgconn));
654+
replication_slot = psprintf("pg_basebackup_%u",
655+
(unsigned int) PQbackendPID(param->bgconn));
655656
if (temp_replication_slot || create_slot)
656657
{
657658
if (!CreateReplicationSlot(param->bgconn, replication_slot, NULL,

0 commit comments

Comments
 (0)