aboutsummaryrefslogtreecommitdiff
path: root/src/backend/replication/logical/tablesync.c
diff options
context:
space:
mode:
authorPeter Eisentraut <peter_e@gmx.net>2017-05-08 12:07:59 -0400
committerPeter Eisentraut <peter_e@gmx.net>2017-05-08 12:10:22 -0400
commit9a591c1bccc5edeb06b979c59f39753982131181 (patch)
treeff6efe9bfa8642c3ba23ce5237a6362e30a90f68 /src/backend/replication/logical/tablesync.c
parentb6576e5914d042bfad1c8629fe199f59b036c342 (diff)
downloadpostgresql-9a591c1bccc5edeb06b979c59f39753982131181.tar.gz
postgresql-9a591c1bccc5edeb06b979c59f39753982131181.zip
Fix statistics reporting in logical replication workers
This new arrangement ensures that statistics are reported right after commit of transactions. The previous arrangement didn't get this quite right and could lead to assertion failures. Author: Petr Jelinek <petr.jelinek@2ndquadrant.com> Reported-by: Erik Rijkers <er@xs4all.nl>
Diffstat (limited to 'src/backend/replication/logical/tablesync.c')
-rw-r--r--src/backend/replication/logical/tablesync.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/backend/replication/logical/tablesync.c b/src/backend/replication/logical/tablesync.c
index 0823000f001..7e51076b376 100644
--- a/src/backend/replication/logical/tablesync.c
+++ b/src/backend/replication/logical/tablesync.c
@@ -274,6 +274,7 @@ process_syncing_tables_for_apply(XLogRecPtr current_lsn)
static List *table_states = NIL;
static HTAB *last_start_times = NULL;
ListCell *lc;
+ bool started_tx = false;
Assert(!IsTransactionState());
@@ -290,6 +291,7 @@ process_syncing_tables_for_apply(XLogRecPtr current_lsn)
table_states = NIL;
StartTransactionCommand();
+ started_tx = true;
/* Fetch all non-ready tables. */
rstates = GetSubscriptionNotReadyRelations(MySubscription->oid);
@@ -304,8 +306,6 @@ process_syncing_tables_for_apply(XLogRecPtr current_lsn)
}
MemoryContextSwitchTo(oldctx);
- CommitTransactionCommand();
-
table_states_valid = true;
}
@@ -350,11 +350,14 @@ process_syncing_tables_for_apply(XLogRecPtr current_lsn)
{
rstate->state = SUBREL_STATE_READY;
rstate->lsn = current_lsn;
- StartTransactionCommand();
+ if (!started_tx)
+ {
+ StartTransactionCommand();
+ started_tx = true;
+ }
SetSubscriptionRelState(MyLogicalRepWorker->subid,
rstate->relid, rstate->state,
rstate->lsn);
- CommitTransactionCommand();
}
}
else
@@ -457,6 +460,12 @@ process_syncing_tables_for_apply(XLogRecPtr current_lsn)
}
}
}
+
+ if (started_tx)
+ {
+ CommitTransactionCommand();
+ pgstat_report_stat(false);
+ }
}
/*
@@ -806,6 +815,7 @@ LogicalRepSyncTableStart(XLogRecPtr *origin_startpos)
MyLogicalRepWorker->relstate,
MyLogicalRepWorker->relstate_lsn);
CommitTransactionCommand();
+ pgstat_report_stat(false);
/*
* We want to do the table data sync in single