我在我的应用程序上运行了postgres数据库,postgres分区是100%满的。在检查pgdata目录中的文件时,可以看到下面的文件占用了大量空间。
smsstoregt1 ins /postgres/pgdata/base/16384> du -skh * | grep -i M
589M 16400
244M 16405请任何人建议如何清理该空间,如果我们可以将文件16400和16405移动到另一个路径或删除它们,或者我们是否可以从DB登录中清除postgres数据库中的任何数据。
下面是我的postgres分区
/dev/mapper/mpath0p1 939M 900M 0 100% /postgres发布于 2017-08-29 13:56:05
您可以在不同的磁盘上创建新的表空间,然后将这些表移动到新的表空间。
首先,在有足够空间的磁盘上创建一个新的表空间:
create tablespace large_disk
location '/path/to/directory/with/more/space'
owner your_postgres_user;通过使your_postgres_user成为该表空间的所有者,用户将自动获得该表空间上的所有特权。
然后,您需要了解这些文件属于哪些表:
select 16400::regclass, 16405::regclass;然后移动表:
alter table public.table_one
set tablespace large_disk;
alter table public.table_two
set tablespace large_disk;发布于 2017-08-29 11:20:13
这些是您的数据文件--您不能在不破坏DB的情况下删除它们。相反,使用LVM来扩展分区。没人能告诉你你能清除什么,这毕竟是你的数据库.
发布于 2018-03-26 14:18:20
可以使用以下脚本监视数据库中所有关系的表大小:
SELECT
relname as "Table",
pg_size_pretty(pg_total_relation_size(relid)) As "Size",
pg_size_pretty(pg_total_relation_size(relid) - pg_relation_size(relid)) as "External Size"
FROM pg_catalog.pg_statio_user_tables
where relname in (select distinct a.relname
from pg_stat_user_indexes a,pg_index b,DBA_IND_COLUMNS c
where c.index_name = upper(a.indexrelname)
and a.indexrelid = b.indexrelid
and idx_scan = 0 and schemaname = <your schema>)
ORDER BY pg_total_relation_size(relid) DESC;请每天使用crontab来安排这个脚本,然后分析在哪一天/哪一天,表的大小急剧增长。
https://dba.stackexchange.com/questions/184574
复制相似问题