PostgreSQL performance audit

A PostgreSQL performance audit checks configuration, hardware, top queries, indexes, bloat and connection handling, then ranks fixes by expected effect. This page explains what the review covers, what it needs from your team and what it cannot promise.

On this page

What a PostgreSQL performance audit answers before you change settings

Most slow PostgreSQL systems respond to a tuning reflex: raise shared_buffers, add an index, lower random_page_cost, or copy a configuration from a blog post. Each change can help, and each can also make a different workload worse. The reader in this situation usually has one of three triggers: queries that have slowed down, CPU or disk I/O that keeps climbing without an obvious cause, or a major upgrade on the calendar and a fear that performance will shift under them. In all three cases, the first question is not which setting to change but which queries and resources are actually responsible. A performance audit starts there, so that every later change can be tied to a measured cost rather than a hunch.

An outside review gathers that evidence in one pass. It reads the current settings against the hardware and the workload, ranks the heaviest statements by total and mean time using pg_stat_statements, checks index usage and table and index bloat, and looks at how connections are opened, pooled and held. The output is a prioritized fix list. Each item names the symptom it addresses, the evidence behind it, the change proposed and the effect the reviewers expect, with the confidence level stated. Ask for that structure explicitly in the scope, and ask whether the expected effect will be checked by a before and after measurement on the same workload. A list without measurements is an opinion.

Tune in-house when the team already collects query statistics, can reproduce the slow workload in a test environment, and has someone who reads execution plans routinely. Commission an audit when the slow path is unclear, when the same database has been tuned several times without lasting results, when production data cannot be copied for testing, or when a major upgrade or a new application load creates a deadline. Confirm before you engage that pg_stat_statements is enabled or can be enabled on your version, that you can share query text and plans under your data handling rules, and that you have a window for benchmarking. Those three answers determine how much of the review can be done without disturbing production.

What a PostgreSQL performance audit checks, area by area

This table compares the six areas a PostgreSQL performance review covers: what the reviewer examines, the evidence to prepare, and the findings that usually lead to a change. Read each row as a checklist for your own environment, and use the last row to confirm that every finding ends in a prioritized fix with an expected effect.

Audit areaWhat the reviewer examinesEvidence to prepareFindings that usually lead to a change
ConfigurationServer parameters compared with the workload, version and hardware, including memory, checkpoint, WAL and autovacuum settingsCurrent postgresql.conf and postgresql.auto.conf values, the PostgreSQL version, and any settings changed by hand or by an operatorMemory settings out of line with host RAM, checkpoints forced by size, autovacuum falling behind, or settings left at defaults after a migration
Hardware and hostCPU count, memory, storage type, filesystem, I/O latency and how the host shares resources with other servicesHost specifications, storage type and mount options, I/O and CPU metrics over a representative period, and virtualization or container limitsStorage that cannot keep up with write volume, memory pressure or swapping, CPU saturation, or noisy neighbors on shared hosts
Top queries (pg_stat_statements)Queries ranked by total time, mean time and call count, with the share of database time each one usespg_stat_statements enabled with the reset time known, a sample from peak hours, and the application code paths that issue each queryA few statements that account for most database time, repeated queries that could be batched, or queries that changed behavior after a deploy
Index and bloat analysisUnused, duplicate and missing indexes, table and index bloat, and the plans that depend on themIndex definitions, index usage statistics since the last reset, table size history and the output of EXPLAIN ANALYZE for the top queriesIndexes never scanned, overlapping indexes that add write cost, bloated tables that vacuum has not reclaimed, or missing indexes behind sequential scans
Connection handlingConnection counts, idle and idle-in-transaction sessions, pool configuration and how applications open and reuse connectionsConnection counts over time, application pool settings, any PgBouncer configuration, and the driver and framework in useConnection storms after restarts, idle transactions holding locks, pools sized larger than the database can serve, or session features that conflict with pooling
Fix list and expected effectEach finding ranked by its effect on the workload, the risk of the change and the effort to make itAgreed priorities from the business owners, a test environment where changes can be measured, and a rollback plan for each changeA short list of changes with the measurement that will show whether each one worked, plus items to defer until after an upgrade or hardware change

