brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: pg_stat_user_tables shows which database tables autovacuum is behind on

Database
~/tips/tip-database-pg-stat-user-tables-dead-rows

FROM pg_stat_user_tables ORDER BY n_dead_tup DESC LIMIT 10;

Finds the PostgreSQL tables with the most dead rows and shows when they were last cleaned.

Slow queries on a PostgreSQL table are often just dead rows that nobody cleaned up yet.

SELECT relname, n_dead_tup, last_autovacuum
FROM pg_stat_user_tables ORDER BY n_dead_tup DESC LIMIT 10;
VACUUM (VERBOSE, ANALYZE) orders;

n_dead_tup is the estimated number of dead rows per table, and last_autovacuum tells you when autovacuum last touched it. A table with a huge count and an old date deserves a manual VACUUM (VERBOSE, ANALYZE).

Plain VACUUM makes the space reusable inside the table but rarely shrinks the file. VACUUM FULL does shrink it, and it takes an exclusive lock for the whole run, so keep it for quiet hours.

Further reading: PostgreSQL documentation: Routine Vacuuming

More Database tips mariadb -e 'CREATE DATABASE IF NOT EXISTS blog' mariadb-dump --no-create-info --insert-ignore shop orders > orders-rows.sql SELECT table_schema, table_name, CHECKSUM TABLE shop.orders; services: All Database tips (53) All topics

Link