Report statistics in logical replication workers
authorPeter Eisentraut <peter_e@gmx.net>
Fri, 14 Apr 2017 18:35:05 +0000 (14:35 -0400)
committerPeter Eisentraut <peter_e@gmx.net>
Fri, 14 Apr 2017 18:37:06 +0000 (14:37 -0400)
Author: Stas Kelvich <s.kelvich@postgrespro.ru>
Author: Petr Jelinek <petr.jelinek@2ndquadrant.com>
Reported-by: Fujii Masao <masao.fujii@gmail.com>
src/backend/postmaster/pgstat.c
src/backend/replication/logical/tablesync.c
src/backend/replication/logical/worker.c

index 3fb57f060c95cbbb24a72dd85c1e6026de96458e..235dc26405556e28b67ab6507e4666c125e97a1f 100644 (file)
@@ -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.
  * ----------
  */
index bf276410099587345a0eaa96e35b2c19677a9835..d287e95df1ded4eadf9770bef6974314d1b0c69c 100644 (file)
@@ -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());
index 29b6c6a168943121fd2ae5b5e93a01c199376ac7..656d3999796dc782e5cae7896cdf3a53897fc54c 100644 (file)
@@ -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);
 }