How evidence turns into a prioritized fix list

The review starts with read-only access and a baseline of the running server, then moves through query statistics, configuration and hardware, indexes and bloat, and connection handling. Each phase feeds the next, so a query that ranks high in pg_stat_statements is checked against its plan, its indexes and its connection pattern before anything is recommended. The reviewer hands over the ranked fix list with its expected effect and the evidence behind each item. Nothing changes until the client approves the items it wants applied. The final step is a retest that compares results with the baseline.

Review phases, with the client approval gate and evidence handover marked.

How the PostgreSQL performance audit runs from access to fix list

The audit moves from a written scope to read access, a captured baseline, evidence-based review of queries, settings and hosts, and finally a ranked backlog where each fix states its expected effect and how it will be verified.

  1. Agree scope and change rules in writing

    Before any access is granted, the client and DeployOpen agree in writing which databases, hosts and applications are in scope, which business periods the review must cover, and who may approve any change. The agreement also states that the audit is read-only: no settings, indexes or schema objects are changed during collection. The step closes when both parties have signed the scope and the named contacts for questions and access approvals are confirmed.

  2. Grant read access and confirm statistics collection

    The client's DBA or platform owner creates a read-only monitoring role and provides connection details for the primary, replicas and any pooler. DeployOpen checks whether pg_stat_statements is loaded and collecting. If it is not active, the client enables it through their normal change process, which usually requires a restart, so the team schedules that change before the baseline. The step closes when a test query against the extension returns rows and the client confirms when the statistics were last reset.

  3. Capture a baseline during representative load

    DeployOpen records the current settings, pg_stat_statements totals, table and index statistics, and host metrics over a window that includes normal peak activity. The team confirms the window covers a full normal business cycle, such as the close of a daily batch or a weekday peak, rather than a quiet period. Any incident, deployment or maintenance job during the window is logged so it can be excluded from conclusions. The step closes with a saved baseline snapshot and a short list of the events that happened during it.

  4. Review top queries and their plans

    The team ranks statements by total execution time, mean time and call count, then pulls execution plans for the top entries using EXPLAIN ANALYZE on a non-production copy or during an agreed low-risk window. Each query is tagged with its likely cause, such as a missing index, stale statistics, a poor join choice or application behavior like N+1 calls. The step closes when every top query in the backlog has a tagged cause and the team has noted which plans were measured and which were inferred.

  5. Check settings, bloat and connection handling

    DeployOpen compares the running configuration with the server version, workload and hardware, checking memory, checkpoint, autovacuum and connection settings. It also measures table and index bloat, unused indexes and connection counts, including whether a pooler is in use and how it is configured. Each finding is linked to evidence from the baseline rather than a generic recommendation. The step closes when every setting checked has either a documented reason to keep it or a proposed change with its supporting data.

  6. Correlate host metrics and check for contention

    The team reviews CPU, memory, disk latency, I/O wait and network metrics from the same baseline window, and checks wait events and lock activity in the database. This separates problems the database can fix from those caused by storage, virtualization or shared hosts. Where the client lacks host metrics, the audit records that gap as a limitation instead of assuming a cause. The step closes when each major slowdown has been matched to either a database or host explanation, or marked as unresolved with the data still needed.

  7. Write the ranked fix list with expected effect

    DeployOpen turns the findings into a backlog ranked by expected impact, risk and effort. Each item states the problem, the evidence, the proposed change, the expected effect as a qualitative estimate with its confidence level, the rollback path and how the result will be measured. The team also records which items need a test in a staging environment or a benchmark before go-live. The step closes when the client has the written list and has confirmed which items they will approve, schedule or decline.

Which audit scope fits your situation

