@@ -384,30 +384,31 @@ pg_decode_begin_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn)
384384 send_replication_origin &= txn -> origin_id != InvalidRepOriginId ;
385385
386386 OutputPluginPrepareWrite (ctx , !send_replication_origin );
387- data -> api -> write_begin (ctx -> out , data , txn );
387+ if (data -> api ) {
388+ data -> api -> write_begin (ctx -> out , data , txn );
388389
389- if (send_replication_origin )
390- {
391- char * origin ;
392-
393- /* Message boundary */
394- OutputPluginWrite (ctx , false);
395- OutputPluginPrepareWrite (ctx , true);
396-
397- /*
398- * XXX: which behaviour we want here?
399- *
400- * Alternatives:
401- * - don't send origin message if origin name not found
402- * (that's what we do now)
403- * - throw error - that will break replication, not good
404- * - send some special "unknown" origin
405- */
406- if (data -> api -> write_origin &&
407- replorigin_by_oid (txn -> origin_id , true, & origin ))
390+ if (send_replication_origin )
391+ {
392+ char * origin ;
393+
394+ /* Message boundary */
395+ OutputPluginWrite (ctx , false);
396+ OutputPluginPrepareWrite (ctx , true);
397+
398+ /*
399+ * XXX: which behaviour we want here?
400+ *
401+ * Alternatives:
402+ * - don't send origin message if origin name not found
403+ * (that's what we do now)
404+ * - throw error - that will break replication, not good
405+ * - send some special "unknown" origin
406+ */
407+ if (data -> api -> write_origin &&
408+ replorigin_by_oid (txn -> origin_id , true, & origin ))
408409 data -> api -> write_origin (ctx -> out , origin , txn -> origin_lsn );
410+ }
409411 }
410-
411412 OutputPluginWrite (ctx , true);
412413}
413414
@@ -421,7 +422,9 @@ pg_decode_commit_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
421422 PGLogicalOutputData * data = (PGLogicalOutputData * )ctx -> output_plugin_private ;
422423
423424 OutputPluginPrepareWrite (ctx , true);
424- data -> api -> write_commit (ctx -> out , data , txn , commit_lsn );
425+ if (data -> api ) {
426+ data -> api -> write_commit (ctx -> out , data , txn , commit_lsn );
427+ }
425428 OutputPluginWrite (ctx , true);
426429}
427430
@@ -433,7 +436,7 @@ pg_decode_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
433436 MemoryContext old ;
434437
435438 /* First check the table filter */
436- if (!call_row_filter_hook (data , txn , relation , change ))
439+ if (!call_row_filter_hook (data , txn , relation , change ) || data -> api == NULL )
437440 return ;
438441
439442 /* Avoid leaking memory by using and resetting our own context */
@@ -539,7 +542,9 @@ send_startup_message(LogicalDecodingContext *ctx,
539542 */
540543
541544 OutputPluginPrepareWrite (ctx , last_message );
542- data -> api -> write_startup_message (ctx -> out , msg );
545+ if (data -> api ) {
546+ data -> api -> write_startup_message (ctx -> out , msg );
547+ }
543548 OutputPluginWrite (ctx , last_message );
544549
545550 pfree (msg );
0 commit comments