2010-09-20 22:08:53 +02:00
|
|
|
<!-- doc/src/sgml/pgbuffercache.sgml -->
|
2007-12-10 06:32:51 +01:00
|
|
|
|
2011-05-08 04:29:20 +02:00
|
|
|
<sect1 id="pgbuffercache" xreflabel="pg_buffercache">
|
2007-11-11 00:30:46 +01:00
|
|
|
<title>pg_buffercache</title>
|
2007-12-10 06:32:51 +01:00
|
|
|
|
2007-12-02 23:33:20 +01:00
|
|
|
<indexterm zone="pgbuffercache">
|
2007-11-11 00:30:46 +01:00
|
|
|
<primary>pg_buffercache</primary>
|
|
|
|
</indexterm>
|
|
|
|
|
|
|
|
<para>
|
2007-12-10 06:32:51 +01:00
|
|
|
The <filename>pg_buffercache</filename> module provides a means for
|
|
|
|
examining what's happening in the shared buffer cache in real time.
|
2007-11-11 00:30:46 +01:00
|
|
|
</para>
|
2007-12-10 06:32:51 +01:00
|
|
|
|
2013-07-04 17:33:08 +02:00
|
|
|
<indexterm>
|
|
|
|
<primary>pg_buffercache_pages</primary>
|
|
|
|
</indexterm>
|
|
|
|
|
2007-11-11 00:30:46 +01:00
|
|
|
<para>
|
2007-12-10 06:32:51 +01:00
|
|
|
The module provides a C function <function>pg_buffercache_pages</function>
|
|
|
|
that returns a set of records, plus a view
|
|
|
|
<structname>pg_buffercache</structname> that wraps the function for
|
|
|
|
convenient use.
|
2007-11-11 00:30:46 +01:00
|
|
|
</para>
|
2007-12-10 06:32:51 +01:00
|
|
|
|
2007-11-11 00:30:46 +01:00
|
|
|
<para>
|
2020-02-28 17:29:58 +01:00
|
|
|
By default, use is restricted to superusers and members of the
|
|
|
|
<literal>pg_monitor</literal> role. Access may be granted to others
|
2017-03-30 20:18:53 +02:00
|
|
|
using <command>GRANT</command>.
|
2007-11-11 00:30:46 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<sect2>
|
2011-01-29 19:00:18 +01:00
|
|
|
<title>The <structname>pg_buffercache</structname> View</title>
|
2007-12-10 06:32:51 +01:00
|
|
|
|
2007-11-11 00:30:46 +01:00
|
|
|
<para>
|
2017-11-23 15:39:47 +01:00
|
|
|
The definitions of the columns exposed by the view are shown in <xref linkend="pgbuffercache-columns"/>.
|
2007-11-11 00:30:46 +01:00
|
|
|
</para>
|
2007-12-10 06:32:51 +01:00
|
|
|
|
2009-05-18 13:08:24 +02:00
|
|
|
<table id="pgbuffercache-columns">
|
2017-10-09 03:44:17 +02:00
|
|
|
<title><structname>pg_buffercache</structname> Columns</title>
|
2007-12-10 06:32:51 +01:00
|
|
|
|
|
|
|
<tgroup cols="4">
|
|
|
|
<thead>
|
|
|
|
<row>
|
|
|
|
<entry>Name</entry>
|
|
|
|
<entry>Type</entry>
|
|
|
|
<entry>References</entry>
|
|
|
|
<entry>Description</entry>
|
|
|
|
</row>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
|
|
|
|
<row>
|
|
|
|
<entry><structfield>bufferid</structfield></entry>
|
|
|
|
<entry><type>integer</type></entry>
|
|
|
|
<entry></entry>
|
2017-10-09 03:44:17 +02:00
|
|
|
<entry>ID, in the range 1..<varname>shared_buffers</varname></entry>
|
2007-12-10 06:32:51 +01:00
|
|
|
</row>
|
|
|
|
|
|
|
|
<row>
|
|
|
|
<entry><structfield>relfilenode</structfield></entry>
|
|
|
|
<entry><type>oid</type></entry>
|
|
|
|
<entry><literal>pg_class.relfilenode</literal></entry>
|
2010-02-07 21:48:13 +01:00
|
|
|
<entry>Filenode number of the relation</entry>
|
2007-12-10 06:32:51 +01:00
|
|
|
</row>
|
|
|
|
|
|
|
|
<row>
|
|
|
|
<entry><structfield>reltablespace</structfield></entry>
|
|
|
|
<entry><type>oid</type></entry>
|
|
|
|
<entry><literal>pg_tablespace.oid</literal></entry>
|
|
|
|
<entry>Tablespace OID of the relation</entry>
|
|
|
|
</row>
|
|
|
|
|
|
|
|
<row>
|
|
|
|
<entry><structfield>reldatabase</structfield></entry>
|
|
|
|
<entry><type>oid</type></entry>
|
|
|
|
<entry><literal>pg_database.oid</literal></entry>
|
|
|
|
<entry>Database OID of the relation</entry>
|
|
|
|
</row>
|
|
|
|
|
2008-08-14 14:56:41 +02:00
|
|
|
<row>
|
|
|
|
<entry><structfield>relforknumber</structfield></entry>
|
|
|
|
<entry><type>smallint</type></entry>
|
|
|
|
<entry></entry>
|
2013-07-03 20:19:44 +02:00
|
|
|
<entry>Fork number within the relation; see
|
2017-10-09 03:44:17 +02:00
|
|
|
<filename>include/common/relpath.h</filename></entry>
|
2008-08-14 14:56:41 +02:00
|
|
|
</row>
|
|
|
|
|
2013-11-28 04:33:45 +01:00
|
|
|
<row>
|
|
|
|
<entry><structfield>relblocknumber</structfield></entry>
|
|
|
|
<entry><type>bigint</type></entry>
|
|
|
|
<entry></entry>
|
|
|
|
<entry>Page number within the relation</entry>
|
|
|
|
</row>
|
|
|
|
|
2007-12-10 06:32:51 +01:00
|
|
|
<row>
|
|
|
|
<entry><structfield>isdirty</structfield></entry>
|
|
|
|
<entry><type>boolean</type></entry>
|
|
|
|
<entry></entry>
|
|
|
|
<entry>Is the page dirty?</entry>
|
|
|
|
</row>
|
|
|
|
|
|
|
|
<row>
|
|
|
|
<entry><structfield>usagecount</structfield></entry>
|
|
|
|
<entry><type>smallint</type></entry>
|
|
|
|
<entry></entry>
|
2013-07-03 20:19:44 +02:00
|
|
|
<entry>Clock-sweep access count</entry>
|
2007-12-10 06:32:51 +01:00
|
|
|
</row>
|
|
|
|
|
2014-08-22 00:28:37 +02:00
|
|
|
<row>
|
|
|
|
<entry><structfield>pinning_backends</structfield></entry>
|
|
|
|
<entry><type>integer</type></entry>
|
|
|
|
<entry></entry>
|
|
|
|
<entry>Number of backends pinning this buffer</entry>
|
|
|
|
</row>
|
|
|
|
|
2007-12-10 06:32:51 +01:00
|
|
|
</tbody>
|
|
|
|
</tgroup>
|
|
|
|
</table>
|
|
|
|
|
2007-11-11 00:30:46 +01:00
|
|
|
<para>
|
|
|
|
There is one row for each buffer in the shared cache. Unused buffers are
|
2017-10-09 03:44:17 +02:00
|
|
|
shown with all fields null except <structfield>bufferid</structfield>. Shared system
|
2007-12-10 06:32:51 +01:00
|
|
|
catalogs are shown as belonging to database zero.
|
2007-11-11 00:30:46 +01:00
|
|
|
</para>
|
2007-12-10 06:32:51 +01:00
|
|
|
|
2007-11-11 00:30:46 +01:00
|
|
|
<para>
|
2007-12-10 06:32:51 +01:00
|
|
|
Because the cache is shared by all the databases, there will normally be
|
|
|
|
pages from relations not belonging to the current database. This means
|
2017-10-09 03:44:17 +02:00
|
|
|
that there may not be matching join rows in <structname>pg_class</structname> for
|
2007-12-10 06:32:51 +01:00
|
|
|
some rows, or that there could even be incorrect joins. If you are
|
2017-10-09 03:44:17 +02:00
|
|
|
trying to join against <structname>pg_class</structname>, it's a good idea to
|
|
|
|
restrict the join to rows having <structfield>reldatabase</structfield> equal to
|
2007-12-10 06:32:51 +01:00
|
|
|
the current database's OID or zero.
|
2007-11-11 00:30:46 +01:00
|
|
|
</para>
|
2007-12-10 06:32:51 +01:00
|
|
|
|
2007-11-11 00:30:46 +01:00
|
|
|
<para>
|
2020-05-08 05:03:05 +02:00
|
|
|
Since buffer manager locks are not taken to copy the buffer state data that
|
|
|
|
the view will display, accessing <structname>pg_buffercache</structname> view
|
|
|
|
has less impact on normal buffer activity but it doesn't provide a consistent
|
|
|
|
set of results across all buffers. However, we ensure that the information of
|
|
|
|
each buffer is self-consistent.
|
2007-11-11 00:30:46 +01:00
|
|
|
</para>
|
|
|
|
</sect2>
|
|
|
|
|
|
|
|
<sect2>
|
2011-01-29 19:00:18 +01:00
|
|
|
<title>Sample Output</title>
|
2005-03-12 16:36:24 +01:00
|
|
|
|
2010-07-29 21:34:41 +02:00
|
|
|
<screen>
|
2020-03-31 23:16:33 +02:00
|
|
|
regression=# SELECT n.nspname, c.relname, count(*) AS buffers
|
2020-04-02 23:42:09 +02:00
|
|
|
FROM pg_buffercache b JOIN pg_class c
|
2010-07-29 21:34:41 +02:00
|
|
|
ON b.relfilenode = pg_relation_filenode(c.oid) AND
|
|
|
|
b.reldatabase IN (0, (SELECT oid FROM pg_database
|
|
|
|
WHERE datname = current_database()))
|
2020-03-31 23:16:33 +02:00
|
|
|
JOIN pg_namespace n ON n.oid = c.relnamespace
|
|
|
|
GROUP BY n.nspname, c.relname
|
|
|
|
ORDER BY 3 DESC
|
2010-07-29 21:34:41 +02:00
|
|
|
LIMIT 10;
|
|
|
|
|
2020-03-31 23:16:33 +02:00
|
|
|
nspname | relname | buffers
|
|
|
|
------------+------------------------+---------
|
|
|
|
public | delete_test_table | 593
|
|
|
|
public | delete_test_table_pkey | 494
|
|
|
|
pg_catalog | pg_attribute | 472
|
|
|
|
public | quad_poly_tbl | 353
|
|
|
|
public | tenk2 | 349
|
|
|
|
public | tenk1 | 349
|
|
|
|
public | gin_test_idx | 306
|
|
|
|
pg_catalog | pg_largeobject | 206
|
|
|
|
public | gin_test_tbl | 188
|
|
|
|
public | spgist_text_tbl | 182
|
2010-07-29 21:34:41 +02:00
|
|
|
(10 rows)
|
|
|
|
</screen>
|
2007-11-11 00:30:46 +01:00
|
|
|
</sect2>
|
|
|
|
|
|
|
|
<sect2>
|
|
|
|
<title>Authors</title>
|
2007-12-10 06:32:51 +01:00
|
|
|
|
|
|
|
<para>
|
|
|
|
Mark Kirkwood <email>markir@paradise.net.nz</email>
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Design suggestions: Neil Conway <email>neilc@samurai.com</email>
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Debugging advice: Tom Lane <email>tgl@sss.pgh.pa.us</email>
|
|
|
|
</para>
|
2007-11-11 00:30:46 +01:00
|
|
|
</sect2>
|
|
|
|
|
|
|
|
</sect1>
|