When a single production database makes user-facing pages slow, the first priority is finding which statements consume the most time under real traffic. The review usually starts with query ranking, then checks whether connection handling or lock waits add latency before any setting is changed. Index and bloat analysis follows, because a missing index on a hot path often explains more than server configuration does.

  • Top statements by total time: ranking from pg_stat_statements shows where the database spends its time, not which queries merely look expensive.
  • Connection behavior: counts of active, idle and idle-in-transaction sessions show whether the application opens too many connections.
  • Plan changes: comparing current EXPLAIN ANALYZE output with the query's history shows whether a statistics change or data growth shifted the plan.
  • Lock and wait events: long waits on locks or I/O can look like slow queries in page timings.
  • Application timing: page-level traces let the reviewer match slow pages to specific statements.

Collect a stats snapshot during a slow period, the page list with timings, and the query log for the same window. A reviewer cannot judge whether a query is acceptable without knowing the expected response time, the peak request rate, or which pages users actually complain about.

Why pg_stat_statements comes before any setting change

Ranking queries by total and mean time shows where the database actually spends its effort before anyone touches a setting. Total time identifies the statements that consume the most server time across all calls, which is often a frequently run query that is individually fast. Mean time identifies the expensive individual executions, which may run rarely but block users when they do. An audit that starts with shared_buffers or work_mem without this ranking tends to move cost elsewhere: a larger memory setting can relieve one query while increasing memory pressure under concurrency, or a checkpoint change can shift I/O into a window where a different batch job suffers.

Statistics have limits that the reader should keep in view. The pg_stat_statements view reflects only the collection window since the last reset, so a snapshot taken right after a deployment or a restart may not represent the normal workload. Reset timing matters: if the statistics were cleared during an incident or a release, the ranking covers a different mix of traffic than the one users see at month end. Confirm when the view was last reset, which application releases ran in that window, and whether the extension's settings were enabled for the full period. The view also does not explain why a query is slow. It reports timing and buffer counters, not the plan the planner chose, so a high-ranked statement still needs its plan examined.

Plans are examined as a separate step, once a query has earned a place on the backlog. The PostgreSQL documentation on EXPLAIN is the reference for reading estimated and actual rows, and the sibling topics on finding slow queries with pg_stat_statements and on reading EXPLAIN ANALYZE cover the mechanics in detail. For the audit, the output to ask for is a short list of top statements with their call counts, mean and total time, and a plan for each one, so that every proposed fix can be traced back to a measured cost and a specific change in the plan.

Protecting data and access during a PostgreSQL performance audit

A performance review needs to see real queries, plans and configuration, which can expose customer rows, credentials and host access. The cards below set out the controls to agree before the review starts and who approves each one, so the audit stays inside the data and access your organization already allows.

Read-only roles that still expose rows

A read-only role stops writes, but it can still read every table it is granted, including customer rows that a tuning review does not need. Ask for a role limited to catalog views and statistics such as pg_stat_user_tables and pg_stat_statements, with SELECT denied on business tables. Where plans need table statistics, have the data owner confirm that row sampling is acceptable. Approval: the database owner and the data protection officer.

Authentication methods docs

Sensitive literals in query text

pg_stat_statements normalizes queries, but the stored text can still carry personal or payment data in cases where literals are not replaced, such as dynamic SQL or statements run through some drivers. Before the reviewer reads the view, check a sample for names, card fragments, account numbers or identifiers, and restrict access to the view to the audit role. Redact any exported extract before it leaves the environment. Approval: the database owner, with the privacy or payments lead for scope.

Changes made directly on production

Tuning steps such as ALTER SYSTEM, new indexes or ANALYZE runs can change live behavior, and some index builds lock or consume I/O. Agree that the reviewer proposes changes only as written scripts, that they run first on a restored copy or staging system, and that production changes go through your normal change process with a rollback step. Approval: the platform owner and the change advisory board.

Credentials shared in tickets

Reviewers often ask for connection strings in a ticket or chat thread, and those values then persist in tool history and logs. Issue a named account per reviewer with an expiry date, deliver the password through your secrets manager, and rotate it when the review closes. Confirm that the password method in pg_hba.conf uses SCRAM rather than MD5. Approval: the identity or security team.

Evidence files with sensitive content

