Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc314ead

Browse files
committed
Add ability to reserve WAL upon slot creation via replication protocol.
Since6fcd885 it is possible to immediately reserve WAL when creating aslot via pg_create_physical_replication_slot(). Extend the replicationprotocol to allow that as well.Although, in contrast to the SQL interface, it is possible to update thereserved location via the replication interface, it is still usefulbeing able to reserve upon creation there. Otherwise the logic inReplicationSlotReserveWal() has to be repeated in slot employingclients.Author: Michael PaquierDiscussion: CAB7nPqT0Wc1W5mdYGeJ_wbutbwNN+3qgrFR64avXaQCiJMGaYA@mail.gmail.com
1 parent258ee1b commitc314ead

File tree

5 files changed

+32
-3
lines changed

5 files changed

+32
-3
lines changed

‎doc/src/sgml/protocol.sgml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1434,7 +1434,7 @@ The commands accepted in walsender mode are:
14341434
</varlistentry>
14351435

14361436
<varlistentry>
1437-
<term>CREATE_REPLICATION_SLOT <replaceable class="parameter">slot_name</> { <literal>PHYSICAL</> | <literal>LOGICAL</> <replaceable class="parameter">output_plugin</> }
1437+
<term>CREATE_REPLICATION_SLOT <replaceable class="parameter">slot_name</> { <literal>PHYSICAL</>[ RESERVE_WAL ]| <literal>LOGICAL</> <replaceable class="parameter">output_plugin</> }
14381438
<indexterm><primary>CREATE_REPLICATION_SLOT</primary></indexterm>
14391439
</term>
14401440
<listitem>
@@ -1463,6 +1463,17 @@ The commands accepted in walsender mode are:
14631463
</para>
14641464
</listitem>
14651465
</varlistentry>
1466+
1467+
<varlistentry>
1468+
<term><literal>RESERVE_WAL</></term>
1469+
<listitem>
1470+
<para>
1471+
Specify that this physical replication reserves <acronym>WAL</>
1472+
immediately; otherwise <acronym>WAL</> is only reserved upon
1473+
connection from a streaming replication client.
1474+
</para>
1475+
</listitem>
1476+
</varlistentry>
14661477
</variablelist>
14671478
</listitem>
14681479
</varlistentry>

‎src/backend/replication/repl_gram.y

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ Node *replication_parse_result;
7676
%tokenK_PHYSICAL
7777
%tokenK_LOGICAL
7878
%tokenK_SLOT
79+
%tokenK_RESERVE_WAL
7980

8081
%type<node>command
8182
%type<node>base_backupstart_replicationstart_logical_replication
@@ -88,6 +89,7 @@ Node *replication_parse_result;
8889
%type<defelt>plugin_opt_elem
8990
%type<node>plugin_opt_arg
9091
%type<str>opt_slot
92+
%type<boolval>opt_reserve_wal
9193

9294
%%
9395

@@ -181,13 +183,14 @@ base_backup_opt:
181183
;
182184

183185
create_replication_slot:
184-
/* CREATE_REPLICATION_SLOT slot PHYSICAL*/
185-
K_CREATE_REPLICATION_SLOTIDENTK_PHYSICAL
186+
/* CREATE_REPLICATION_SLOT slot PHYSICALRESERVE_WAL*/
187+
K_CREATE_REPLICATION_SLOTIDENTK_PHYSICALopt_reserve_wal
186188
{
187189
CreateReplicationSlotCmd *cmd;
188190
cmd = makeNode(CreateReplicationSlotCmd);
189191
cmd->kind = REPLICATION_KIND_PHYSICAL;
190192
cmd->slotname =$2;
193+
cmd->reserve_wal =$4;
191194
$$ = (Node *) cmd;
192195
}
193196
/* CREATE_REPLICATION_SLOT slot LOGICAL plugin*/
@@ -268,6 +271,11 @@ opt_physical:
268271
|/* EMPTY*/
269272
;
270273

274+
opt_reserve_wal:
275+
K_RESERVE_WAL{$$ =true; }
276+
|/* EMPTY*/{$$ =false; }
277+
;
278+
271279
opt_slot:
272280
K_SLOTIDENT
273281
{$$ =$2; }

‎src/backend/replication/repl_scanner.l

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ CREATE_REPLICATION_SLOT{ return K_CREATE_REPLICATION_SLOT; }
9595
DROP_REPLICATION_SLOT{return K_DROP_REPLICATION_SLOT; }
9696
TIMELINE_HISTORY{return K_TIMELINE_HISTORY; }
9797
PHYSICAL{return K_PHYSICAL; }
98+
RESERVE_WAL{return K_RESERVE_WAL; }
9899
LOGICAL{return K_LOGICAL; }
99100
SLOT{return K_SLOT; }
100101

‎src/backend/replication/walsender.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,14 @@ CreateReplicationSlot(CreateReplicationSlotCmd *cmd)
826826

827827
ReplicationSlotPersist();
828828
}
829+
elseif (cmd->kind==REPLICATION_KIND_PHYSICAL&&cmd->reserve_wal)
830+
{
831+
ReplicationSlotReserveWal();
832+
833+
/* Write this slot to disk */
834+
ReplicationSlotMarkDirty();
835+
ReplicationSlotSave();
836+
}
829837

830838
slot_name=NameStr(MyReplicationSlot->data.name);
831839
snprintf(xpos,sizeof(xpos),"%X/%X",

‎src/include/nodes/replnodes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ typedef struct CreateReplicationSlotCmd
5555
char*slotname;
5656
ReplicationKindkind;
5757
char*plugin;
58+
boolreserve_wal;
5859
}CreateReplicationSlotCmd;
5960

6061

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp