Index: doc/src/sgml/func.sgml
===================================================================
RCS file: /var/lib/cvs/pgsql-server/doc/src/sgml/func.sgml,v
retrieving revision 1.141
diff -c -r1.141 func.sgml
*** doc/src/sgml/func.sgml	19 Feb 2003 03:12:22 -0000	1.141
--- doc/src/sgml/func.sgml	19 Feb 2003 06:20:34 -0000
***************
*** 5309,5327 ****
      Some examples:
  <screen>
  SELECT CURRENT_TIME;
! <computeroutput>14:39:53.662522-05</computeroutput>
  
  SELECT CURRENT_DATE;
! <computeroutput>2001-12-23</computeroutput>
  
  SELECT CURRENT_TIMESTAMP;
! <computeroutput>2001-12-23 14:39:53.662522-05</computeroutput>
  
  SELECT CURRENT_TIMESTAMP(2);
! <computeroutput>2001-12-23 14:39:53.66-05</computeroutput>
  
  SELECT LOCALTIMESTAMP;
! <computeroutput>2001-12-23 14:39:53.662522</computeroutput>
  </screen>
     </para>
  
--- 5309,5327 ----
      Some examples:
  <screen>
  SELECT CURRENT_TIME;
! <lineannotation>Result:</> <computeroutput>14:39:53.662522-05</>
  
  SELECT CURRENT_DATE;
! <lineannotation>Result:</> <computeroutput>2001-12-23</>
  
  SELECT CURRENT_TIMESTAMP;
! <lineannotation>Result:</> <computeroutput>2001-12-23 14:39:53.662522-05</>
  
  SELECT CURRENT_TIMESTAMP(2);
! <lineannotation>Result:</> <computeroutput>2001-12-23 14:39:53.66-05</>
  
  SELECT LOCALTIMESTAMP;
! <lineannotation>Result:</> <computeroutput>2001-12-23 14:39:53.662522</>
  </screen>
     </para>
  
***************
*** 5332,5351 ****
     </para>
  
     <para>
!     There is also <function>timeofday()</function>, which for historical
!     reasons returns a text string rather than a <type>timestamp</type> value:
  <screen>
  SELECT timeofday();
!  Sat Feb 17 19:07:32.000126 2001 EST
  </screen>
     </para>
  
     <para>
      It is important to realize that
!     <function>CURRENT_TIMESTAMP</function> and related functions return
!     the start time of the current transaction; their values do not
!     change during the transaction. <function>timeofday()</function>
!     returns the wall clock time and does advance during transactions.
     </para>
  
     <note>
--- 5332,5356 ----
     </para>
  
     <para>
!     There is also <function>timeofday()</function>, which for
!     historical reasons returns a <type>text</type> string rather than
!     a <type>timestamp</type> value:
  <screen>
  SELECT timeofday();
! <lineannotation>Result:</> <computeroutput>Sat Feb 17 19:07:32.000126 2001 EST</>
  </screen>
     </para>
  
     <para>
      It is important to realize that
!     <function>CURRENT_TIMESTAMP</function> and related functions
!     return the start time of the current transaction; their values do
!     not change during the transaction. This is considered a feature:
!     the intent is to allow a single transaction to have a consistent
!     notion of the <quote>current</quote> time, so that multiple
!     modifications within the same transaction bear the same
!     timestamp. <function>timeofday()</function> returns the wall clock
!     time and does advance during transactions.
     </para>
  
     <note>
Index: doc/src/sgml/monitoring.sgml
===================================================================
RCS file: /var/lib/cvs/pgsql-server/doc/src/sgml/monitoring.sgml,v
retrieving revision 1.15
diff -c -r1.15 monitoring.sgml
*** doc/src/sgml/monitoring.sgml	11 Nov 2002 20:14:03 -0000	1.15
--- doc/src/sgml/monitoring.sgml	19 Feb 2003 20:32:54 -0000
***************
*** 146,157 ****
     <important>
      <para>
       Since the variables <varname>STATS_COMMAND_STRING</varname>,
!      <varname>STATS_BLOCK_LEVEL</varname>,
!      and <varname>STATS_ROW_LEVEL</varname>
!      default to <literal>false</>, no statistics are actually collected
!      in the default configuration.  You must turn one or more of them on
!      before you will get useful results from the statistical display
!      functions.
      </para>
     </important>
  
--- 146,158 ----
     <important>
      <para>
       Since the variables <varname>STATS_COMMAND_STRING</varname>,
!      <varname>STATS_BLOCK_LEVEL</varname>, and
!      <varname>STATS_ROW_LEVEL</varname> default to <literal>false</>,
!      very few statistics are collected in the default
!      configuration. Enabling one or more of these configuration
!      variables will significantly enhance the amount of useful data
!      produced by the statistics collector, at the expense of
!      additional run-time overhead.
      </para>
     </important>
  
***************
*** 205,215 ****
      <tbody>
       <row>
        <entry><structname>pg_stat_activity</></entry>
!       <entry>One row per server process, showing process <acronym>ID</>, database,
!       user, and current query.  The current query column is only available
!       to superusers; for others it reads as null.  (Note that because of
!       the collector's reporting delay, current query will only be up-to-date
!       for long-running queries.)</entry>
       </row>
  
       <row>
--- 206,220 ----
      <tbody>
       <row>
        <entry><structname>pg_stat_activity</></entry>
!       <entry>One row per server process, showing process
!       <acronym>ID</>, database, user, current query, and the time at
!       which the current query began execution. The columns that report
!       data on the current query are only available if the
!       <varname>STATS_COMMAND_STRING</varname> configuration option has
!       been enabled. Furthermore, these columns can only be accessed by
!       superusers; to other users, they always appear NULL. (Note that
!       because of the collector's reporting delay, current query will
!       only be up-to-date for long-running queries.)</entry>
       </row>
  
       <row>
***************
*** 333,342 ****
    </para>
  
    <para>
!    The <structname>pg_statio_</> views are primarily useful to determine
!    the effectiveness of the buffer cache.  When the number of actual disk
!    reads is much smaller than the number of buffer hits, then the cache
!    is satisfying most read requests without invoking a kernel call.
    </para>
  
    <para>
--- 338,357 ----
    </para>
  
    <para>
!    The <structname>pg_statio_</> views are primarily useful to
!    determine the effectiveness of the buffer cache.  When the number
!    of actual disk reads is much smaller than the number of buffer
!    hits, then the cache is satisfying most read requests without
!    invoking a kernel call. However, these statistics do not give the
!    entire story: due to the way in which <productname>PostgreSQL</>
!    handles disk I/O, data that is not in the
!    <productname>PostgreSQL</> buffer cache may still reside in the
!    kernel's I/O cache, and may therefore still be fetched without
!    requiring a physical read. Users interested in obtaining more
!    detailed information on <productname>PostgreSQL</> I/O behavior are
!    advised to use the <productname>PostgreSQL</> statistics collector
!    in combination with operating system utilities that allow insight
!    into the kernel's handling of I/O.
    </para>
  
    <para>
***************
*** 401,407 ****
        <entry><function>pg_stat_get_db_blocks_hit</function>(<type>oid</type>)</entry>
        <entry><type>bigint</type></entry>
        <entry>
!        Number of disk block requests found in cache for database
        </entry>
       </row>
  
--- 416,422 ----
        <entry><function>pg_stat_get_db_blocks_hit</function>(<type>oid</type>)</entry>
        <entry><type>bigint</type></entry>
        <entry>
!        Number of disk block fetch requests found in cache for database
        </entry>
       </row>
  
***************
*** 478,484 ****
        <entry><type>set of integer</type></entry>
        <entry>
         Set of currently active backend IDs (from 1 to N where N is the
!        number of active backends).  See usage example below.
        </entry>
       </row>
  
--- 493,499 ----
        <entry><type>set of integer</type></entry>
        <entry>
         Set of currently active backend IDs (from 1 to N where N is the
!        number of active backends).  See usage example below
        </entry>
       </row>
  
***************
*** 518,532 ****
        <entry><function>pg_stat_get_backend_activity</function>(<type>integer</type>)</entry>
        <entry><type>text</type></entry>
        <entry>
!        Current query of backend process (NULL if caller is not superuser)
        </entry>
       </row>
  
       <row>
        <entry><function>pg_stat_reset</function>()</entry>
        <entry><type>boolean</type></entry>
        <entry>
!        Reset all currently collected statistics.
        </entry>
       </row>
      </tbody>
--- 533,559 ----
        <entry><function>pg_stat_get_backend_activity</function>(<type>integer</type>)</entry>
        <entry><type>text</type></entry>
        <entry>
!        Current query of backend process (NULL if caller is not
!        superuser, or <varname>STATS_COMMAND_STRING</varname> is not enabled)
        </entry>
       </row>
  
       <row>
+       <entry><function>pg_stat_get_backend_activity_start</function>(<type>integer</type>)</entry>
+       <entry><type>text</type></entry>
+       <entry>
+        The time at which the specified backend's currently executing query was
+        initiated (NULL if caller is not superuser, or
+        <varname>STATS_COMMAND_STRING</varname> is not enabled)
+       </entry>
+      </row>
+ 
+ 
+      <row>
        <entry><function>pg_stat_reset</function>()</entry>
        <entry><type>boolean</type></entry>
        <entry>
!        Reset all currently collected statistics
        </entry>
       </row>
      </tbody>
***************
*** 535,541 ****
  
     <note>
      <para>
!      Blocks_fetched minus blocks_hit gives the number of kernel
       <function>read()</> calls issued for the table, index, or
       database; but the actual number of physical reads is usually
       lower due to kernel-level buffering.
--- 562,569 ----
  
     <note>
      <para>
!      <literal>blocks_fetched</literal> minus
!      <literal>blocks_hit</literal> gives the number of kernel
       <function>read()</> calls issued for the table, index, or
       database; but the actual number of physical reads is usually
       lower due to kernel-level buffering.
Index: doc/src/sgml/runtime.sgml
===================================================================
RCS file: /var/lib/cvs/pgsql-server/doc/src/sgml/runtime.sgml,v
retrieving revision 1.169
diff -c -r1.169 runtime.sgml
*** doc/src/sgml/runtime.sgml	19 Feb 2003 04:06:28 -0000	1.169
--- doc/src/sgml/runtime.sgml	19 Feb 2003 19:39:05 -0000
***************
*** 1182,1197 ****
  
       <varlistentry>
        <term><varname>STATS_COMMAND_STRING</varname> (<type>boolean</type>)</term>
        <term><varname>STATS_BLOCK_LEVEL</varname> (<type>boolean</type>)</term>
        <term><varname>STATS_ROW_LEVEL</varname> (<type>boolean</type>)</term>
        <listitem>
         <para>
!         Determines what information backends send to the statistics
!         collector process: current commands, block-level activity
!         statistics, or row-level activity statistics.  All default to
!         off.  Enabling statistics collection costs a small amount of
!         time per query, but is invaluable for debugging and
!         performance tuning.
         </para>
        </listitem>
       </varlistentry>
--- 1182,1212 ----
  
       <varlistentry>
        <term><varname>STATS_COMMAND_STRING</varname> (<type>boolean</type>)</term>
+       <listitem>
+        <para>
+         Enables the collection of statistics on the currently
+         executing command of each backend, along with the time at
+         which that query began execution. This option is off by
+         default. Note that even when enabled, this information is only
+         visible to the superuser, so it should not represent a
+         security risk. This data can be accessed via the
+         <structname>pg_stat_activity</structname> system view; refer
+         to the &cite-admin; for more information.
+        </para>
+       </listitem>
+      </varlistentry>
+ 
+      <varlistentry>
        <term><varname>STATS_BLOCK_LEVEL</varname> (<type>boolean</type>)</term>
        <term><varname>STATS_ROW_LEVEL</varname> (<type>boolean</type>)</term>
        <listitem>
         <para>
