On Fri, Aug 14, 2015 at 4:54 PM, Andres Freund <and...@anarazel.de> wrote: > On 2015-08-14 16:44:44 +0900, Michael Paquier wrote: >> Commit 6fcd8851, which is the result of this thread, is not touching >> the replication protocol at all. This looks like an oversight to me: >> we should be a maximum consistent between the SQL interface and the >> replication protocol if possible, and it looks useful to me to be able >> to set restart_lsn when creating the slot as well when using a >> replication connection. > > It wasn't, at least not from my side. You can relatively easily do > nearly the same just by connecting to the slot and sending a feedback > message. The complaint upthread (and/or a related thread) was that it's > not possible to do the same from SQL. > > It'd be a good additional to offer the same facility to the replication > protocol. > [...] > I'd name it RESERVE_WAL. My feeling is that the options for the logical > case are geared towards the output plugin, not the walsender. I think > it'd be confusing to use (slot_options) differently for physical slots.
Well, this has taken less time than I thought: =# CREATE_REPLICATION_SLOT toto PHYSICAL; slot_name | consistent_point | snapshot_name | output_plugin -----------+------------------+---------------+--------------- toto | 0/0 | null | null (1 row) =# CREATE_REPLICATION_SLOT toto2 PHYSICAL RESERVE_WAL; slot_name | consistent_point | snapshot_name | output_plugin -----------+------------------+---------------+--------------- toto2 | 0/0 | null | null (1 row) =# \q $ psql -c 'select slot_name,restart_lsn from pg_replication_slots' slot_name | restart_lsn -----------+------------- toto | toto2 | 0/1738850 (2 rows) What do you want to do with that? Do you wish to have a look at it or should I register it in the next CF? I am fine with both, though this is tightly linked with the feature already committed. Regards, -- Michael
diff --git a/doc/src/sgml/protocol.sgml b/doc/src/sgml/protocol.sgml index 42e9497..df49fa3 100644 --- a/doc/src/sgml/protocol.sgml +++ b/doc/src/sgml/protocol.sgml @@ -1434,7 +1434,7 @@ The commands accepted in walsender mode are: </varlistentry> <varlistentry> - <term>CREATE_REPLICATION_SLOT <replaceable class="parameter">slot_name</> { <literal>PHYSICAL</> | <literal>LOGICAL</> <replaceable class="parameter">output_plugin</> } + <term>CREATE_REPLICATION_SLOT <replaceable class="parameter">slot_name</> { <literal>PHYSICAL</> [ RESERVE_WAL ] | <literal>LOGICAL</> <replaceable class="parameter">output_plugin</> } <indexterm><primary>CREATE_REPLICATION_SLOT</primary></indexterm> </term> <listitem> @@ -1463,6 +1463,17 @@ The commands accepted in walsender mode are: </para> </listitem> </varlistentry> + + <varlistentry> + <term><literal>RESERVE_WAL</></term> + <listitem> + <para> + Specify that the <acronym>LSN</> for this physical replication + slot is reserved immediately; otherwise the <acronym>LSN</> is + reserved on first connection from a streaming replication client. + </para> + </listitem> + </varlistentry> </variablelist> </listitem> </varlistentry> diff --git a/src/backend/replication/repl_gram.y b/src/backend/replication/repl_gram.y index e9177ca..077d67d 100644 --- a/src/backend/replication/repl_gram.y +++ b/src/backend/replication/repl_gram.y @@ -76,6 +76,7 @@ Node *replication_parse_result; %token K_PHYSICAL %token K_LOGICAL %token K_SLOT +%token K_RESERVE_WAL %type <node> command %type <node> base_backup start_replication start_logical_replication @@ -88,6 +89,7 @@ Node *replication_parse_result; %type <defelt> plugin_opt_elem %type <node> plugin_opt_arg %type <str> opt_slot +%type <boolval> opt_reserve_wal %% @@ -181,13 +183,14 @@ base_backup_opt: ; create_replication_slot: - /* CREATE_REPLICATION_SLOT slot PHYSICAL */ - K_CREATE_REPLICATION_SLOT IDENT K_PHYSICAL + /* CREATE_REPLICATION_SLOT slot PHYSICAL RESERVE_WAL */ + K_CREATE_REPLICATION_SLOT IDENT K_PHYSICAL opt_reserve_wal { CreateReplicationSlotCmd *cmd; cmd = makeNode(CreateReplicationSlotCmd); cmd->kind = REPLICATION_KIND_PHYSICAL; cmd->slotname = $2; + cmd->reserve_wal = $4; $$ = (Node *) cmd; } /* CREATE_REPLICATION_SLOT slot LOGICAL plugin */ @@ -268,6 +271,12 @@ opt_physical: | /* EMPTY */ ; +opt_reserve_wal: + K_RESERVE_WAL + { $$ = TRUE } + | /* EMPTY */ + { $$ = FALSE } + opt_slot: K_SLOT IDENT { $$ = $2; } diff --git a/src/backend/replication/repl_scanner.l b/src/backend/replication/repl_scanner.l index 056cc14..d7030c1 100644 --- a/src/backend/replication/repl_scanner.l +++ b/src/backend/replication/repl_scanner.l @@ -95,6 +95,7 @@ CREATE_REPLICATION_SLOT { return K_CREATE_REPLICATION_SLOT; } DROP_REPLICATION_SLOT { return K_DROP_REPLICATION_SLOT; } TIMELINE_HISTORY { return K_TIMELINE_HISTORY; } PHYSICAL { return K_PHYSICAL; } +RESERVE_WAL { return K_RESERVE_WAL; } LOGICAL { return K_LOGICAL; } SLOT { return K_SLOT; } diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c index e1bab07..9142811 100644 --- a/src/backend/replication/walsender.c +++ b/src/backend/replication/walsender.c @@ -826,6 +826,14 @@ CreateReplicationSlot(CreateReplicationSlotCmd *cmd) ReplicationSlotPersist(); } + else if (cmd->kind == REPLICATION_KIND_PHYSICAL && cmd->reserve_wal) + { + ReplicationSlotReserveWal(); + + /* Write this slot to disk */ + ReplicationSlotMarkDirty(); + ReplicationSlotSave(); + } slot_name = NameStr(MyReplicationSlot->data.name); snprintf(xpos, sizeof(xpos), "%X/%X", diff --git a/src/include/nodes/replnodes.h b/src/include/nodes/replnodes.h index cac6419..4e35be6 100644 --- a/src/include/nodes/replnodes.h +++ b/src/include/nodes/replnodes.h @@ -55,6 +55,7 @@ typedef struct CreateReplicationSlotCmd char *slotname; ReplicationKind kind; char *plugin; + bool reserve_wal; } CreateReplicationSlotCmd;
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers