summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Eisentraut2017-04-14 18:35:05 +0000
committerPeter Eisentraut2017-04-14 18:37:06 +0000
commit139eb9673cb84c76f493af7e68301ae204199746 (patch)
tree6ab3d94e12bb2ab040ecd2b64cc6759efb582f9c
parent67c2def11d49de05aacd959ecdffc6736f52efee (diff)
Report statistics in logical replication workers
Author: Stas Kelvich <[email protected]> Author: Petr Jelinek <[email protected]> Reported-by: Fujii Masao <[email protected]>
-rw-r--r--src/backend/postmaster/pgstat.c7
-rw-r--r--src/backend/replication/logical/tablesync.c8
-rw-r--r--src/backend/replication/logical/worker.c1
3 files changed, 12 insertions, 4 deletions
diff --git a/src/backend/postmaster/pgstat.c b/src/backend/postmaster/pgstat.c
index 3fb57f060c..235dc26405 100644
--- a/src/backend/postmaster/pgstat.c
+++ b/src/backend/postmaster/pgstat.c
@@ -769,9 +769,10 @@ allow_immediate_pgstat_restart(void)
/* ----------
* pgstat_report_stat() -
*
- * Called from tcop/postgres.c to send the so far collected per-table
- * and function usage statistics to the collector. Note that this is
- * called only when not within a transaction, so it is fair to use
+ * Must be called by processes that performs DML: tcop/postgres.c, logical
+ * receiver processes, SPI worker, etc. to send the so far collected
+ * per-table and function usage statistics to the collector. Note that this
+ * is called only when not within a transaction, so it is fair to use
* transaction stop time as an approximation of current time.
* ----------
*/
diff --git a/src/backend/replication/logical/tablesync.c b/src/backend/replication/logical/tablesync.c
index bf27641009..d287e95df1 100644
--- a/src/backend/replication/logical/tablesync.c
+++ b/src/backend/replication/logical/tablesync.c
@@ -114,9 +114,15 @@ StringInfo copybuf = NULL;
static void pg_attribute_noreturn()
finish_sync_worker(void)
{
- /* Commit any outstanding transaction. */
+ /*
+ * Commit any outstanding transaction. This is the usual case, unless
+ * there was nothing to do for the table.
+ */
if (IsTransactionState())
+ {
CommitTransactionCommand();
+ pgstat_report_stat(false);
+ }
/* And flush all writes. */
XLogFlush(GetXLogWriteRecPtr());
diff --git a/src/backend/replication/logical/worker.c b/src/backend/replication/logical/worker.c
index 29b6c6a168..656d399979 100644
--- a/src/backend/replication/logical/worker.c
+++ b/src/backend/replication/logical/worker.c
@@ -462,6 +462,7 @@ apply_handle_commit(StringInfo s)
/* Process any tables that are being synchronized in parallel. */
process_syncing_tables(commit_data.end_lsn);
+ pgstat_report_stat(false);
pgstat_report_activity(STATE_IDLE, NULL);
}