pg_stat_activity view to identify top SQL and wait events consuming resources.EXPLAIN ANALYZE BUFFERS plans to investigate plan node details, including:
Rewriting Queries: A function call in a predicate can lead the optimizer to perform a sequential full table scan instead of using an index. Rewriting the query to include a SELECT call for the function provides the optimizer with the necessary information to use the index.
Leveraging Partial Indexes: When a table has a high percentage of inactive/deleted data, creating a partial index on the active data can significantly improve performance by reducing the number of rows the optimizer needs to consider.
Switching Query Plans: When the optimizer chooses a suboptimal index plan, the PostgreSQL Plan Management extension can be used to capture, approve, and switch between different query plans without modifying the application code.
Heap-Only Tuple Updates: For updates to non-indexed columns, the "heap-only tuple" feature can be leveraged by reducing the table's fill factor, allowing PostgreSQL to update the data in-place without modifying indexes.
Partition Pruning and Locking: For partitioned tables, ensuring the partition key is used in the query predicate can enable partition pruning and reduce the number of locks required, improving performance.
Identifying and Removing Unused/Duplicate Indexes: Unused and duplicate indexes can consume unnecessary storage and impact write performance. Regularly monitoring and removing these indexes can provide a performance boost.