V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
xyjincan
V2EX  ›  PostgreSQL

数据库数据目录下 base 文件夹有很多 1GB 大小文件,占用几百 G 空间

  •  
  •   xyjincan · 2023-01-11 13:18:07 +08:00 · 1431 次点击
    这是一个创建于 464 天前的主题,其中的信息可能已经有所发展或是发生改变。

    怎么清零出空间呢,数据库表里面数据不多

    建立了额外的四个表空间独立存储每月新增数据。

    旧缓存数据定期删除。

    4 条回复    2023-01-13 02:09:41 +08:00
    h0099
        1
    h0099  
       2023-01-11 13:44:57 +08:00   ❤️ 1
    > 1GB 大小文件

    这是 pgsql 的一个文件分片机制: https://www.postgresql.org/docs/current/storage-file-layout.html
    > When a table or index exceeds 1 GB, it is divided into gigabyte-sized segments. The first segment's file name is the same as the filenode; subsequent segments are named filenode.1, filenode.2, etc. This arrangement avoids problems on platforms that have file size limitations. (Actually, 1 GB is just the default segment size. The segment size can be adjusted using the configuration option --with-segsize when building PostgreSQL.) In principle, free space map and visibility map forks could require multiple segments as well, though this is unlikely to happen in practice.

    根据
    https://dba.stackexchange.com/questions/48273/whats-stored-in-data-dir-base-of-postgresql
    https://dba.stackexchange.com/questions/228114/why-is-my-postgres-base-directory-filling-up-rapidly
    您有执行过[VACUUM]( https://www.postgresql.org/docs/current/routine-vacuuming.html#VACUUM-FOR-SPACE-RECOVERY)吗
    xyjincan
        2
    xyjincan  
    OP
       2023-01-11 14:29:06 +08:00
    @h0099 第一次知道 PostgreSQL 的 VACUUM ,没有执行过。🥲
    cstj0505
        3
    cstj0505  
       2023-01-11 15:29:29 +08:00
    vacuum full xx 表
    会锁表。
    ericFork
        4
    ericFork  
       2023-01-13 02:09:41 +08:00
    pg_repack 或者类似的工具了解一下
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4428 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 10:07 · PVG 18:07 · LAX 03:07 · JFK 06:07
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.