1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-27 12:41:57 +03:00

Add pg_buffercache_evict() function for testing.

When testing buffer pool logic, it is useful to be able to evict
arbitrary blocks.  This function can be used in SQL queries over the
pg_buffercache view to set up a wide range of buffer pool states.  Of
course, buffer mappings might change concurrently so you might evict a
block other than the one you had in mind, and another session might
bring it back in at any time.  That's OK for the intended purpose of
setting up developer testing scenarios, and more complicated interlocking
schemes to give stronger guararantees about that would likely be less
flexible for actual testing work anyway.  Superuser-only.

Author: Palak Chaturvedi <chaturvedipalak1911@gmail.com>
Author: Thomas Munro <thomas.munro@gmail.com> (docs, small tweaks)
Reviewed-by: Nitin Jadhav <nitinjadhavpostgres@gmail.com>
Reviewed-by: Andres Freund <andres@anarazel.de>
Reviewed-by: Cary Huang <cary.huang@highgo.ca>
Reviewed-by: Cédric Villemain <cedric.villemain+pgsql@abcsql.com>
Reviewed-by: Jim Nasby <jim.nasby@gmail.com>
Reviewed-by: Maxim Orlov <orlovmg@gmail.com>
Reviewed-by: Thomas Munro <thomas.munro@gmail.com>
Reviewed-by: Melanie Plageman <melanieplageman@gmail.com>
Discussion: https://postgr.es/m/CALfch19pW48ZwWzUoRSpsaV9hqt0UPyaBPC4bOZ4W+c7FF566A@mail.gmail.com
This commit is contained in:
Thomas Munro
2024-04-07 09:13:17 +12:00
parent 0ea51bac38
commit 13453eedd3
8 changed files with 127 additions and 8 deletions

View File

@ -11,6 +11,8 @@
<para>
The <filename>pg_buffercache</filename> module provides a means for
examining what's happening in the shared buffer cache in real time.
It also offers a low-level way to evict data from it, for testing
purposes.
</para>
<indexterm>
@ -21,11 +23,16 @@
<primary>pg_buffercache_summary</primary>
</indexterm>
<indexterm>
<primary>pg_buffercache_evict</primary>
</indexterm>
<para>
This module provides the <function>pg_buffercache_pages()</function>
function (wrapped in the <structname>pg_buffercache</structname> view),
the <function>pg_buffercache_summary()</function> function, and the
<function>pg_buffercache_usage_counts()</function> function.
the <function>pg_buffercache_summary()</function> function, the
<function>pg_buffercache_usage_counts()</function> function and
the <function>pg_buffercache_evict()</function> function.
</para>
<para>
@ -47,9 +54,15 @@
</para>
<para>
By default, use is restricted to superusers and roles with privileges of the
<literal>pg_monitor</literal> role. Access may be granted to others
using <command>GRANT</command>.
By default, use of the above functions is restricted to superusers and roles
with privileges of the <literal>pg_monitor</literal> role. Access may be
granted to others using <command>GRANT</command>.
</para>
<para>
The <function>pg_buffercache_evict()</function> function allows a block to
be evicted from the buffer pool given a buffer identifier. Use of this
function is restricted to superusers only.
</para>
<sect2 id="pgbuffercache-pg-buffercache">
@ -351,7 +364,21 @@
</para>
</sect2>
<sect2 id="pgbuffercache-sample-output">
<sect2 id="pgbuffercache-pg-buffercache-evict">
<title>The <structname>pg_buffercache_evict</structname> Function</title>
<para>
The <function>pg_buffercache_evict()</function> function takes a buffer
identifier, as shown in the <structfield>bufferid</structfield> column of
the <structname>pg_buffercache</structname> view. It returns true on success,
and false if the buffer wasn't valid, if it couldn't be evicted because it
was pinned, or if it became dirty again after an attempt to write it out.
The result is immediately out of date upon return, as the buffer might
become valid again at any time due to concurrent activity. The function is
intended for developer testing only.
</para>
</sect2>
<sect2 id="pgbuffercache-sample-output">
<title>Sample Output</title>
<screen>