!         Enables the collection of block-level and row-level statistics
!         on database activity, respectively. These options are off by
!         default. This data can be accessed via the
!         <structname>pg_stat</structname> and
!         <structname>pg_statio</structname> family of system views;
!         refer to the &cite-admin; for more information.
         </para>
        </listitem>
       </varlistentry>
Index: src/backend/catalog/heap.c
===================================================================
RCS file: /var/lib/cvs/pgsql-server/src/backend/catalog/heap.c,v
retrieving revision 1.239
diff -c -r1.239 heap.c
*** src/backend/catalog/heap.c	8 Jan 2003 22:06:20 -0000	1.239
--- src/backend/catalog/heap.c	19 Feb 2003 18:59:20 -0000
***************
*** 961,967 ****
  	attStruct->attstattarget = 0;
  
  	/* Change the column name to something that isn't likely to conflict */
! 	snprintf(newattname, NAMEDATALEN, "........pg.dropped.%d........", attnum);
  	namestrcpy(&(attStruct->attname), newattname);
  
  	simple_heap_update(attr_rel, &tuple->t_self, tuple);
--- 961,968 ----
  	attStruct->attstattarget = 0;
  
  	/* Change the column name to something that isn't likely to conflict */
! 	snprintf(newattname, sizeof(newattname),
! 			 "........pg.dropped.%d........", attnum);
  	namestrcpy(&(attStruct->attname), newattname);
  
  	simple_heap_update(attr_rel, &tuple->t_self, tuple);
Index: src/backend/catalog/namespace.c
===================================================================
RCS file: /var/lib/cvs/pgsql-server/src/backend/catalog/namespace.c,v
retrieving revision 1.47
diff -c -r1.47 namespace.c
*** src/backend/catalog/namespace.c	9 Feb 2003 06:56:26 -0000	1.47
--- src/backend/catalog/namespace.c	19 Feb 2003 19:00:36 -0000
***************
*** 1598,1604 ****
  		elog(ERROR, "%s: not authorized to create temp tables",
  			 DatabaseName);
  
