mirror of
https://github.com/postgres/postgres.git
synced 2025-11-09 06:21:09 +03:00
Move replication slot release to before_shmem_exit().
Previously, replication slots were released in ProcKill() on error, resulting in reporting replication slot drop of ephemeral slots after the stats subsystem was already shut down. To fix this problem, move replication slot release to a before_shmem_exit() hook that is called before the stats collector shuts down. There wasn't really a good reason for the slot handling to be in ProcKill() anyway. Patch by Masahiko Sawada, with very minor polishing by me. I, Andres, wrote a test for dropping slots during process exit, but there may be some OS dependent issues around the number of times FATAL error messages are displayed due to a still debated libpq issue. So that test will be committed separately / later. Reviewed-By: Kyotaro Horiguchi <horikyota.ntt@gmail.com> Reviewed-By: Andres Freund <andres@anarazel.de> Author: Masahiko Sawada <sawada.mshk@gmail.com> Discussion: https://postgr.es/m/CAD21AoDAeEpAbZEyYJsPZJUmSPaRicVSBObaL7sPaofnKz+9zg@mail.gmail.com
This commit is contained in:
@@ -46,6 +46,7 @@
|
||||
#include "pgstat.h"
|
||||
#include "replication/slot.h"
|
||||
#include "storage/fd.h"
|
||||
#include "storage/ipc.h"
|
||||
#include "storage/proc.h"
|
||||
#include "storage/procarray.h"
|
||||
#include "utils/builtins.h"
|
||||
@@ -99,6 +100,7 @@ ReplicationSlot *MyReplicationSlot = NULL;
|
||||
int max_replication_slots = 0; /* the maximum number of replication
|
||||
* slots */
|
||||
|
||||
static void ReplicationSlotShmemExit(int code, Datum arg);
|
||||
static void ReplicationSlotDropAcquired(void);
|
||||
static void ReplicationSlotDropPtr(ReplicationSlot *slot);
|
||||
|
||||
@@ -160,6 +162,29 @@ ReplicationSlotsShmemInit(void)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Register the callback for replication slot cleanup and releasing.
|
||||
*/
|
||||
void
|
||||
ReplicationSlotInitialize(void)
|
||||
{
|
||||
before_shmem_exit(ReplicationSlotShmemExit, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Release and cleanup replication slots.
|
||||
*/
|
||||
static void
|
||||
ReplicationSlotShmemExit(int code, Datum arg)
|
||||
{
|
||||
/* Make sure active replication slots are released */
|
||||
if (MyReplicationSlot != NULL)
|
||||
ReplicationSlotRelease();
|
||||
|
||||
/* Also cleanup all the temporary slots. */
|
||||
ReplicationSlotCleanup();
|
||||
}
|
||||
|
||||
/*
|
||||
* Check whether the passed slot name is valid and report errors at elevel.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user