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

2023-01-11 13:18:07 +08:00
 xyjincan

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

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

旧缓存数据定期删除。

1496 次点击
所在节点    PostgreSQL
4 条回复
h0099
2023-01-11 13:44:57 +08:00
> 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
2023-01-11 14:29:06 +08:00
@h0099 第一次知道 PostgreSQL 的 VACUUM ,没有执行过。🥲
cstj0505
2023-01-11 15:29:29 +08:00
vacuum full xx 表
会锁表。
ericFork
2023-01-13 02:09:41 +08:00
pg_repack 或者类似的工具了解一下

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/908120

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX