New view pg_stat_bgwriter, and the functions required to build it.
-<!-- $PostgreSQL: pgsql/doc/src/sgml/monitoring.sgml,v 1.47 2007/03/16 17:57:35 mha Exp $ -->
+<!-- $PostgreSQL: pgsql/doc/src/sgml/monitoring.sgml,v 1.48 2007/03/30 18:34:55 mha Exp $ -->
<chapter id="monitoring">
<title>Monitoring Database Activity</title>
</entry>
</row>
+ <row>
+ <entry><structname>pg_stat_bgwriter</></entry>
+ <entry>One row only, showing cluster-wide statistics from the
+ background writer: number of scheduled checkpoints, requested
+ checkpoints, buffers written by checkpoints, lru-scans and all-scans,
+ and the number of times the bgwriter aborted a round because it had
+ written too many buffers during lru-scans and all-scans.
+ </entry>
+ </row>
+
<row>
<entry><structname>pg_stat_database</></entry>
<entry>One row per database, showing database OID, database name,
</entry>
</row>
+ <row>
+ <entry><literal><function>pg_stat_get_bgwriter_timed_checkpoints</function>()</literal></entry>
+ <entry><type>bigint</type></entry>
+ <entry>
+ The number of times the bgwriter has started timed checkpoints
+ (because the <varname>checkpoint_timeout</varname> time has expired).
+ </entry>
+ </row>
+
+ <row>
+ <entry><literal><function>pg_stat_get_bgwriter_requested_checkpoints</function>()</literal></entry>
+ <entry><type>bigint</type></entry>
+ <entry>
+ The number of times the bgwriter has started checkpoints based on
+ requests from backends because the <varname>checkpoint_segments</varname>
+ has been exceeded or because the CHECKPOINT command has been issued.
+ </entry>
+ </row>
+
+ <row>
+ <entry><literal><function>pg_stat_get_bgwriter_buf_written_checkpoints</function>()</literal></entry>
+ <entry><type>bigint</type></entry>
+ <entry>
+ The number of buffers written by the bgwriter during checkpoints.
+ </entry>
+ </row>
+
+ <row>
+ <entry><literal><function>pg_stat_get_bgwriter_buf_written_lru</function>()</literal></entry>
+ <entry><type>bigint</type></entry>
+ <entry>
+ The number of buffers written by the bgwriter when performing a
+ LRU scan of the buffer cache.
+ </entry>
+ </row>
+
+ <row>
+ <entry><literal><function>pg_stat_get_bgwriter_buf_written_all</function>()</literal></entry>
+ <entry><type>bigint</type></entry>
+ <entry>
+ The number of buffers written by the bgwriter when performing a
+ scan of all the buffer cache.
+ </entry>
+ </row>
+
+ <row>
+ <entry><literal><function>pg_stat_get_bgwriter_maxwritten_lru</function>()</literal></entry>
+ <entry><type>bigint</type></entry>
+ <entry>
+ The number of times the bgwriter has stopped its LRU round because
+ it has written more buffers than specified in the
+ <varname>bgwriter_lru_maxpages</varname> parameter.
+ </entry>
+ </row>
+
+ <row>
+ <entry><literal><function>pg_stat_get_bgwriter_maxwritten_all</function>()</literal></entry>
+ <entry><type>bigint</type></entry>
+ <entry>
+ The number of times the bgwriter has stopped its all-buffer round
+ because it has written more buffers than specified in the
+ <varname>bgwriter_all_maxpages</varname> parameter.
+ </entry>
+ </row>
+
<row>
<entry><literal><function>pg_stat_clear_snapshot</function>()</literal></entry>
<entry><type>void</type></entry>
*
* Copyright (c) 1996-2007, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/backend/catalog/system_views.sql,v 1.36 2007/03/16 17:57:36 mha Exp $
+ * $PostgreSQL: pgsql/src/backend/catalog/system_views.sql,v 1.37 2007/03/30 18:34:55 mha Exp $
*/
CREATE VIEW pg_roles AS
pg_stat_get_db_tuples_updated(D.oid) AS tup_updated,
pg_stat_get_db_tuples_deleted(D.oid) AS tup_deleted
FROM pg_database D;
+
+CREATE VIEW pg_stat_bgwriter AS
+ SELECT
+ pg_stat_get_bgwriter_timed_checkpoints() AS checkpoints_timed,
+ pg_stat_get_bgwriter_requested_checkpoints() AS checkpoints_req,
+ pg_stat_get_bgwriter_buf_written_checkpoints() AS buffers_checkpoint,
+ pg_stat_get_bgwriter_buf_written_lru() AS buffers_lru,
+ pg_stat_get_bgwriter_buf_written_all() AS buffers_all,
+ pg_stat_get_bgwriter_maxwritten_lru() AS maxwritten_lru,
+ pg_stat_get_bgwriter_maxwritten_all() AS maxwritten_all;
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/postmaster/bgwriter.c,v 1.36 2007/01/17 16:25:01 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/postmaster/bgwriter.c,v 1.37 2007/03/30 18:34:55 mha Exp $
*
*-------------------------------------------------------------------------
*/
#include "access/xlog_internal.h"
#include "libpq/pqsignal.h"
#include "miscadmin.h"
+#include "pgstat.h"
#include "postmaster/bgwriter.h"
#include "storage/fd.h"
#include "storage/freespace.h"
static BgWriterShmemStruct *BgWriterShmem;
+/*
+ * BgWriter statistics counters.
+ * Stored directly in a stats message structure so it can be sent
+ * without needing to copy things around.
+ */
+PgStat_MsgBgWriter BgWriterStats;
+
/*
* GUC parameters
*/
ALLOCSET_DEFAULT_MAXSIZE);
MemoryContextSwitchTo(bgwriter_context);
+ /*
+ * Initialize statistics counters to zero
+ */
+ memset(&BgWriterStats, 0, sizeof(BgWriterStats));
+
/*
* If an exception is encountered, processing resumes here.
*
checkpoint_requested = false;
do_checkpoint = true;
force_checkpoint = true;
+ BgWriterStats.m_requested_checkpoints++;
}
if (shutdown_requested)
{
now = time(NULL);
elapsed_secs = now - last_checkpoint_time;
if (elapsed_secs >= CheckPointTimeout)
+ {
do_checkpoint = true;
+ if (!force_checkpoint)
+ BgWriterStats.m_timed_checkpoints++;
+ }
/*
* Do a checkpoint if requested, otherwise do one cycle of
}
}
+ /*
+ * Send off activity statistics to the stats collector
+ */
+ pgstat_send_bgwriter();
+
/*
* Nap for the configured time, or sleep for 10 seconds if there is no
* bgwriter activity configured.
*
* Copyright (c) 2001-2007, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.151 2007/03/28 22:17:12 alvherre Exp $
+ * $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.152 2007/03/30 18:34:55 mha Exp $
* ----------
*/
#include "postgres.h"
static PgBackendStatus *localBackendStatusTable = NULL;
static int localNumBackends = 0;
+/*
+ * BgWriter global statistics counters, from bgwriter.c
+ */
+extern PgStat_MsgBgWriter BgWriterStats;
+
+/*
+ * Cluster wide statistics, kept in the stats collector.
+ * Contains statistics that are not collected per database
+ * or per table.
+ */
+static PgStat_GlobalStats globalStats;
+
static volatile bool need_exit = false;
static volatile bool need_statwrite = false;
static void pgstat_recv_autovac(PgStat_MsgAutovacStart *msg, int len);
static void pgstat_recv_vacuum(PgStat_MsgVacuum *msg, int len);
static void pgstat_recv_analyze(PgStat_MsgAnalyze *msg, int len);
+static void pgstat_recv_bgwriter(PgStat_MsgBgWriter *msg, int len);
/* ------------------------------------------------------------
return localNumBackends;
}
+/*
+ * ---------
+ * pgstat_fetch_global() -
+ *
+ * Support function for the SQL-callable pgstat* functions. Returns
+ * a pointer to the global statistics struct.
+ * ---------
+ */
+PgStat_GlobalStats *
+pgstat_fetch_global(void)
+{
+ backend_read_statsfile();
+
+ return &globalStats;
+}
+
/* ------------------------------------------------------------
* Functions for management of the shared-memory PgBackendStatus array
#endif
}
+/* ----------
+ * pgstat_send_bgwriter() -
+ *
+ * Send bgwriter statistics to the collector
+ * ----------
+ */
+void
+pgstat_send_bgwriter(void)
+{
+ /*
+ * This function can be called even if nothing at all has happened.
+ * In this case, avoid sending a completely empty message to
+ * the stats collector.
+ */
+ if (BgWriterStats.m_timed_checkpoints == 0 &&
+ BgWriterStats.m_requested_checkpoints == 0 &&
+ BgWriterStats.m_buf_written_checkpoints == 0 &&
+ BgWriterStats.m_buf_written_lru == 0 &&
+ BgWriterStats.m_buf_written_all == 0 &&
+ BgWriterStats.m_maxwritten_lru == 0 &&
+ BgWriterStats.m_maxwritten_all == 0)
+ return;
+
+ /*
+ * Prepare and send the message
+ */
+ pgstat_setheader(&BgWriterStats.m_hdr, PGSTAT_MTYPE_BGWRITER);
+ pgstat_send(&BgWriterStats, sizeof(BgWriterStats));
+
+ /*
+ * Clear out the bgwriter statistics buffer, so it can be
+ * re-used.
+ */
+ memset(&BgWriterStats, 0, sizeof(BgWriterStats));
+}
+
/* ----------
* PgstatCollectorMain() -
pgstat_recv_analyze((PgStat_MsgAnalyze *) &msg, len);
break;
+ case PGSTAT_MTYPE_BGWRITER:
+ pgstat_recv_bgwriter((PgStat_MsgBgWriter *) &msg, len);
+ break;
+
default:
break;
}
format_id = PGSTAT_FILE_FORMAT_ID;
fwrite(&format_id, sizeof(format_id), 1, fpout);
+ /*
+ * Write global stats struct
+ */
+ fwrite(&globalStats, sizeof(globalStats), 1, fpout);
+
/*
* Walk through the database table.
*/
dbhash = hash_create("Databases hash", PGSTAT_DB_HASH_SIZE, &hash_ctl,
HASH_ELEM | HASH_FUNCTION | HASH_CONTEXT);
+ /*
+ * Clear out global statistics so they start from zero in case we can't
+ * load an existing statsfile.
+ */
+ memset(&globalStats, 0, sizeof(globalStats));
+
/*
* Try to open the status file. If it doesn't exist, the backends simply
* return zero for anything and the collector simply starts from scratch
goto done;
}
+ /*
+ * Read global stats struct
+ */
+ if (fread(&globalStats, 1, sizeof(globalStats), fpin) != sizeof(globalStats))
+ {
+ ereport(pgStatRunningInCollector ? LOG : WARNING,
+ (errmsg("corrupted pgstat.stat file")));
+ goto done;
+ }
+
/*
* We found an existing collector stats file. Read it and put all the
* hashtable entries into place.
tabentry->n_dead_tuples = msg->m_dead_tuples;
tabentry->last_anl_tuples = msg->m_live_tuples + msg->m_dead_tuples;
}
+
+
+/* ----------
+ * pgstat_recv_bgwriter() -
+ *
+ * Process a BGWRITER message.
+ * ----------
+ */
+static void
+pgstat_recv_bgwriter(PgStat_MsgBgWriter *msg, int len)
+{
+ globalStats.timed_checkpoints += msg->m_timed_checkpoints;
+ globalStats.requested_checkpoints += msg->m_requested_checkpoints;
+ globalStats.buf_written_checkpoints += msg->m_buf_written_checkpoints;
+ globalStats.buf_written_lru += msg->m_buf_written_lru;
+ globalStats.buf_written_all += msg->m_buf_written_all;
+ globalStats.maxwritten_lru += msg->m_maxwritten_lru;
+ globalStats.maxwritten_all += msg->m_maxwritten_all;
+}
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/storage/buffer/bufmgr.c,v 1.215 2007/02/01 19:10:27 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/storage/buffer/bufmgr.c,v 1.216 2007/03/30 18:34:55 mha Exp $
*
*-------------------------------------------------------------------------
*/
/* local state for LockBufferForCleanup */
static volatile BufferDesc *PinCountWaitBuf = NULL;
+/*
+ * Global statistics for the bgwriter. The contents of this variable
+ * only makes sense in the bgwriter process.
+ */
+extern PgStat_MsgBgWriter BgWriterStats;
+
static bool PinBuffer(volatile BufferDesc *buf);
static void PinBuffer_Locked(volatile BufferDesc *buf);
{
if (SyncOneBuffer(buf_id, false))
{
+ BgWriterStats.m_buf_written_checkpoints++;
+
/*
* If in bgwriter, absorb pending fsync requests after each
* WRITES_PER_ABSORB write operations, to prevent overflow of the
if (SyncOneBuffer(buf_id1, false))
{
if (++num_written >= bgwriter_all_maxpages)
+ {
+ BgWriterStats.m_maxwritten_all++;
break;
+ }
}
}
+ BgWriterStats.m_buf_written_all += num_written;
}
/*
if (SyncOneBuffer(buf_id2, true))
{
if (++num_written >= bgwriter_lru_maxpages)
+ {
+ BgWriterStats.m_maxwritten_lru++;
break;
+ }
}
if (++buf_id2 >= NBuffers)
buf_id2 = 0;
}
+ BgWriterStats.m_buf_written_lru += num_written;
}
}
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/pgstatfuncs.c,v 1.40 2007/03/16 17:57:36 mha Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/pgstatfuncs.c,v 1.41 2007/03/30 18:34:55 mha Exp $
*
*-------------------------------------------------------------------------
*/
extern Datum pg_stat_get_db_tuples_updated(PG_FUNCTION_ARGS);
extern Datum pg_stat_get_db_tuples_deleted(PG_FUNCTION_ARGS);
+extern Datum pg_stat_get_bgwriter_timed_checkpoints(PG_FUNCTION_ARGS);
+extern Datum pg_stat_get_bgwriter_requested_checkpoints(PG_FUNCTION_ARGS);
+extern Datum pg_stat_get_bgwriter_buf_written_checkpoints(PG_FUNCTION_ARGS);
+extern Datum pg_stat_get_bgwriter_buf_written_lru(PG_FUNCTION_ARGS);
+extern Datum pg_stat_get_bgwriter_buf_written_all(PG_FUNCTION_ARGS);
+extern Datum pg_stat_get_bgwriter_maxwritten_lru(PG_FUNCTION_ARGS);
+extern Datum pg_stat_get_bgwriter_maxwritten_all(PG_FUNCTION_ARGS);
+
extern Datum pg_stat_clear_snapshot(PG_FUNCTION_ARGS);
extern Datum pg_stat_reset(PG_FUNCTION_ARGS);
+/* Global bgwriter statistics, from bgwriter.c */
+extern PgStat_MsgBgWriter bgwriterStats;
Datum
pg_stat_get_numscans(PG_FUNCTION_ARGS)
PG_RETURN_INT64(result);
}
+Datum
+pg_stat_get_bgwriter_timed_checkpoints(PG_FUNCTION_ARGS)
+{
+ PG_RETURN_INT64(pgstat_fetch_global()->timed_checkpoints);
+}
+
+Datum
+pg_stat_get_bgwriter_requested_checkpoints(PG_FUNCTION_ARGS)
+{
+ PG_RETURN_INT64(pgstat_fetch_global()->requested_checkpoints);
+}
+
+Datum
+pg_stat_get_bgwriter_buf_written_checkpoints(PG_FUNCTION_ARGS)
+{
+ PG_RETURN_INT64(pgstat_fetch_global()->buf_written_checkpoints);
+}
+
+Datum
+pg_stat_get_bgwriter_buf_written_lru(PG_FUNCTION_ARGS)
+{
+ PG_RETURN_INT64(pgstat_fetch_global()->buf_written_lru);
+}
+
+Datum
+pg_stat_get_bgwriter_buf_written_all(PG_FUNCTION_ARGS)
+{
+ PG_RETURN_INT64(pgstat_fetch_global()->buf_written_all);
+}
+
+Datum
+pg_stat_get_bgwriter_maxwritten_lru(PG_FUNCTION_ARGS)
+{
+ PG_RETURN_INT64(pgstat_fetch_global()->maxwritten_lru);
+}
+
+Datum
+pg_stat_get_bgwriter_maxwritten_all(PG_FUNCTION_ARGS)
+{
+ PG_RETURN_INT64(pgstat_fetch_global()->maxwritten_all);
+}
+
/* Discard the active statistics snapshot */
Datum
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.396 2007/03/27 23:21:11 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.397 2007/03/30 18:34:56 mha Exp $
*
*-------------------------------------------------------------------------
*/
*/
/* yyyymmddN */
-#define CATALOG_VERSION_NO 200703271
+#define CATALOG_VERSION_NO 200703301
#endif
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.451 2007/03/27 23:21:11 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.452 2007/03/30 18:34:56 mha Exp $
*
* NOTES
* The script catalog/genbki.sh reads this file and generates .bki
DESCR("Statistics: Tuples updated in database");
DATA(insert OID = 2762 ( pg_stat_get_db_tuples_deleted PGNSP PGUID 12 1 0 f f t f s 1 20 "26" _null_ _null_ _null_ pg_stat_get_db_tuples_deleted - _null_ ));
DESCR("Statistics: Tuples deleted in database");
+DATA(insert OID = 2769 ( pg_stat_get_bgwriter_timed_checkpoints PGNSP PGUID 12 1 0 f f t f s 0 20 "" _null_ _null_ _null_ pg_stat_get_bgwriter_timed_checkpoints - _null_ ));
+DESCR("Statistics: Number of timed checkpoints started by the bgwriter");
+DATA(insert OID = 2770 ( pg_stat_get_bgwriter_requested_checkpoints PGNSP PGUID 12 1 0 f f t f s 0 20 "" _null_ _null_ _null_ pg_stat_get_bgwriter_requested_checkpoints - _null_ ));
+DESCR("Statistics: Number of backend requested checkpoints started by the bgwriter");
+DATA(insert OID = 2771 ( pg_stat_get_bgwriter_buf_written_checkpoints PGNSP PGUID 12 1 0 f f t f s 0 20 "" _null_ _null_ _null_ pg_stat_get_bgwriter_buf_written_checkpoints - _null_ ));
+DESCR("Statistics: Number of buffers written by the bgwriter during checkpoints");
+DATA(insert OID = 2772 ( pg_stat_get_bgwriter_buf_written_lru PGNSP PGUID 12 1 0 f f t f s 0 20 "" _null_ _null_ _null_ pg_stat_get_bgwriter_buf_written_lru - _null_ ));
+DESCR("Statistics: Number of buffers written by the bgwriter during LRU scans");
+DATA(insert OID = 2773 ( pg_stat_get_bgwriter_buf_written_all PGNSP PGUID 12 1 0 f f t f s 0 20 "" _null_ _null_ _null_ pg_stat_get_bgwriter_buf_written_all - _null_ ));
+DESCR("Statistics: Number of buffers written by the bgwriter during all-buffer scans");
+DATA(insert OID = 2774 ( pg_stat_get_bgwriter_maxwritten_lru PGNSP PGUID 12 1 0 f f t f s 0 20 "" _null_ _null_ _null_ pg_stat_get_bgwriter_maxwritten_lru - _null_ ));
+DESCR("Statistics: Number of times the bgwriter stopped processing when it had written too many buffers during LRU scans");
+DATA(insert OID = 2775 ( pg_stat_get_bgwriter_maxwritten_all PGNSP PGUID 12 1 0 f f t f s 0 20 "" _null_ _null_ _null_ pg_stat_get_bgwriter_maxwritten_all - _null_ ));
+DESCR("Statistics: Number of times the bgwriter stopped processing when it had written too many buffers during all-buffer scans");
DATA(insert OID = 2230 ( pg_stat_clear_snapshot PGNSP PGUID 12 1 0 f f f f v 0 2278 "" _null_ _null_ _null_ pg_stat_clear_snapshot - _null_ ));
DESCR("Statistics: Discard current transaction's statistics snapshot");
DATA(insert OID = 2274 ( pg_stat_reset PGNSP PGUID 12 1 0 f f f f v 0 2278 "" _null_ _null_ _null_ pg_stat_reset - _null_ ));
*
* Copyright (c) 2001-2007, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/include/pgstat.h,v 1.56 2007/03/22 19:53:31 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/pgstat.h,v 1.57 2007/03/30 18:34:55 mha Exp $
* ----------
*/
#ifndef PGSTAT_H
PGSTAT_MTYPE_RESETCOUNTER,
PGSTAT_MTYPE_AUTOVAC_START,
PGSTAT_MTYPE_VACUUM,
- PGSTAT_MTYPE_ANALYZE
+ PGSTAT_MTYPE_ANALYZE,
+ PGSTAT_MTYPE_BGWRITER
} StatMsgType;
/* ----------
} PgStat_MsgAnalyze;
+/* ----------
+ * PgStat_MsgBgWriter Sent by the bgwriter to update statistics.
+ * ----------
+ */
+typedef struct PgStat_MsgBgWriter
+{
+ PgStat_MsgHdr m_hdr;
+
+ PgStat_Counter m_timed_checkpoints;
+ PgStat_Counter m_requested_checkpoints;
+ PgStat_Counter m_buf_written_checkpoints;
+ PgStat_Counter m_buf_written_lru;
+ PgStat_Counter m_buf_written_all;
+ PgStat_Counter m_maxwritten_lru;
+ PgStat_Counter m_maxwritten_all;
+} PgStat_MsgBgWriter;
+
+
/* ----------
* PgStat_Msg Union over all possible messages.
* ----------
PgStat_MsgAutovacStart msg_autovacuum;
PgStat_MsgVacuum msg_vacuum;
PgStat_MsgAnalyze msg_analyze;
+ PgStat_MsgBgWriter msg_bgwriter;
} PgStat_Msg;
} PgStat_StatTabEntry;
+/*
+ * Global statistics kept in the stats collector
+ */
+typedef struct PgStat_GlobalStats
+{
+ PgStat_Counter timed_checkpoints;
+ PgStat_Counter requested_checkpoints;
+ PgStat_Counter buf_written_checkpoints;
+ PgStat_Counter buf_written_lru;
+ PgStat_Counter buf_written_all;
+ PgStat_Counter maxwritten_lru;
+ PgStat_Counter maxwritten_all;
+} PgStat_GlobalStats;
+
+
/* ----------
* Shared-memory data structures
* ----------
extern void pgstat_count_xact_commit(void);
extern void pgstat_count_xact_rollback(void);
+extern void pgstat_send_bgwriter(void);
/* ----------
* Support functions for the SQL-callable functions to
extern PgStat_StatTabEntry *pgstat_fetch_stat_tabentry(Oid relid);
extern PgBackendStatus *pgstat_fetch_stat_beentry(int beid);
extern int pgstat_fetch_stat_numbackends(void);
+extern PgStat_GlobalStats *pgstat_fetch_global(void);
#endif /* PGSTAT_H */
pg_stat_activity | SELECT d.oid AS datid, d.datname, pg_stat_get_backend_pid(s.backendid) AS procpid, pg_stat_get_backend_userid(s.backendid) AS usesysid, u.rolname AS usename, pg_stat_get_backend_activity(s.backendid) AS current_query, pg_stat_get_backend_waiting(s.backendid) AS waiting, pg_stat_get_backend_txn_start(s.backendid) AS txn_start, pg_stat_get_backend_activity_start(s.backendid) AS query_start, pg_stat_get_backend_start(s.backendid) AS backend_start, pg_stat_get_backend_client_addr(s.backendid) AS client_addr, pg_stat_get_backend_client_port(s.backendid) AS client_port FROM pg_database d, (SELECT pg_stat_get_backend_idset() AS backendid) s, pg_authid u WHERE ((pg_stat_get_backend_dbid(s.backendid) = d.oid) AND (pg_stat_get_backend_userid(s.backendid) = u.oid));
pg_stat_all_indexes | SELECT c.oid AS relid, i.oid AS indexrelid, n.nspname AS schemaname, c.relname, i.relname AS indexrelname, pg_stat_get_numscans(i.oid) AS idx_scan, pg_stat_get_tuples_returned(i.oid) AS idx_tup_read, pg_stat_get_tuples_fetched(i.oid) AS idx_tup_fetch FROM (((pg_class c JOIN pg_index x ON ((c.oid = x.indrelid))) JOIN pg_class i ON ((i.oid = x.indexrelid))) LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) WHERE (c.relkind = ANY (ARRAY['r'::"char", 't'::"char"]));
pg_stat_all_tables | SELECT c.oid AS relid, n.nspname AS schemaname, c.relname, pg_stat_get_numscans(c.oid) AS seq_scan, pg_stat_get_tuples_returned(c.oid) AS seq_tup_read, (sum(pg_stat_get_numscans(i.indexrelid)))::bigint AS idx_scan, ((sum(pg_stat_get_tuples_fetched(i.indexrelid)))::bigint + pg_stat_get_tuples_fetched(c.oid)) AS idx_tup_fetch, pg_stat_get_tuples_inserted(c.oid) AS n_tup_ins, pg_stat_get_tuples_updated(c.oid) AS n_tup_upd, pg_stat_get_tuples_deleted(c.oid) AS n_tup_del, pg_stat_get_live_tuples(c.oid) AS n_live_tup, pg_stat_get_dead_tuples(c.oid) AS n_dead_tup, pg_stat_get_last_vacuum_time(c.oid) AS last_vacuum, pg_stat_get_last_autovacuum_time(c.oid) AS last_autovacuum, pg_stat_get_last_analyze_time(c.oid) AS last_analyze, pg_stat_get_last_autoanalyze_time(c.oid) AS last_autoanalyze FROM ((pg_class c LEFT JOIN pg_index i ON ((c.oid = i.indrelid))) LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) WHERE (c.relkind = ANY (ARRAY['r'::"char", 't'::"char"])) GROUP BY c.oid, n.nspname, c.relname;
+ pg_stat_bgwriter | SELECT pg_stat_get_bgwriter_timed_checkpoints() AS checkpoints_timed, pg_stat_get_bgwriter_requested_checkpoints() AS checkpoints_req, pg_stat_get_bgwriter_buf_written_checkpoints() AS buffers_checkpoint, pg_stat_get_bgwriter_buf_written_lru() AS buffers_lru, pg_stat_get_bgwriter_buf_written_all() AS buffers_all, pg_stat_get_bgwriter_maxwritten_lru() AS maxwritten_lru, pg_stat_get_bgwriter_maxwritten_all() AS maxwritten_all;
pg_stat_database | SELECT d.oid AS datid, d.datname, pg_stat_get_db_numbackends(d.oid) AS numbackends, pg_stat_get_db_xact_commit(d.oid) AS xact_commit, pg_stat_get_db_xact_rollback(d.oid) AS xact_rollback, (pg_stat_get_db_blocks_fetched(d.oid) - pg_stat_get_db_blocks_hit(d.oid)) AS blks_read, pg_stat_get_db_blocks_hit(d.oid) AS blks_hit, pg_stat_get_db_tuples_returned(d.oid) AS tup_returned, pg_stat_get_db_tuples_fetched(d.oid) AS tup_fetched, pg_stat_get_db_tuples_inserted(d.oid) AS tup_inserted, pg_stat_get_db_tuples_updated(d.oid) AS tup_updated, pg_stat_get_db_tuples_deleted(d.oid) AS tup_deleted FROM pg_database d;
pg_stat_sys_indexes | SELECT pg_stat_all_indexes.relid, pg_stat_all_indexes.indexrelid, pg_stat_all_indexes.schemaname, pg_stat_all_indexes.relname, pg_stat_all_indexes.indexrelname, pg_stat_all_indexes.idx_scan, pg_stat_all_indexes.idx_tup_read, pg_stat_all_indexes.idx_tup_fetch FROM pg_stat_all_indexes WHERE (pg_stat_all_indexes.schemaname = ANY (ARRAY['pg_catalog'::"name", 'pg_toast'::"name", 'information_schema'::"name"]));
pg_stat_sys_tables | SELECT pg_stat_all_tables.relid, pg_stat_all_tables.schemaname, pg_stat_all_tables.relname, pg_stat_all_tables.seq_scan, pg_stat_all_tables.seq_tup_read, pg_stat_all_tables.idx_scan, pg_stat_all_tables.idx_tup_fetch, pg_stat_all_tables.n_tup_ins, pg_stat_all_tables.n_tup_upd, pg_stat_all_tables.n_tup_del, pg_stat_all_tables.n_live_tup, pg_stat_all_tables.n_dead_tup, pg_stat_all_tables.last_vacuum, pg_stat_all_tables.last_autovacuum, pg_stat_all_tables.last_analyze, pg_stat_all_tables.last_autoanalyze FROM pg_stat_all_tables WHERE (pg_stat_all_tables.schemaname = ANY (ARRAY['pg_catalog'::"name", 'pg_toast'::"name", 'information_schema'::"name"]));
shoelace_obsolete | SELECT shoelace.sl_name, shoelace.sl_avail, shoelace.sl_color, shoelace.sl_len, shoelace.sl_unit, shoelace.sl_len_cm FROM shoelace WHERE (NOT (EXISTS (SELECT shoe.shoename FROM shoe WHERE (shoe.slcolor = shoelace.sl_color))));
street | SELECT r."name", r.thepath, c.cname FROM ONLY road r, real_city c WHERE (c.outline ## r.thepath);
toyemp | SELECT emp."name", emp.age, emp."location", (12 * emp.salary) AS annualsal FROM emp;
-(48 rows)
+(49 rows)
SELECT tablename, rulename, definition FROM pg_rules
ORDER BY tablename, rulename;