- /*
- * When a backend process is consuming huge memory, logging all its memory
- * contexts might overrun available disk space. To prevent this, we limit
- * the depth of the hierarchy, as well as the number of child contexts to
- * log per parent to 100.
- *
- * As with MemoryContextStats(), we suppose that practical cases where the
- * dump gets long will typically be huge numbers of siblings under the
- * same parent context; while the additional debugging value from seeing
- * details about individual siblings beyond 100 will not be large.
- */
- MemoryContextStatsDetail(TopMemoryContext, 100, 100, false);
+ PG_TRY();
+ {
+ /*
+ * Use LOG_SERVER_ONLY to prevent this message from being sent to the
+ * connected client.
+ */
+ ereport(LOG_SERVER_ONLY,
+ (errhidestmt(true),
+ errhidecontext(true),
+ errmsg("logging memory contexts of PID %d", MyProcPid)));
+
+ /*
+ * When a backend process is consuming huge memory, logging all its
+ * memory contexts might overrun available disk space. To prevent
+ * this, we limit the depth of the hierarchy, as well as the number of
+ * child contexts to log per parent to 100.
+ *
+ * As with MemoryContextStats(), we suppose that practical cases where
+ * the dump gets long will typically be huge numbers of siblings under
+ * the same parent context; while the additional debugging value from
+ * seeing details about individual siblings beyond 100 will not be
+ * large.
+ */
+ MemoryContextStatsDetail(TopMemoryContext, 100, 100, false);
+ }
+ PG_FINALLY();
+ {
+ LogMemoryContextInProgress = false;
+ }
+ PG_END_TRY();