! 	snprintf(namespaceName, NAMEDATALEN, "pg_temp_%d", MyBackendId);
  
  	namespaceId = GetSysCacheOid(NAMESPACENAME,
  								 CStringGetDatum(namespaceName),
--- 1598,1604 ----
  		elog(ERROR, "%s: not authorized to create temp tables",
  			 DatabaseName);
  
! 	snprintf(namespaceName, sizeof(namespaceName), "pg_temp_%d", MyBackendId);
  
  	namespaceId = GetSysCacheOid(NAMESPACENAME,
  								 CStringGetDatum(namespaceName),
Index: src/backend/commands/cluster.c
===================================================================
RCS file: /var/lib/cvs/pgsql-server/src/backend/commands/cluster.c,v
retrieving revision 1.105
diff -c -r1.105 cluster.c
*** src/backend/commands/cluster.c	9 Feb 2003 06:56:26 -0000	1.105
--- src/backend/commands/cluster.c	19 Feb 2003 19:01:38 -0000
***************
*** 376,382 ****
  	 * namespace from the old, or we will have problems with the TEMP
  	 * status of temp tables.
  	 */
! 	snprintf(NewHeapName, NAMEDATALEN, "pg_temp_%u", tableOid);
  
  	OIDNewHeap = make_new_heap(tableOid, NewHeapName);
  	/*
--- 376,382 ----
  	 * namespace from the old, or we will have problems with the TEMP
  	 * status of temp tables.
  	 */
! 	snprintf(NewHeapName, sizeof(NewHeapName), "pg_temp_%u", tableOid);
  
  	OIDNewHeap = make_new_heap(tableOid, NewHeapName);
  	/*
***************
*** 596,602 ****
  		Relation	pg_index;
  
  		/* Create the new index under a temporary name */
! 		snprintf(newIndexName, NAMEDATALEN, "pg_temp_%u", attrs->indexOID);
  
  		/*
  		 * The new index will have primary and constraint status set to
--- 596,603 ----
  		Relation	pg_index;
  
  		/* Create the new index under a temporary name */
! 		snprintf(newIndexName, sizeof(newIndexName),
! 				 "pg_temp_%u", attrs->indexOID);
  
  		/*
  		 * The new index will have primary and constraint status set to
Index: src/backend/commands/sequence.c
===================================================================
RCS file: /var/lib/cvs/pgsql-server/src/backend/commands/sequence.c,v
retrieving revision 1.91
diff -c -r1.91 sequence.c
*** src/backend/commands/sequence.c	13 Feb 2003 05:25:24 -0000	1.91
--- src/backend/commands/sequence.c	19 Feb 2003 19:03:41 -0000
***************
*** 406,412 ****
  				{
  					char		buf[100];
  
! 					snprintf(buf, 100, INT64_FORMAT, maxv);
  					elog(ERROR, "%s.nextval: reached MAXVALUE (%s)",
  						 sequence->relname, buf);
  				}
--- 406,412 ----
  				{
  					char		buf[100];
  
! 					snprintf(buf, sizeof(buf), INT64_FORMAT, maxv);
  					elog(ERROR, "%s.nextval: reached MAXVALUE (%s)",
  						 sequence->relname, buf);
  				}
***************
*** 427,433 ****
  				{
  					char		buf[100];
  
! 					snprintf(buf, 100, INT64_FORMAT, minv);
  					elog(ERROR, "%s.nextval: reached MINVALUE (%s)",
  						 sequence->relname, buf);
  				}
--- 427,433 ----
  				{
  					char		buf[100];
  
! 					snprintf(buf, sizeof(buf), INT64_FORMAT, minv);
  					elog(ERROR, "%s.nextval: reached MINVALUE (%s)",
  						 sequence->relname, buf);
  				}
***************
*** 569,577 ****
  					bufm[100],
  					bufx[100];
  
! 		snprintf(bufv, 100, INT64_FORMAT, next);
! 		snprintf(bufm, 100, INT64_FORMAT, seq->min_value);
! 		snprintf(bufx, 100, INT64_FORMAT, seq->max_value);
  		elog(ERROR, "%s.setval: value %s is out of bounds (%s,%s)",
  			 sequence->relname, bufv, bufm, bufx);
  	}
--- 569,577 ----
  					bufm[100],
  					bufx[100];
  
! 		snprintf(bufv, sizeof(bufv), INT64_FORMAT, next);
! 		snprintf(bufm, sizeof(bufm), INT64_FORMAT, seq->min_value);
! 		snprintf(bufx, sizeof(bufx), INT64_FORMAT, seq->max_value);
  		elog(ERROR, "%s.setval: value %s is out of bounds (%s,%s)",
  			 sequence->relname, bufv, bufm, bufx);
  	}
***************
*** 861,868 ****
  		char		bufm[100],
  					bufx[100];
  
! 		snprintf(bufm, 100, INT64_FORMAT, new->min_value);
! 		snprintf(bufx, 100, INT64_FORMAT, new->max_value);
  		elog(ERROR, "DefineSequence: MINVALUE (%s) must be less than MAXVALUE (%s)",
  			 bufm, bufx);
  	}
--- 861,868 ----
  		char		bufm[100],
  					bufx[100];
  
! 		snprintf(bufm, sizeof(bufm), INT64_FORMAT, new->min_value);
! 		snprintf(bufx, sizeof(bufx), INT64_FORMAT, new->max_value);
  		elog(ERROR, "DefineSequence: MINVALUE (%s) must be less than MAXVALUE (%s)",
  			 bufm, bufx);
  	}
***************
*** 882,889 ****
  		char		bufs[100],
  					bufm[100];
  
! 		snprintf(bufs, 100, INT64_FORMAT, new->last_value);
! 		snprintf(bufm, 100, INT64_FORMAT, new->min_value);
  		elog(ERROR, "DefineSequence: START value (%s) can't be less than MINVALUE (%s)",
  			 bufs, bufm);
  	}
--- 882,889 ----
  		char		bufs[100],
  					bufm[100];
  
! 		snprintf(bufs, sizeof(bufs), INT64_FORMAT, new->last_value);
! 		snprintf(bufm, sizeof(bufm), INT64_FORMAT, new->min_value);
  		elog(ERROR, "DefineSequence: START value (%s) can't be less than MINVALUE (%s)",
  			 bufs, bufm);
  	}
***************
*** 892,899 ****
  		char		bufs[100],
  					bufm[100];
  
! 		snprintf(bufs, 100, INT64_FORMAT, new->last_value);
! 		snprintf(bufm, 100, INT64_FORMAT, new->max_value);
  		elog(ERROR, "DefineSequence: START value (%s) can't be greater than MAXVALUE (%s)",
  			 bufs, bufm);
  	}
--- 892,899 ----
  		char		bufs[100],
  					bufm[100];
  
! 		snprintf(bufs, sizeof(bufs), INT64_FORMAT, new->last_value);
! 		snprintf(bufm, sizeof(bufm), INT64_FORMAT, new->max_value);
  		elog(ERROR, "DefineSequence: START value (%s) can't be greater than MAXVALUE (%s)",
  			 bufs, bufm);
  	}
***************
*** 904,910 ****
  	{
  		char		buf[100];
  
! 		snprintf(buf, 100, INT64_FORMAT, new->cache_value);
  		elog(ERROR, "DefineSequence: CACHE (%s) can't be <= 0",
  			 buf);
  	}
--- 904,910 ----
  	{
  		char		buf[100];
  
! 		snprintf(buf, sizeof(buf), INT64_FORMAT, new->cache_value);
  		elog(ERROR, "DefineSequence: CACHE (%s) can't be <= 0",
  			 buf);
  	}
Index: src/backend/commands/tablecmds.c
===================================================================
RCS file: /var/lib/cvs/pgsql-server/src/backend/commands/tablecmds.c,v
retrieving revision 1.67
diff -c -r1.67 tablecmds.c
*** src/backend/commands/tablecmds.c	13 Feb 2003 05:19:59 -0000	1.67
--- src/backend/commands/tablecmds.c	19 Feb 2003 19:02:33 -0000
***************
*** 3875,3882 ****
  	/*
  	 * Create the toast table and its index
  	 */
! 	snprintf(toast_relname, NAMEDATALEN, "pg_toast_%u", relOid);
! 	snprintf(toast_idxname, NAMEDATALEN, "pg_toast_%u_index", relOid);
  
  	/* this is pretty painful...  need a tuple descriptor */
  	tupdesc = CreateTemplateTupleDesc(3, false);
--- 3875,3882 ----
  	/*
  	 * Create the toast table and its index
  	 */
! 	snprintf(toast_relname, sizeof(toast_relname), "pg_toast_%u", relOid);
! 	snprintf(toast_idxname, sizeof(toast_idxname), "pg_toast_%u_index", relOid);
  
  	/* this is pretty painful...  need a tuple descriptor */
  	tupdesc = CreateTemplateTupleDesc(3, false);
Index: src/backend/executor/execMain.c
===================================================================
RCS file: /var/lib/cvs/pgsql-server/src/backend/executor/execMain.c,v
retrieving revision 1.200
diff -c -r1.200 execMain.c
*** src/backend/executor/execMain.c	3 Feb 2003 15:07:06 -0000	1.200
--- src/backend/executor/execMain.c	19 Feb 2003 19:12:09 -0000
***************
*** 569,575 ****
  			erm = (execRowMark *) palloc(sizeof(execRowMark));
  			erm->relation = relation;
  			erm->rti = rti;
! 			snprintf(erm->resname, 32, "ctid%u", rti);
  			estate->es_rowMark = lappend(estate->es_rowMark, erm);
  		}
  	}
--- 569,575 ----
  			erm = (execRowMark *) palloc(sizeof(execRowMark));
  			erm->relation = relation;
  			erm->rti = rti;
! 			snprintf(erm->resname, sizeof(erm->resname), "ctid%u", rti);
  			estate->es_rowMark = lappend(estate->es_rowMark, erm);
  		}
  	}
