mirror of
https://github.com/postgres/postgres.git
synced 2025-11-28 11:44:57 +03:00
pg_buffercache: Add pg_buffercache_os_pages
ba2a3c2302 has added a way to check if a buffer is spread across
multiple pages with some NUMA information, via a new view
pg_buffercache_numa that depends on pg_buffercache_numa_pages(), a SQL
function. These can only be queried when support for libnuma exists,
generating an error if not.
However, it can be useful to know how shared buffers and OS pages map
when NUMA is not supported or not available. This commit expands the
capabilities around pg_buffercache_numa:
- pg_buffercache_numa_pages() is refactored as an internal function,
able to optionally process NUMA. Its SQL definition prior to this
commit is still around to ensure backward-compatibility with v1.6.
- A SQL function called pg_buffercache_os_pages() is added, able to work
with or without NUMA.
- The view pg_buffercache_numa is redefined to use
pg_buffercache_os_pages().
- A new view is added, called pg_buffercache_os_pages. This ignores
NUMA for its result processing, for a better efficiency.
The implementation is done so as there is no code duplication between
the NUMA and non-NUMA views/functions, relying on one internal function
that does the job for all of them. The module is bumped to v1.7.
Author: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Reviewed-by: Mircea Cadariu <cadariu.mircea@gmail.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/Z/fFA2heH6lpSLlt@ip-10-97-1-34.eu-west-3.compute.internal
This commit is contained in:
@@ -46,8 +46,9 @@
|
||||
<para>
|
||||
This module provides the <function>pg_buffercache_pages()</function>
|
||||
function (wrapped in the <structname>pg_buffercache</structname> view), the
|
||||
<function>pg_buffercache_numa_pages()</function> function (wrapped in the
|
||||
<structname>pg_buffercache_numa</structname> view), the
|
||||
<function>pg_buffercache_os_pages()</function> function (wrapped in the
|
||||
<structname>pg_buffercache_os_pages</structname> and
|
||||
<structname>pg_buffercache_numa</structname> views), the
|
||||
<function>pg_buffercache_summary()</function> function, the
|
||||
<function>pg_buffercache_usage_counts()</function> function, the
|
||||
<function>pg_buffercache_evict()</function> function, the
|
||||
@@ -63,12 +64,16 @@
|
||||
</para>
|
||||
|
||||
<para>
|
||||
The <function>pg_buffercache_numa_pages()</function> function provides
|
||||
<acronym>NUMA</acronym> node mappings for shared buffer entries. This
|
||||
information is not part of <function>pg_buffercache_pages()</function>
|
||||
itself, as it is much slower to retrieve.
|
||||
The <structname>pg_buffercache_numa</structname> view wraps the function for
|
||||
convenient use.
|
||||
The <function>pg_buffercache_os_pages()</function> function provides OS
|
||||
pages mappings for shared buffer entries. When its argument is
|
||||
<literal>true</literal>, it also provides <acronym>NUMA</acronym> node
|
||||
mappings for shared buffer entries (this information is not part of
|
||||
<function>pg_buffercache_pages()</function> itself, as it is much
|
||||
slower to retrieve).
|
||||
The <structname>pg_buffercache_os_pages</structname> and
|
||||
<structname>pg_buffercache_numa</structname> views wrap the function for
|
||||
convenient use, with its argument set to <literal>false</literal> and
|
||||
<literal>true</literal> respectively.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
@@ -242,6 +247,53 @@
|
||||
</para>
|
||||
</sect2>
|
||||
|
||||
<sect2 id="pgbuffercache-pg-buffercache-os-pages">
|
||||
<title>The <structname>pg_buffercache_os_pages</structname> View</title>
|
||||
|
||||
<para>
|
||||
The definitions of the columns exposed by the view are shown in
|
||||
<xref linkend="pgbuffercache-os-pages-columns"/>.
|
||||
</para>
|
||||
|
||||
<table id="pgbuffercache-os-pages-columns">
|
||||
<title><structname>pg_buffercache_os_pages</structname> Columns</title>
|
||||
<tgroup cols="1">
|
||||
<thead>
|
||||
<row>
|
||||
<entry role="catalog_table_entry"><para role="column_definition">
|
||||
Column Type
|
||||
</para>
|
||||
<para>
|
||||
Description
|
||||
</para></entry>
|
||||
</row>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<row>
|
||||
<entry role="catalog_table_entry"><para role="column_definition">
|
||||
<structfield>bufferid</structfield> <type>integer</type>
|
||||
</para>
|
||||
<para>
|
||||
ID, in the range 1..<varname>shared_buffers</varname>
|
||||
</para></entry>
|
||||
</row>
|
||||
|
||||
<row>
|
||||
<entry role="catalog_table_entry"><para role="column_definition">
|
||||
<structfield>os_page_num</structfield> <type>bigint</type>
|
||||
</para>
|
||||
<para>
|
||||
Number of OS memory page for this buffer
|
||||
</para></entry>
|
||||
</row>
|
||||
|
||||
</tbody>
|
||||
</tgroup>
|
||||
</table>
|
||||
|
||||
</sect2>
|
||||
|
||||
<sect2 id="pgbuffercache-pg-buffercache-numa">
|
||||
<title>The <structname>pg_buffercache_numa</structname> View</title>
|
||||
|
||||
@@ -558,6 +610,46 @@ regression=# SELECT n.nspname, c.relname, count(*) AS buffers
|
||||
public | spgist_text_tbl | 182
|
||||
(10 rows)
|
||||
|
||||
regression=# SELECT pages_per_buffer, COUNT(*) as buffer_count
|
||||
FROM (
|
||||
SELECT bufferid, COUNT(*) as pages_per_buffer
|
||||
FROM pg_buffercache_os_pages
|
||||
GROUP BY bufferid
|
||||
)
|
||||
GROUP BY pages_per_buffer
|
||||
ORDER BY pages_per_buffer;
|
||||
|
||||
pages_per_buffer | buffer_count
|
||||
------------------+--------------
|
||||
1 | 261120
|
||||
2 | 1024
|
||||
(2 rows)
|
||||
|
||||
regression=# SELECT n.nspname, c.relname, count(*) AS buffers_on_multiple_pages
|
||||
FROM pg_buffercache b JOIN pg_class c
|
||||
ON b.relfilenode = pg_relation_filenode(c.oid) AND
|
||||
b.reldatabase IN (0, (SELECT oid FROM pg_database
|
||||
WHERE datname = current_database()))
|
||||
JOIN pg_namespace n ON n.oid = c.relnamespace
|
||||
JOIN (SELECT bufferid FROM pg_buffercache_os_pages
|
||||
GROUP BY bufferid HAVING count(*) > 1) m on m.bufferid = b.bufferid
|
||||
GROUP BY n.nspname, c.relname
|
||||
ORDER BY 3 DESC
|
||||
LIMIT 10;
|
||||
|
||||
nspname | relname | buffers_on_multiple_pages
|
||||
------------+------------------------------+---------------------------
|
||||
public | delete_test_table | 3
|
||||
public | gin_test_idx | 2
|
||||
pg_catalog | pg_depend | 2
|
||||
public | quad_poly_tbl | 2
|
||||
pg_catalog | pg_depend_reference_index | 1
|
||||
pg_catalog | pg_index_indexrelid_index | 1
|
||||
pg_catalog | pg_constraint_contypid_index | 1
|
||||
pg_catalog | pg_statistic | 1
|
||||
pg_catalog | pg_depend_depender_index | 1
|
||||
pg_catalog | pg_operator | 1
|
||||
(10 rows)
|
||||
|
||||
regression=# SELECT * FROM pg_buffercache_summary();
|
||||
buffers_used | buffers_unused | buffers_dirty | buffers_pinned | usagecount_avg
|
||||
|
||||
Reference in New Issue
Block a user