diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml
index e64b7ef..458ae0f 100644
--- a/doc/src/sgml/monitoring.sgml
+++ b/doc/src/sgml/monitoring.sgml
@@ -642,6 +642,11 @@ postgres 27093 0.0 0.0 30096 2752 ? Ss 11:34 0:00 postgres: ser
+ waiting for synchronous replication>: The backend is waiting for its transaction to be flushed on a synchronous standby.
+
+
+
+
idle>: The backend is waiting for a new client command.
diff --git a/src/backend/replication/syncrep.c b/src/backend/replication/syncrep.c
index 325239d..b6ee1c3 100644
--- a/src/backend/replication/syncrep.c
+++ b/src/backend/replication/syncrep.c
@@ -45,7 +45,7 @@
#include "postgres.h"
#include
-
+#include
#include "access/xact.h"
#include "miscadmin.h"
#include "replication/syncrep.h"
@@ -151,6 +151,16 @@ SyncRepWaitForLSN(XLogRecPtr XactCommitLSN)
set_ps_display(new_status, false);
new_status[len] = '\0'; /* truncate off " waiting ..." */
}
+ /*
+ * Alter state in pg_stat before entering the loop.
+ * As with updating the ps display it is save to assume that we'll wait
+ * at least for a short time. Hence updating to a waiting state seems
+ * appropriate even without exactly checking if waiting is required.
+ * However, we avoid using the waiting-flag at this point as there is
+ * no lock to wait for.
+ */
+
+ pgstat_report_activity(STATE_WAITINGFORREPLICATION,NULL);
/*
* Wait for specified LSN to be confirmed.
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index f7c9bf6..84d67e0 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -663,6 +663,9 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
case STATE_IDLEINTRANSACTION_ABORTED:
values[4] = CStringGetTextDatum("idle in transaction (aborted)");
break;
+ case STATE_WAITINGFORREPLICATION:
+ values[4] = CStringGetTextDatum("waiting for synchronous replication");
+ break;
case STATE_DISABLED:
values[4] = CStringGetTextDatum("disabled");
break;
diff --git a/src/include/pgstat.h b/src/include/pgstat.h
index 9ecc163..ab1befc 100644
--- a/src/include/pgstat.h
+++ b/src/include/pgstat.h
@@ -692,6 +692,7 @@ typedef enum BackendState
STATE_IDLEINTRANSACTION,
STATE_FASTPATH,
STATE_IDLEINTRANSACTION_ABORTED,
+ STATE_WAITINGFORREPLICATION,
STATE_DISABLED
} BackendState;