Index: src/backend/libpq/hba.c
===================================================================
RCS file: /var/lib/cvs/pgsql-server/src/backend/libpq/hba.c,v
retrieving revision 1.93
diff -c -r1.93 hba.c
*** src/backend/libpq/hba.c	6 Jan 2003 03:18:26 -0000	1.93
--- src/backend/libpq/hba.c	19 Feb 2003 19:09:17 -0000
***************
*** 1162,1168 ****
  			char		ident_query[80];
  
  			/* The query we send to the Ident server */
! 			snprintf(ident_query, 80, "%d,%d\n",
  					 ntohs(remote_port), ntohs(local_port));
  			/* loop in case send is interrupted */
  			do
--- 1162,1168 ----
  			char		ident_query[80];
  
  			/* The query we send to the Ident server */
! 			snprintf(ident_query, sizeof(ident_query), "%d,%d\n",
  					 ntohs(remote_port), ntohs(local_port));
  			/* loop in case send is interrupted */
  			do
Index: src/backend/postmaster/pgstat.c
===================================================================
RCS file: /var/lib/cvs/pgsql-server/src/backend/postmaster/pgstat.c,v
retrieving revision 1.31
diff -c -r1.31 pgstat.c
*** src/backend/postmaster/pgstat.c	24 Oct 2002 23:19:13 -0000	1.31
--- src/backend/postmaster/pgstat.c	19 Feb 2003 19:19:58 -0000
***************
*** 1757,1762 ****
--- 1757,1764 ----
  	beentry->databaseid = msg->m_databaseid;
  	beentry->procpid = msg->m_procpid;
  	beentry->userid = msg->m_userid;
+ 	beentry->activity_start_sec = 0;
+ 	beentry->activity_start_usec = 0;
  	MemSet(beentry->activity, 0, PGSTAT_ACTIVITY_SIZE);
  
  	/*
***************
*** 2460,2465 ****
--- 2462,2469 ----
  static void
  pgstat_recv_activity(PgStat_MsgActivity *msg, int len)
  {
+ 	PgStat_StatBeEntry *entry;
+ 
  	/*
  	 * Here we check explicitly for 0 return, since we don't want to
  	 * mangle the activity of an active backend by a delayed packed from a
***************
*** 2468,2475 ****
  	if (pgstat_add_backend(&msg->m_hdr) != 0)
  		return;
  
! 	strncpy(pgStatBeTable[msg->m_hdr.m_backendid - 1].activity,
! 			msg->m_what, PGSTAT_ACTIVITY_SIZE);
  }
  
  
--- 2472,2483 ----
  	if (pgstat_add_backend(&msg->m_hdr) != 0)
  		return;
  
! 	entry = &(pgStatBeTable[msg->m_hdr.m_backendid - 1]);
! 
! 	strncpy(entry->activity, msg->m_what, PGSTAT_ACTIVITY_SIZE);
! 
! 	entry->activity_start_sec =
! 		GetCurrentAbsoluteTimeUsec(&entry->activity_start_usec);
  }
  
  
Index: src/backend/utils/adt/nabstime.c
===================================================================
RCS file: /var/lib/cvs/pgsql-server/src/backend/utils/adt/nabstime.c,v
retrieving revision 1.102
diff -c -r1.102 nabstime.c
*** src/backend/utils/adt/nabstime.c	12 Dec 2002 19:16:55 -0000	1.102
--- src/backend/utils/adt/nabstime.c	19 Feb 2003 06:20:38 -0000
***************
*** 87,95 ****
  			AbsoluteTime *i_end);
  
  
! /* GetCurrentAbsoluteTime()
!  * Get the current system time. Set timezone parameters if not specified elsewhere.
!  * Define HasCTZSet to allow clients to specify the default timezone.
   *
   * Returns the number of seconds since epoch (January 1 1970 GMT)
   */
--- 87,98 ----
  			AbsoluteTime *i_end);
  
  
! /* 
!  * GetCurrentAbsoluteTime()
!  *
!  * Get the current system time. Set timezone parameters if not specified
!  * elsewhere.  Define HasCTZSet to allow clients to specify the default
!  * timezone.
   *
   * Returns the number of seconds since epoch (January 1 1970 GMT)
   */
***************
*** 155,163 ****
  }	/* GetCurrentAbsoluteTime() */
  
  
! /* GetCurrentAbsoluteTimeUsec()
!  * Get the current system time. Set timezone parameters if not specified elsewhere.
!  * Define HasCTZSet to allow clients to specify the default timezone.
   *
   * Returns the number of seconds since epoch (January 1 1970 GMT)
   */
--- 158,169 ----
  }	/* GetCurrentAbsoluteTime() */
  
  
! /* 
!  * GetCurrentAbsoluteTimeUsec()
!  *
!  * Get the current system time. Set timezone parameters if not specified
!  * elsewhere.  Define HasCTZSet to allow clients to specify the default
!  * timezone.
   *
   * Returns the number of seconds since epoch (January 1 1970 GMT)
   */
Index: src/backend/utils/adt/pgstatfuncs.c
===================================================================
RCS file: /var/lib/cvs/pgsql-server/src/backend/utils/adt/pgstatfuncs.c,v
retrieving revision 1.9
diff -c -r1.9 pgstatfuncs.c
*** src/backend/utils/adt/pgstatfuncs.c	4 Dec 2002 05:18:34 -0000	1.9
--- src/backend/utils/adt/pgstatfuncs.c	19 Feb 2003 19:24:21 -0000
***************
*** 25,30 ****
--- 25,31 ----
  extern Datum pg_stat_get_backend_dbid(PG_FUNCTION_ARGS);
  extern Datum pg_stat_get_backend_userid(PG_FUNCTION_ARGS);
  extern Datum pg_stat_get_backend_activity(PG_FUNCTION_ARGS);
