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之后才能彻底“压实”页面。

  • 相关阅读:
    C# GDI+图形程序设计看书笔记
    SQL2008转SQL2005
    vb6 调用 .Net Dll
    VS编译后的postevent
    Bind 和 ScaffoldColumn
    转: MarshalAs与StructLayout
    Microsoft .NET Compact Framework 开发常见问题解答
    .Net2.0 使用ConfigurationManager读写配置文件
    在.NET中使用命名管道完成进程间通信[转]
    C# 取电信公网IP并发送邮件
  • 原文地址:https://www.cnblogs.com/jinli1771/p/14998195.html
Copyright © 2011-2022 走看看