重庆思庄Oracle、KingBase、PostgreSQL、Redhat认证学习论坛

标题: 使用 pg_buffercache 查看PG缓冲区使用情况 [打印本页]

作者: 郑全    时间: 2024-10-7 13:43
标题: 使用 pg_buffercache 查看PG缓冲区使用情况
pg_buffercache 插件默认情况下没有安装,需要安装

1.创建pg_buffercache插件

  create extension pg_buffercache;

  查看安装情况:
   pgbenchdb=# \dx
                      List of installed extensions
      Name      | Version |   Schema   |           Description           
----------------+---------+------------+---------------------------------
pg_buffercache | 1.4     | public     | examine the shared buffer cache
plpgsql        | 1.0     | pg_catalog | PL/pgSQL procedural language

2.更新一个表
   pgbenchdb=# update pgbench_accounts set filler=filler;

3.方便查看,建立一个视图
   create view pg_buffercache_v as
        select bufferid,
               (select c.relname
                from   pg_class c
                where  pg_relation_filenode(c.oid) = b.relfilenode
               ) relname,
               case relforknumber
                 when 0 then 'main'
                 when 1 then 'fsm'
                 when 2 then 'vm'
               end relfork,
               relblocknumber,
               isdirty,
               usagecount
        from   pg_buffercache b
        where  b.reldatabase in (0,(select oid from pg_database where datname=current_database()))
        and    b.usagecount is not null;



4.查看该表 缓冲区情况


pgbenchdb=# select * from  pg_buffercache_v where relname='pgbench_accounts';
bufferid |     relname      | relfork | relblocknumber | isdirty | usagecount
----------+------------------+---------+----------------+---------+------------
        2 | pgbench_accounts | main    |          34060 | t       |          1
        3 | pgbench_accounts | main    |         866375 | t       |          4
        4 | pgbench_accounts | main    |         866266 | t       |          2
        5 | pgbench_accounts | main    |         866163 | f       |          0






欢迎光临 重庆思庄Oracle、KingBase、PostgreSQL、Redhat认证学习论坛 (http://bbs.cqsztech.com/) Powered by Discuz! X3.2