diff options
author | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2020-03-27 16:04:52 -0300 |
---|---|---|
committer | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2020-03-27 16:20:33 -0300 |
commit | 092c6936de49effe63daad94855bcd8ef26a09dd (patch) | |
tree | 301494253f5a9a51254073617ed0d81199f3627b /src/backend/replication/walreceiverfuncs.c | |
parent | fbc7a716084ebccd2a996cc415187c269ea54b3e (diff) | |
download | postgresql-092c6936de49effe63daad94855bcd8ef26a09dd.tar.gz postgresql-092c6936de49effe63daad94855bcd8ef26a09dd.zip |
Set wal_receiver_create_temp_slot PGC_POSTMASTER
Commit 329730827848 gave walreceiver the ability to create and use a
temporary replication slot, and made it controllable by a GUC (enabled
by default) that can be changed with SIGHUP. That's useful but has two
problems: one, it's possible to cause the origin server to fill its disk
if the slot doesn't advance in time; and also there's a disconnect
between state passed down via the startup process and GUCs that
walreceiver reads directly.
We handle the first problem by setting the option to disabled by
default. If the user enables it, its on their head to make sure that
disk doesn't fill up.
We handle the second problem by passing the flag via startup rather than
having walreceiver acquire it directly, and making it PGC_POSTMASTER
(which ensures a walreceiver always has the fresh value). A future
commit can relax this (to PGC_SIGHUP again) by having the startup
process signal walreceiver to shutdown whenever the value changes.
Author: Sergei Kornilov <sk@zsrv.org>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Álvaro Herrera <alvherre@alvh.no-ip.org>
Discussion: https://postgr.es/m/20200122055510.GH174860@paquier.xyz
Diffstat (limited to 'src/backend/replication/walreceiverfuncs.c')
-rw-r--r-- | src/backend/replication/walreceiverfuncs.c | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/src/backend/replication/walreceiverfuncs.c b/src/backend/replication/walreceiverfuncs.c index 89c903e45af..21d18236076 100644 --- a/src/backend/replication/walreceiverfuncs.c +++ b/src/backend/replication/walreceiverfuncs.c @@ -215,13 +215,19 @@ ShutdownWalRcv(void) /* * Request postmaster to start walreceiver. * - * recptr indicates the position where streaming should begin, conninfo - * is a libpq connection string to use, and slotname is, optionally, the name - * of a replication slot to acquire. + * "recptr" indicates the position where streaming should begin. "conninfo" + * is a libpq connection string to use. "slotname" is, optionally, the name + * of a replication slot to acquire. "create_temp_slot" indicates to create + * a temporary slot when no "slotname" is given. + * + * WAL receivers do not directly load GUC parameters used for the connection + * to the primary, and rely on the values passed down by the caller of this + * routine instead. Hence, the addition of any new parameters should happen + * through this code path. */ void RequestXLogStreaming(TimeLineID tli, XLogRecPtr recptr, const char *conninfo, - const char *slotname) + const char *slotname, bool create_temp_slot) { WalRcvData *walrcv = WalRcv; bool launch = false; @@ -248,10 +254,22 @@ RequestXLogStreaming(TimeLineID tli, XLogRecPtr recptr, const char *conninfo, else walrcv->conninfo[0] = '\0'; - if (slotname != NULL) + /* + * Use configured replication slot if present, and ignore the value + * of create_temp_slot as the slot name should be persistent. Otherwise, + * use create_temp_slot to determine whether this WAL receiver should + * create a temporary slot by itself and use it, or not. + */ + if (slotname != NULL && slotname[0] != '\0') + { strlcpy((char *) walrcv->slotname, slotname, NAMEDATALEN); + walrcv->is_temp_slot = false; + } else + { walrcv->slotname[0] = '\0'; + walrcv->is_temp_slot = create_temp_slot; + } if (walrcv->walRcvState == WALRCV_STOPPED) { |