Findings usually include EXPLAIN output, slow query logs and host metrics, and these files can contain literal values, host names, IP addresses and internal paths. Store evidence in an approved location with access limited to the review team, strip literal values from plans before sharing, and set a deletion date in the agreement. Approval: the security team and the data owner, who confirm what may be retained.

Reviewer access to host systems

Database statistics rarely answer every question, and a reviewer may ask for shell access to read I/O, memory and kernel settings. Grant read-only access through a bastion with session recording, limit it to the commands the review needs, and keep the database server's administrative account out of the reviewer's hands. Approval: the infrastructure owner and the security operations lead.

What buyers ask before hiring outside PostgreSQL performance help

What drives the cost and effort of a PostgreSQL performance review?

The scope written before work starts sets most of the cost. The main drivers are the number of database clusters and databases, how many applications and query patterns touch them, the size and age of the workload history available for analysis, and whether the review covers only the database or also the hosts, storage and connection layers around it. Cost is paid for the reviewer's time: reviewing configuration and hardware, analyzing top queries and plans, checking indexes and bloat, examining connection handling, and writing the prioritized fix list with expected effect. These are mostly one-time costs. Ongoing tuning or retesting after fixes is a separate piece of work. Ask any provider for a quote that lists each cluster in scope, the data sources it will use, what is excluded, and whether a retest is included.

Can our own database team run a performance audit in-house?

Yes, many teams can, and the work is well documented. The PostgreSQL project publishes the configuration parameters, statistics views and extensions that a review relies on, and pg_stat_statements is the usual starting point for ranking slow queries. The harder parts are judging which findings matter for your workload, separating a query problem from a hardware or connection problem, and resisting changes that trade one symptom for another. An internal team usually needs time away from feature work, a second reviewer for changes, and a safe place to test. An outside review adds an independent view and a written backlog. Decide based on whether your team has done this kind of analysis on production systems before, and whether it has the time to do it without pressure from an incident.

What access and time does our team need to provide for a review?

The reviewer needs read access to the systems being reviewed and a named contact who can answer questions about the application. Typical requests include: a read-only database role with access to the statistics views, the server configuration file, pg_stat_statements output for a representative period, slow query logs if they exist, host metrics for CPU, memory, disk and network, and the connection pooler configuration. The reviewer also needs to know the workload calendar, such as batch windows and peak periods, and any change freeze. Your team should expect to answer questions, approve any test runs against non-production copies, and review the findings before the fix list is final. Confirm exact access requirements and data handling rules in writing before work starts, especially if production data is involved.

How long does a PostgreSQL performance review take?

Duration depends mainly on the number of database clusters, the number of databases and applications per cluster, and how complex the workload is. A single cluster with a small set of known query patterns takes far less analysis than a shared cluster serving many applications with ad hoc reporting. Other factors include how quickly access is granted, how much representative statistics history exists, and how many rounds of questions the application team needs to answer. The reliable way to get a figure is to ask for a written timeline tied to the agreed scope, with milestones for data collection, analysis, the draft findings and the final fix list. Be wary of any timeline quoted before the number of clusters and the workload type are known.

What does the fix list contain and how is it prioritized?

A useful fix list has one entry per finding, and each entry names the evidence behind it. Expect the following for each item:

  • The observed problem, such as a high-total-time query, unused indexes, table bloat, or connection saturation, with the query ID or table name
  • The proposed change, such as an index, a query rewrite, a parameter change, or a pooler setting
  • The expected effect, described in terms the evidence supports, and how to measure it
  • The risk of the change, rollback steps, and who owns it

Priority should follow the work the database does for users, not the number of warnings. Ask for the scoring method in writing so the ranking can be checked.

Does a performance review guarantee a speedup?

A review identifies what is slow, why it is slow based on the evidence collected, and what changes are likely to help. It does not promise a specific speedup, because the result depends on the application, the hardware, the data and changes made by your team. Some findings have a large measurable effect, while others only reduce risk. Ask providers to state the basis for each expected effect and how it will be tested, for example by comparing the same queries before and after a change on a copy of the workload. Benchmarking tools such as pgbench are useful for load testing, but they do not replace a test that mirrors your own queries.

