首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >即使真空已满,也不会删除pg_clog文件

即使真空已满,也不会删除pg_clog文件
EN

Stack Overflow用户
提问于 2017-11-06 10:07:55
回答 2查看 274关注 0票数 1

版本8.4.17

(是的,我知道它很旧,但这超出了我的控制范围。)

市场上有180个pg_clog文件,其中许多来自8月份。

代码语言:javascript
复制
$ dir /var/lib/pgsql/data/pg_clog | grep 2017-08 | wc
     59     472    4307

我使用了这个脚本,因为数据库非常大,我希望看到进展。(我剥离了大量的日志记录。)尽管如此,pg_clog文件仍然保留。

代码语言:javascript
复制
vacuumdb -ezd postgres
SQL="select schemaname||'.'||tablename \
     from pg_tables \
     where schemaname not in ('information_schema', 'pg_catalog') \
     order by schemaname,tablename;"
psql -t $DB -c "$SQL" > $TABLES
for T in $(cat $TABLES); do
    psql -q $DB -c "VACUUM FULL ${T};"
done

我做错了什么?

编辑:为@CraigRinger添加信息

列datminmxid和relminmxid不存在。

代码语言:javascript
复制
postgres=# select datname, datfrozenxid, age(datfrozenxid)
from pg_database
order by age(datfrozenxid);
  datname  | datfrozenxid |    age   
-----------+--------------+-----------
template0 |   3603470462 |  24747443
template1 |   3603334165 |  24883740
postgres  |   3576970250 |  51247655
TAPd      |   3433741226 | 194476679
(4 rows)

TAPd=# select oid, relname, relfrozenxid, age(relfrozenxid)
from pg_class
where not relfrozenxid = xid '0'
order by age(relfrozenxid) desc;
    oid    |                    relname                    | relfrozenxid |    age   
-----------+-----------------------------------------------+--------------+-----------
      2617 | pg_operator                                   |   3433741226 | 194476689
      2602 | pg_amop                                       |   3433741226 | 194476689
      2753 | pg_opfamily                                   |   3445877061 | 182340854
      1259 | pg_class                                      |   3445877061 | 182340854
      1136 | pg_pltemplate                                 |   3445877061 | 182340854
      1213 | pg_tablespace                                 |   3445877061 | 182340854
      3600 | pg_ts_dict                                    |   3445877061 | 182340854
      1262 | pg_database                                   |   3445877061 | 182340854
      3603 | pg_ts_config_map                              |   3445877061 | 182340854
     11467 | sql_parts                                     |   3445877061 | 182340854
      3602 | pg_ts_config                                  |   3445877061 | 182340854
     11457 | sql_languages                                 |   3445877061 | 182340854
      1261 | pg_auth_members                               |   3445877061 | 182340854
     11452 | sql_implementation_info                       |   3445877061 | 182340854
      1417 | pg_foreign_server                             |   3445877061 | 182340854
      2328 | pg_foreign_data_wrapper                       |   3445877061 | 182340854
      3764 | pg_ts_template                                |   3445877061 | 182340854
      2396 | pg_shdescription                              |   3445877061 | 182340854
      2600 | pg_aggregate                                  |   3445877061 | 182340854
      3601 | pg_ts_parser                                  |   3445877061 | 182340854
      2613 | pg_largeobject                                |   3445877061 | 182340854
      2612 | pg_language                                   |   3445877061 | 182340854
     11477 | sql_sizing_profiles                           |   3445877061 | 182340854
      2603 | pg_amproc                                     |   3445877061 | 182340854
[snip]

因此,我必须对pg_catalog模式进行真空处理。但是,仍然有许多“用户”表具有旧的relfrozenxid年龄,即使我在用户表上运行VACUUM FULL。

EN

回答 2

Stack Overflow用户

发布于 2017-11-06 15:36:16

您应该在所有数据库中以超级用户身份运行VACUUM FREEZE

然后,在下一个检查点之后,情况应该会有所改善。

票数 1
EN

Stack Overflow用户

发布于 2017-11-07 04:00:22

解决方案是将@CraigRinger注释中的查询与@LaurenzAlbe建议的VACUUM FREEZE合并。

获取具有旧relfrozenxid值的表的完整列表:

代码语言:javascript
复制
select cl.oid,
       ta.schemaname, 
       cl.relname,
       cl.relfrozenxid,
       age(cl.relfrozenxid)
     from pg_class cl FULL JOIN pg_tables ta
        ON ta.tablename = cl.relname
     where not cl.relfrozenxid = xid '0'
       and age(cl.relfrozenxid) > 60000000
     order by age(cl.relfrozenxid) desc

获取要清理的对象列表:

代码语言:javascript
复制
select COALESCE(ta.schemaname, 'pg_toast') || '.' || cl.relname
     from pg_class cl FULL JOIN pg_tables ta
        ON ta.tablename = cl.relname
     where not cl.relfrozenxid = xid '0'
       and age(cl.relfrozenxid) > 60000000
     order by age(cl.relfrozenxid) desc
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47128748

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档