'bundle exec rake db:migrate' 因日历迁移耗时过长

ystemd+  7660  0.0  0.3 352060 28284 ?        S    22:31   0:00 /usr/lib/postgresql/13/bin/postmaster -D /etc/postgresql/13/main
systemd+  7667  0.0  0.1 352588  9628 ?        Ss   22:31   0:00 postgres: 13/main: checkpointer 
systemd+  7668  0.3  0.9 352060 78796 ?        Ss   22:31   0:03 postgres: 13/main: background writer 
systemd+  7669  0.0  0.1 352060 13696 ?        Ss   22:31   0:00 postgres: 13/main: walwriter 
systemd+  7670  0.0  0.1 352728 11892 ?        Ss   22:31   0:00 postgres: 13/main: autovacuum launcher 
systemd+  7671  0.0  0.0  67996  5320 ?        Ss   22:31   0:00 postgres: 13/main: stats collector 
systemd+  7672  0.0  0.0 352612  6640 ?        Ss   22:31   0:00 postgres: 13/main: logical replication launcher 
systemd+ 10900 82.0  3.8 487164 317728 ?       Rs   22:33  10:42 postgres: 13/main: discourse discourse [local] DELETE
systemd+ 10901  0.0  0.1 353432 13804 ?        Ss   22:33   0:00 postgres: 13/main: discourse discourse [local] idle

htop 显示 discourse [local] delete 占用了 100% 的 CPU。该液滴有 8GB 内存,目前使用量 <1GB(不包括缓冲区)。

操作系统已过时,但这对我来说似乎非常奇怪。内存和磁盘充足,并且该 postgres 删除任务已运行超过 12 分钟。帖子少于 600K,用户少于 4K,因此数据库并不大。哦。等等。postgres_data 目录是 28GB。

我运行了 VACUUM VERBOSE ANALYZE;。

我做了这个:

discourse=# SELECT checkpoints_timed, checkpoints_req FROM pg_stat_bgwriter; 
 checkpoints_timed | checkpoints_req 
-------------------+-----------------
                 6 |              20

我现在正在尝试并发重新索引。也许 vacuum 和 reindex 会有帮助。