PostgreSQL Autovacuum Tuning Based on Table Size

Object This post provides a SQL query that analyzes PostgreSQL tables and suggests optimized autovacuum settings on a per-table basis. It aims to improve database health and performance by adapting vacuum/analyze thresholds according to table size and usage patterns. Goal PostgreSQL uses autovacuum to automatically clean up dead tuples and refresh planner statistics. However, the default settings may be too aggressive for small tables or too lax for large ones, leading to: ...

July 27, 2025 · 4 min · beh74

Enable pg_stat_statements module

How to do it pg_stat_statements is required by pgAssistant. If you are not familiar with this module, you can find here the official Postgres documentation. To enable this module, add this option on the command that runs Posgres : shared_preload_libraries='pg_stat_statements' Then, connect to the database and run this command : CREATE EXTENSION IF NOT EXISTS pg_stat_statements; (When you run pgAssistant, he will execute this SQL Statements) If you run Postgresql in a docker environment Here is a sample docker-compose file that enables the module : ...

January 10, 2025 · 1 min · beh74

The issue - Missing index on foreign key

What is all about When you create a foreign key, you should always create an index on it (and NO, postgres do not create automaticly an index for you). Should You Always Index Foreign Keys in PostgreSQL? Foreign keys are an essential part of relational database design. They ensure referential integrity by linking rows between tables. But when it comes to performance, many developers wonder: “Should I always add an index to a foreign key column?” ...

January 10, 2025 · 3 min · beh74