+ extern Datum pg_stat_get_backend_activity_start(PG_FUNCTION_ARGS);
  
  extern Datum pg_stat_get_db_numbackends(PG_FUNCTION_ARGS);
  extern Datum pg_stat_get_db_xact_commit(PG_FUNCTION_ARGS);
***************
*** 221,227 ****
  
  /*
   * Built-in function for resetting the counters
-  *
   */
  Datum
  pg_stat_reset(PG_FUNCTION_ARGS)
--- 222,227 ----
***************
*** 298,303 ****
--- 298,347 ----
  	memcpy(VARDATA(result), beentry->activity, len);
  
  	PG_RETURN_TEXT_P(result);
+ }
+ 
+ 
+ Datum
+ pg_stat_get_backend_activity_start(PG_FUNCTION_ARGS)
+ {
+ 	PgStat_StatBeEntry	*beentry;
+ 	int32				 beid;
+ 	AbsoluteTime		 sec;
+ 	int					 usec;
+ 	Timestamp			 result;
+ 
+ 	beid = PG_GETARG_INT32(0);
+ 
+ 	if (!superuser())
+ 		PG_RETURN_NULL();
+ 
+ 	if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
+ 		PG_RETURN_NULL();
+ 
+ 	sec = beentry->activity_start_sec;
+ 	usec = beentry->activity_start_usec;
+ 
+ 	/*
+ 	 * No time recorded for start of current query -- this is the case
+ 	 * if the user hasn't enabled query-level stats collection.
+ 	 */
+ 	if (sec == 0 && usec == 0)
+ 		PG_RETURN_NULL();
+ 
+ 	/*
+ 	 * This method of converting "Unix time" (sec/usec since epoch) to a
+ 	 * PostgreSQL timestamp is an ugly hack -- if you fix it, be sure to
+ 	 * fix the similar hackery in timestamp.c
+ 	 */
+ #ifdef HAVE_INT64_TIMESTAMP
+ 	result = (((sec - ((date2j(2000, 1, 1) - date2j(1970, 1, 1)) * 86400))
+ 			   * INT64CONST(1000000)) + usec);
+ #else
+ 	result = (sec + (usec * 1.0e-6) - ((date2j(2000, 1, 1) -
+ 										date2j(1970, 1, 1)) * 86400));
+ #endif
+ 
+ 	PG_RETURN_TIMESTAMP(result);
  }
  
  
Index: src/backend/utils/error/elog.c
===================================================================
RCS file: /var/lib/cvs/pgsql-server/src/backend/utils/error/elog.c,v
retrieving revision 1.106
diff -c -r1.106 elog.c
*** src/backend/utils/error/elog.c	7 Jan 2003 22:23:17 -0000	1.106
--- src/backend/utils/error/elog.c	19 Feb 2003 19:10:33 -0000
***************
*** 215,221 ****
  		 * Prints the failure line of the COPY.  Wow, what a hack!	bjm
  		 * Translator:	Error message will be truncated at 31 characters.
  		 */
! 		snprintf(copylineno_buf, 32, gettext("copy: line %d, "), copy_lineno);
  		space_needed += strlen(copylineno_buf);
  	}
  
--- 215,222 ----
  		 * Prints the failure line of the COPY.  Wow, what a hack!	bjm
  		 * Translator:	Error message will be truncated at 31 characters.
  		 */
! 		snprintf(copylineno_buf, sizeof(copylineno_buf),
! 				 gettext("copy: line %d, "), copy_lineno);
  		space_needed += strlen(copylineno_buf);
  	}
  
***************
*** 787,794 ****
  		 * translator: This string will be truncated at 47 characters
  		 * expanded.
  		 */
! 		snprintf(errorstr_buf, 48, gettext("operating system error %d"),
! 				 errnum);
  		str = errorstr_buf;
  	}
  
--- 788,795 ----
  		 * translator: This string will be truncated at 47 characters
  		 * expanded.
  		 */
! 		snprintf(errorstr_buf, sizeof(errorstr_buf),
! 				 gettext("operating system error %d"), errnum);
  		str = errorstr_buf;
  	}
  
Index: src/bin/initdb/initdb.sh
===================================================================
RCS file: /var/lib/cvs/pgsql-server/src/bin/initdb/initdb.sh,v
retrieving revision 1.183
diff -c -r1.183 initdb.sh
*** src/bin/initdb/initdb.sh	19 Feb 2003 04:02:54 -0000	1.183
--- src/bin/initdb/initdb.sh	19 Feb 2003 18:49:31 -0000
***************
*** 953,959 ****
              pg_stat_get_backend_pid(S.backendid) AS procpid, \
              pg_stat_get_backend_userid(S.backendid) AS usesysid, \
              U.usename AS usename, \
!             pg_stat_get_backend_activity(S.backendid) AS current_query \
      FROM pg_database D, \
              (SELECT pg_stat_get_backend_idset() AS backendid) AS S, \
              pg_shadow U \
--- 953,960 ----
              pg_stat_get_backend_pid(S.backendid) AS procpid, \
              pg_stat_get_backend_userid(S.backendid) AS usesysid, \
              U.usename AS usename, \
!             pg_stat_get_backend_activity(S.backendid) AS current_query, \
! 			pg_stat_get_backend_activity_start(S.backendid) AS query_start \
      FROM pg_database D, \
              (SELECT pg_stat_get_backend_idset() AS backendid) AS S, \
              pg_shadow U \
Index: src/bin/pg_dump/pg_backup_tar.c
===================================================================
RCS file: /var/lib/cvs/pgsql-server/src/bin/pg_dump/pg_backup_tar.c,v
retrieving revision 1.34
diff -c -r1.34 pg_backup_tar.c
*** src/bin/pg_dump/pg_backup_tar.c	1 Feb 2003 19:29:16 -0000	1.34
--- src/bin/pg_dump/pg_backup_tar.c	19 Feb 2003 19:06:18 -0000
***************
*** 1044,1051 ****
  		char		buf1[100],
  					buf2[100];
  