What happens after the fixes are applied?

Most of the work after a review belongs to your team: applying changes in order, testing each one, and watching for side effects. Outside help can be scoped as a retest of the fixed items, a follow-up review after a major workload change, or ongoing support. Ask whether the engagement includes a retest, how results are compared against the baseline captured during the review, and who approves changes to production. Performance also changes with data growth and new application releases, so plan for periodic reviews of the top queries and the statistics views. Major version upgrades can change planner behavior, so the fix list should note which items need rechecking after an upgrade.

Limits to confirm before you commission the review

A performance review is only as useful as the environment it can see and change. Confirm the items below with your database owner, platform team and provider before you sign a scope, because each one shapes which findings are possible and how they can be verified.

Major version and support end date

Confirm which PostgreSQL major version runs in production and when its community support ends. Version choice changes which planner behavior, statistics handling and I/O options apply, and a fix list for a version near end of life may lead straight into an upgrade. Ask your database owner for the exact version string from SELECT version(); so the review targets the real release.

Supported version to check
14
Versioning policy

pg_stat_statements access

Ask whether the pg_stat_statements extension is installed, preloaded and readable by the reviewer's role. Without it, query ranking falls back to logs and guesswork. Managed providers often expose it with limits, so confirm the statistics window and whether anyone can reset it during the engagement.

A representative workload window

Confirm that a period of normal and peak traffic can be captured, such as a full business cycle with batch jobs, reports and autovacuum activity included. A review sampled only during a quiet weekend will miss the queries that cause the slowdowns people report. Ask who owns the monitoring data that covers that window and how long it is retained.

Connection pooling in front of the database

Find out whether applications connect directly or through PgBouncer or a similar pooler, and in which mode. Pooling changes which connection settings matter, can break session features and alters how the reviewer reads connection counts and wait times. Ask the application team for the pool configuration and the drivers in use.

PgBouncer site

Managed-service setting restrictions

If a cloud or hosted provider runs the database, confirm which parameters can be changed, which need a restart and whether the provider allows kernel or storage changes at all. Some recommended fixes will be impossible on that platform. Ask the provider for its documented parameter list and change process before the review starts.

A staging copy to test expected effects

Confirm whether a staging database with comparable data volume and hardware exists, and who can run workload replays against it. Each fix in the priority list should carry an expected effect that is measured before it reaches production. Ask your platform team who approves changes to staging and how long a test cycle can run.

How DeployOpen scopes, delivers and supports a PostgreSQL performance audit

DeployOpen treats a PostgreSQL performance audit as a fixed-scope piece of work with written deliverables. The review runs inside your own infrastructure, and the output is a prioritized fix list your team can act on, with optional retainer support afterward.

How we scope

  • Agree in writing which PostgreSQL servers, databases, workloads and time windows the audit covers before any work starts.
  • Confirm access to configuration files, pg_stat_statements data, and system metrics, and whether read-only or staging access is used.
  • Define the deliverables, including the prioritized fix list with expected effect and the retest scope, so the quote follows from a clear scope.

How we build

  • Review configuration and hardware settings against the workload, then rank top queries from pg_stat_statements by total and mean time.
  • Analyze indexes, table and index bloat, and connection handling, and check each proposed change against plans and measured data.
  • Test proposed fixes in a non-production environment where the client permits it, and record before and after measurements for each change.

How we hand over

  • Deliver a written report that explains each finding, the evidence behind it, and the change proposed, ranked by priority and expected effect.
  • Walk your database, operations and application teams through the findings so they can own the backlog after the engagement ends.
  • Document the configuration changes, index and query recommendations, and the retest results in a form your change process can review.

How we support

  • Retest agreed fixes after your team applies them and report whether the measured effect matched the expected effect in the fix list.
  • Offer ongoing support, upgrades and continuous testing as a retainer if you want DeployOpen to keep reviewing performance after the audit.
  • Confirm with DeployOpen the retest window, support hours and escalation path in the written scope before the engagement starts.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.