zoukankan      html  css  js  c++  java
  • pg_freespacemap查看表膨胀

    pg_freespacemap模块提供一种检查自由空间映射(FSM)的手段。它提供一个名为pg_freespace的函数,或精确的说是两个重载函数。该函数在一个给定的页面或关系中的所有页面的自由空间映射内显示记录的值。缺省的公共访问在该函数中取消了,只是因为潜藏的安全问题。
    1,创建扩展

    jinli=# create extension pg_freespacemap;
    CREATE EXTENSION
    jinli=# dxS+ pg_freespacemap
     Objects in extension "pg_freespacemap"
               Object Description           
    ----------------------------------------
     function pg_freespace(regclass)
     function pg_freespace(regclass,bigint)
    (2 rows)

    可以发现pg_freespacemap扩展模块被创建出来后,多了两个重载函数。
    2,示例输出

    jinli=# select * from pg_freespace('public.log_level_problem');
    blkno | avail
    -------+-------
    0 | 73921 | 66562 | 35523 | 3204 | 45765 | 49286 | 59527 | 80648 | 79369 | 793610 | 6944 (11 rows) select * from pg_freespace('public.log_level_problem',10); pg_freespace
    --------------
    6944 (1 row) jinli=# --查看表的平均空间空闲率 jinli=# select count(1) as "number of pages",pg_size_pretty(cast(avg(avail) as bigint)) as "freespace size",round(100 * avg(avail)/8192,2)||'%' as "freespace tatio" from pg_freespace('public.log_level_problem'); number of pages | freespace size | freespace tatio
    -----------------+---------------------+----------------------
    11 | 5841 bytes | 71.31%(1 row) jinli=# vacuum public.log_level_problem; VACUUM jinli=# select count(1) as "number of pages",pg_size_pretty(cast(avg(avail) as bigint)) as "freespace size",round(100 * avg(avail)/8192,2)||'%' as "freespace tatio" from pg_freespace('public.log_level_problem'); number of pages |freespace size |freespace tatio
    -----------------+---------------------+----------------------
    11 | 5690 bytes | 69.46% (1 row) vacuum full public.log_level_problem; VACUUM jinli=# select count(1) as "number of pages",pg_size_pretty(cast(avg(avail) as bigint)) as "freespace size",round(100 * avg(avail)/8192,2)||'%' as "freespace tatio" from pg_freespace('public.log_level_problem'); number of pages | freespace size | freespace tatio
    -----------------+---------------------+----------------------
    4 | 0 bytes | 0.00%
    (1 row)
    jinli=# select * from pg_freespace('public.log_level_problem');
    blkno | avail
    -------+-------
    0 | 01 | 02 | 03 | 0 (4 rows)


    该示例可以看出来执行完vacuum并不能全部释放空间,需执行vacuum full之后才能彻底“压实”页面。

  • 相关阅读:
    [array] leetcode
    [array] leetcode
    [array] leetcode
    无法将“Scaffold-DbContext”项识别为 cmdlet、函数、脚本文件或可运行程序的名称...
    远程桌面报错解决:No Remote Desktop License Servers Available
    linux设置开机自启动
    阿里云ECS服务器环境搭建 ubuntu 16.04 图形界面的安装
    VS C#程序打包覆盖安装不能更新的解决方法
    MySql EF6 DBFirst 向导无法生成 edmx 解决方法(同:您的项目引用了最新实体框架;但是,找不到数据链接所需的与版本兼容的实体框架数据库提供程序)
    "docker build" requires exactly 1 argument(s).
  • 原文地址:https://www.cnblogs.com/jinli1771/p/14998195.html
Copyright © 2011-2022 走看看