@ -51,6 +51,7 @@
# include "catalog/pg_type.h"
# include "commands/dbcommands.h"
# include "commands/defrem.h"
# include "funcapi.h"
# include "libpq/libpq.h"
# include "libpq/pqformat.h"
@ -737,6 +738,48 @@ logical_read_xlog_page(XLogReaderState *state, XLogRecPtr targetPagePtr, int req
return count ;
}
/*
* Process extra options given to CREATE_REPLICATION_SLOT .
*/
static void
parseCreateReplSlotOptions ( CreateReplicationSlotCmd * cmd ,
bool * reserve_wal ,
bool * export_snapshot )
{
ListCell * lc ;
bool snapshot_action_given = false ;
bool reserve_wal_given = false ;
/* Parse options */
foreach ( lc , cmd - > options )
{
DefElem * defel = ( DefElem * ) lfirst ( lc ) ;
if ( strcmp ( defel - > defname , " export_snapshot " ) = = 0 )
{
if ( snapshot_action_given | | cmd - > kind ! = REPLICATION_KIND_LOGICAL )
ereport ( ERROR ,
( errcode ( ERRCODE_SYNTAX_ERROR ) ,
errmsg ( " conflicting or redundant options " ) ) ) ;
snapshot_action_given = true ;
* export_snapshot = defGetBoolean ( defel ) ;
}
else if ( strcmp ( defel - > defname , " reserve_wal " ) = = 0 )
{
if ( reserve_wal_given | | cmd - > kind ! = REPLICATION_KIND_PHYSICAL )
ereport ( ERROR ,
( errcode ( ERRCODE_SYNTAX_ERROR ) ,
errmsg ( " conflicting or redundant options " ) ) ) ;
reserve_wal_given = true ;
* reserve_wal = true ;
}
else
elog ( ERROR , " unrecognized option: %s " , defel - > defname ) ;
}
}
/*
* Create a new replication slot .
*/
@ -746,6 +789,8 @@ CreateReplicationSlot(CreateReplicationSlotCmd *cmd)
const char * snapshot_name = NULL ;
char xpos [ MAXFNAMELEN ] ;
char * slot_name ;
bool reserve_wal = false ;
bool export_snapshot = true ;
DestReceiver * dest ;
TupOutputState * tstate ;
TupleDesc tupdesc ;
@ -754,6 +799,8 @@ CreateReplicationSlot(CreateReplicationSlotCmd *cmd)
Assert ( ! MyReplicationSlot ) ;
parseCreateReplSlotOptions ( cmd , & reserve_wal , & export_snapshot ) ;
/* setup state for XLogReadPage */
sendTimeLineIsHistoric = false ;
sendTimeLine = ThisTimeLineID ;
@ -799,10 +846,13 @@ CreateReplicationSlot(CreateReplicationSlotCmd *cmd)
DecodingContextFindStartpoint ( ctx ) ;
/*
* Export a plain ( not of the snapbuild . c type ) snapshot to the user
* that can be imported into another session .
* Export the snapshot if we ' ve been asked to do so .
*
* NB . We will convert the snapbuild . c kind of snapshot to normal
* snapshot when doing this .
*/
snapshot_name = SnapBuildExportSnapshot ( ctx - > snapshot_builder ) ;
if ( export_snapshot )
snapshot_name = SnapBuildExportSnapshot ( ctx - > snapshot_builder ) ;
/* don't need the decoding context anymore */
FreeDecodingContext ( ctx ) ;
@ -810,7 +860,7 @@ CreateReplicationSlot(CreateReplicationSlotCmd *cmd)
if ( ! cmd - > temporary )
ReplicationSlotPersist ( ) ;
}
else if ( cmd - > kind = = REPLICATION_KIND_PHYSICAL & & cmd - > reserve_wal )
else if ( cmd - > kind = = REPLICATION_KIND_PHYSICAL & & reserve_wal )
{
ReplicationSlotReserveWal ( ) ;