! 		snprintf(buf1, 100, INT64_FORMAT, (int64) len);
! 		snprintf(buf2, 100, INT64_FORMAT, (int64) th->pos);
  		die_horribly(AH, modulename, "actual file length (%s) does not match expected (%s)\n",
  					 buf1, buf2);
  	}
--- 1044,1051 ----
  		char		buf1[100],
  					buf2[100];
  
! 		snprintf(buf1, sizeof(buf1), INT64_FORMAT, (int64) len);
! 		snprintf(buf2, sizeof(buf2), INT64_FORMAT, (int64) th->pos);
  		die_horribly(AH, modulename, "actual file length (%s) does not match expected (%s)\n",
  					 buf1, buf2);
  	}
***************
*** 1081,1088 ****
  		char		buf1[100],
  					buf2[100];
  
! 		snprintf(buf1, 100, INT64_FORMAT, (int64) ctx->tarFHpos);
! 		snprintf(buf2, 100, INT64_FORMAT, (int64) ctx->tarNextMember);
  		ahlog(AH, 4, "moving from position %s to next member at file position %s\n",
  			  buf1, buf2);
  
--- 1081,1088 ----
  		char		buf1[100],
  					buf2[100];
  
! 		snprintf(buf1, sizeof(buf1), INT64_FORMAT, (int64) ctx->tarFHpos);
! 		snprintf(buf2, sizeof(buf2), INT64_FORMAT, (int64) ctx->tarNextMember);
  		ahlog(AH, 4, "moving from position %s to next member at file position %s\n",
  			  buf1, buf2);
  
***************
*** 1093,1099 ****
  	{
  		char		buf[100];
  
! 		snprintf(buf, 100, INT64_FORMAT, (int64) ctx->tarFHpos);
  		ahlog(AH, 4, "now at file position %s\n", buf);
  	}
  
--- 1093,1099 ----
  	{
  		char		buf[100];
  
! 		snprintf(buf, sizeof(buf), INT64_FORMAT, (int64) ctx->tarFHpos);
  		ahlog(AH, 4, "now at file position %s\n", buf);
  	}
  
***************
*** 1163,1170 ****
  			char		buf1[100],
  						buf2[100];
  
! 			snprintf(buf1, 100, INT64_FORMAT, (int64) ftello(ctx->tarFH));
! 			snprintf(buf2, 100, INT64_FORMAT, (int64) ftello(ctx->tarFHpos));
  			die_horribly(AH, modulename,
  						 "mismatch in actual vs. predicted file position (%s vs. %s)\n",
  						 buf1, buf2);
--- 1163,1170 ----
  			char		buf1[100],
  						buf2[100];
  
! 			snprintf(buf1, sizeof(buf1), INT64_FORMAT, (int64) ftello(ctx->tarFH));
! 			snprintf(buf2, sizeof(buf2), INT64_FORMAT, (int64) ftello(ctx->tarFHpos));
  			die_horribly(AH, modulename,
  						 "mismatch in actual vs. predicted file position (%s vs. %s)\n",
  						 buf1, buf2);
***************
*** 1215,1221 ****
  	{
  		char		buf[100];
  
! 		snprintf(buf, 100, INT64_FORMAT, (int64) hPos);
  		ahlog(AH, 3, "TOC Entry %s at %s (length %lu, checksum %d)\n",
  			  tag, buf, (unsigned long) len, sum);
  	}
--- 1215,1221 ----
  	{
  		char		buf[100];
  
! 		snprintf(buf, sizeof(buf), INT64_FORMAT, (int64) hPos);
  		ahlog(AH, 3, "TOC Entry %s at %s (length %lu, checksum %d)\n",
  			  tag, buf, (unsigned long) len, sum);
  	}
