diff --git a/src/backend/replication/logical/tablesync.c b/src/backend/replication/logical/tablesync.c
index 4647837b82..bb45c2107f 100644
--- a/src/backend/replication/logical/tablesync.c
+++ b/src/backend/replication/logical/tablesync.c
@@ -539,15 +539,27 @@ process_syncing_tables_for_apply(XLogRecPtr current_lsn)
 					LWLockRelease(LogicalRepWorkerLock);
 
 					/*
-					 * Enter busy loop and wait for synchronization worker to
-					 * reach expected state (or die trying).
+					 * If we have a transaction, we must commit it to release
+					 * any locks we have (it's quite likely we hold lock on
+					 * pg_replication_origin, which the sync worker will need
+					 * to update).  Then start a new transaction so we can
+					 * examine catalog state.
 					 */
-					if (!started_tx)
+					if (started_tx)
+					{
+						CommitTransactionCommand();
+						StartTransactionCommand();
+					}
+					else
 					{
 						StartTransactionCommand();
 						started_tx = true;
 					}
 
+					/*
+					 * Enter busy loop and wait for synchronization worker to
+					 * reach expected state (or die trying).
+					 */
 					wait_for_relation_state_change(rstate->relid,
 												   SUBREL_STATE_SYNCDONE);
 				}