***************
*** 1224,1230 ****
  	{
  		char		buf[100];
  
! 		snprintf(buf, 100, INT64_FORMAT, (int64) ftello(ctx->tarFH));
  		die_horribly(AH, modulename,
  					 "corrupt tar header found in %s "
  					 "(expected %d, computed %d) file position %s\n",
--- 1224,1230 ----
  	{
  		char		buf[100];
  
! 		snprintf(buf, sizeof(buf), INT64_FORMAT, (int64) ftello(ctx->tarFH));
  		die_horribly(AH, modulename,
  					 "corrupt tar header found in %s "
  					 "(expected %d, computed %d) file position %s\n",
Index: src/include/pgstat.h
===================================================================
RCS file: /var/lib/cvs/pgsql-server/src/include/pgstat.h,v
retrieving revision 1.12
diff -c -r1.12 pgstat.h
*** src/include/pgstat.h	9 Jan 2003 18:00:24 -0000	1.12
--- src/include/pgstat.h	19 Feb 2003 19:23:22 -0000
***************
*** 11,16 ****
--- 11,18 ----
  #ifndef PGSTAT_H
  #define PGSTAT_H
  
+ #include "utils/nabstime.h"
+ 
  /* ----------
   * Paths for the statistics files. The %s is replaced with the
   * installations $PGDATA.
***************
*** 111,116 ****
--- 113,120 ----
  	Oid			userid;
  	int			procpid;
  	char		activity[PGSTAT_ACTIVITY_SIZE];
+ 	AbsoluteTime activity_start_sec;
+ 	int			activity_start_usec;
  } PgStat_StatBeEntry;
  
  
Index: src/include/catalog/catversion.h
===================================================================
RCS file: /var/lib/cvs/pgsql-server/src/include/catalog/catversion.h,v
retrieving revision 1.177
diff -c -r1.177 catversion.h
*** src/include/catalog/catversion.h	16 Feb 2003 02:30:39 -0000	1.177
--- src/include/catalog/catversion.h	19 Feb 2003 06:20:34 -0000
***************
*** 53,58 ****
   */
  
  /*							yyyymmddN */
! #define CATALOG_VERSION_NO	200302151
  
  #endif
--- 53,58 ----
   */
  
  /*							yyyymmddN */
! #define CATALOG_VERSION_NO	200302181
  
  #endif
Index: src/include/catalog/pg_proc.h
===================================================================
RCS file: /var/lib/cvs/pgsql-server/src/include/catalog/pg_proc.h,v
retrieving revision 1.283
diff -c -r1.283 pg_proc.h
*** src/include/catalog/pg_proc.h	13 Feb 2003 05:24:02 -0000	1.283
--- src/include/catalog/pg_proc.h	19 Feb 2003 18:49:18 -0000
***************
*** 2739,2744 ****
--- 2739,2746 ----
  DESCR("Statistics: User ID of backend");
  DATA(insert OID = 1940 (  pg_stat_get_backend_activity	PGNSP PGUID 12 f f t f s 1 25 "23"	pg_stat_get_backend_activity - _null_ ));
  DESCR("Statistics: Current query of backend");
+ DATA(insert OID = 2094 (  pg_stat_get_backend_activity_start PGNSP PGUID 12 f f t f s 1 1114 "23"  pg_stat_get_backend_activity_start - _null_));
+ DESCR("Statistics: Start time for current query of backend");
  DATA(insert OID = 1941 (  pg_stat_get_db_numbackends	PGNSP PGUID 12 f f t f s 1 23 "26"	pg_stat_get_db_numbackends - _null_ ));
  DESCR("Statistics: Number of backends in database");
  DATA(insert OID = 1942 (  pg_stat_get_db_xact_commit	PGNSP PGUID 12 f f t f s 1 20 "26"	pg_stat_get_db_xact_commit - _null_ ));
***************
*** 2748,2754 ****
  DATA(insert OID = 1944 (  pg_stat_get_db_blocks_fetched PGNSP PGUID 12 f f t f s 1 20 "26"	pg_stat_get_db_blocks_fetched - _null_ ));
  DESCR("Statistics: Blocks fetched for database");
  DATA(insert OID = 1945 (  pg_stat_get_db_blocks_hit		PGNSP PGUID 12 f f t f s 1 20 "26"	pg_stat_get_db_blocks_hit - _null_ ));
! DESCR("Statistics: Block found in cache for database");
  
  DATA(insert OID = 1946 (  encode						PGNSP PGUID 12 f f t f i 2 25 "17 25"  binary_encode - _null_ ));
  DESCR("Convert bytea value into some ascii-only text string");
--- 2750,2756 ----
  DATA(insert OID = 1944 (  pg_stat_get_db_blocks_fetched PGNSP PGUID 12 f f t f s 1 20 "26"	pg_stat_get_db_blocks_fetched - _null_ ));
  DESCR("Statistics: Blocks fetched for database");
  DATA(insert OID = 1945 (  pg_stat_get_db_blocks_hit		PGNSP PGUID 12 f f t f s 1 20 "26"	pg_stat_get_db_blocks_hit - _null_ ));
! DESCR("Statistics: Blocks found in cache for database");
  
  DATA(insert OID = 1946 (  encode						PGNSP PGUID 12 f f t f i 2 25 "17 25"  binary_encode - _null_ ));
  DESCR("Convert bytea value into some ascii-only text string");
Index: src/test/regress/expected/rules.out
===================================================================
RCS file: /var/lib/cvs/pgsql-server/src/test/regress/expected/rules.out,v
retrieving revision 1.71
diff -c -r1.71 rules.out
*** src/test/regress/expected/rules.out	19 Feb 2003 04:02:54 -0000	1.71
--- src/test/regress/expected/rules.out	19 Feb 2003 20:35:41 -0000
***************
*** 1274,1280 ****
   pg_locks                 | SELECT l.object, l."class", l."database", l."transaction", l.pid, l."mode", l.granted FROM pg_lock_status() l(object oid, "class" oid, "database" oid, "transaction" xid, pid integer, "mode" text, granted boolean);
   pg_rules                 | SELECT n.nspname AS schemaname, c.relname AS tablename, r.rulename, pg_get_ruledef(r.oid) AS definition FROM ((pg_rewrite r JOIN pg_class c ON ((c.oid = r.ev_class))) LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) WHERE (r.rulename <> '_RETURN'::name);
   pg_settings              | SELECT a.name, a.setting FROM pg_show_all_settings() a(name text, setting text);
!  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.usename, pg_stat_get_backend_activity(s.backendid) AS current_query FROM pg_database d, (SELECT pg_stat_get_backend_idset() AS backendid) s, pg_shadow u WHERE ((pg_stat_get_backend_dbid(s.backendid) = d.oid) AND (pg_stat_get_backend_userid(s.backendid) = u.usesysid));
   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 = 'r'::"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)) AS idx_scan, sum(pg_stat_get_tuples_fetched(i.indexrelid)) 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 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 = 'r'::"char") GROUP BY c.oid, n.nspname, c.relname;
   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 FROM pg_database d;
--- 1274,1280 ----
   pg_locks                 | SELECT l.object, l."class", l."database", l."transaction", l.pid, l."mode", l.granted FROM pg_lock_status() l(object oid, "class" oid, "database" oid, "transaction" xid, pid integer, "mode" text, granted boolean);
   pg_rules                 | SELECT n.nspname AS schemaname, c.relname AS tablename, r.rulename, pg_get_ruledef(r.oid) AS definition FROM ((pg_rewrite r JOIN pg_class c ON ((c.oid = r.ev_class))) LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) WHERE (r.rulename <> '_RETURN'::name);
   pg_settings              | SELECT a.name, a.setting FROM pg_show_all_settings() a(name text, setting text);
!  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.usename, pg_stat_get_backend_activity(s.backendid) AS current_query, pg_stat_get_backend_activity_start(s.backendid) AS query_start FROM pg_database d, (SELECT pg_stat_get_backend_idset() AS backendid) s, pg_shadow u WHERE ((pg_stat_get_backend_dbid(s.backendid) = d.oid) AND (pg_stat_get_backend_userid(s.backendid) = u.usesysid));
   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 = 'r'::"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)) AS idx_scan, sum(pg_stat_get_tuples_fetched(i.indexrelid)) 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 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 = 'r'::"char") GROUP BY c.oid, n.nspname, c.relname;
   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 FROM pg_database d;
