How to detect PostgreSQL corruption before it reaches your backups
Your database team needs two answers: are the data pages on disk sound, and can the backups you hold be trusted to restore? Three layers answer different parts of that question. Data checksums catch pages that change after PostgreSQL writes them, such as damage from storage or memory faults, while amcheck checks the logical structure of B-tree indexes and heap pages on a running server. Backup tools that validate pages during a backup run give a third view, because they read the files as they are copied. Each layer has gaps, so no single one is sufficient on its own.
Checksums are a cluster-level setting, and on an existing cluster they are not something you switch on casually. Confirm in the PostgreSQL documentation for your exact major version how data checksums are enabled on a cluster that was initialized without them, what the write and downtime costs are, and whether your version supports enabling them online. Then check the current state with pg_controldata or the data_checksums setting, and record the answer in your runbook. Plan for amcheck to run against a restored copy or during a low-traffic window, since its checks read heavily and can surface problems you then must act on.
Detection only helps if you have a tested recovery path. A checksum failure or amcheck report tells you a page is damaged, not how to repair it. Decide in advance whether a damaged table is restored from a verified base backup and archived WAL, rebuilt from a logical copy, or reconstructed from a replica, and confirm which of these your backup tool can check for page validity before it writes a backup. Ask your backup vendor or your own tests to show that restores succeed, because a backup that copies damaged pages without complaint will reach your recovery point unnoticed.
Which corruption check fits which situation
This table compares data checksums, amcheck and page-validating backup tools by what each detects, when it runs, what it costs to run and where it fits. Read each row against your cluster's age, uptime constraints and recovery target, then confirm the function names, flags and settings for your PostgreSQL version in the official documentation.
| Check | What it detects | When it runs | Downtime or setup | Where it fits |
|---|---|---|---|---|
| Data checksums | Page-level corruption caused by storage or I/O faults when a page is read, reported as checksum failures in the server log | Continuously on reads and writes once enabled | Set at cluster initialization or enabled offline on an existing cluster; confirm the offline enablement steps for your version | Clusters where silent storage damage is the main worry and checksums were not enabled at creation |
| amcheck B-tree verification | Structural inconsistencies in B-tree indexes, such as ordering and linkage problems, using the bt_index_check family of functions | On demand, run against live tables with SQL | No downtime; requires the amcheck extension and a role with the privileges the function needs | Routine index health checks after a crash, storage event or suspected damage to an index |
| amcheck heap verification | Heap page problems and inconsistencies between a table and its indexes, using heap check functions in the amcheck extension | On demand, typically during a maintenance window because it reads more data | No downtime for most use; expect heavier I/O on large tables and confirm the function list for your version | Targeted checks of critical tables after a suspected corruption event |
| Backup tool page validation | Damaged pages encountered while copying the data directory, such as checksum failures reported during a base backup | During each backup run | Requires the backup tool's verification option; confirm the exact flags in the tool's documentation | Ongoing protection that flags damage before a backup becomes the only copy of good data |
| Restore test | Whether backups and archived WAL actually rebuild a usable cluster, which no check above proves | On a schedule, in a separate environment | Needs spare capacity and a documented procedure; effort depends on database size and recovery target | Confirming recovery options before corruption is found, not after |
How detection results feed the recovery decision
The diagram starts with the three signals that can surface corruption: checksum failures, amcheck findings and failed backup validation. Each one feeds a single triage decision, which decides whether the damage is confined before anything is restored or failed over. From there the path branches to scoping the damage, restoring from point-in-time recovery or a base backup, failing over to a verified standby, or escalating. No single check covers every failure mode, so the scope step matters before choosing a branch.
Detection signals converge on one triage decision with four recovery branches.
Enabling data checksums on a new cluster or an existing one
When a cluster is initialized, data checksums can be turned on at creation time, so every data page written from the start carries a checksum. This is the lowest-effort path because no existing data needs rewriting and no outage is planned around the change. The work sits in the build runbook rather than in an operations window. Confirm the exact initialization option, its requirements and any restrictions for your target version in the PostgreSQL documentation before you script the build.
- Build option: Add the checksum setting to the initialization step in your automation, so it is never left to an operator's memory.
- Template and automation: Check that configuration management, container images and Kubernetes operator templates pass the setting through without overrides.
- Replica builds: Confirm that base backups and standbys are created from the checksummed cluster, so every copy matches the primary's setting.
- Documentation: Record the setting in the cluster inventory so audits and later corruption checks can see it.
After the build, verify with the server's control data or the checksum status view for your version, and confirm that a sample of new tables and backups report checksums as enabled.
An existing cluster that was initialized without checksums cannot switch them on while it is running. The usual route is to stop the cluster cleanly, run the offline tool that rewrites the data directory with checksums, and start it again. The duration depends on data directory size, storage speed and the tool's behavior for your version, so the team should measure it on a copy before setting a window. Confirm the tool name, its requirements and the offline steps in the PostgreSQL documentation for the target version, since those details are not covered here.
- Backup first: Take and verify a full backup before the change, because the rewrite modifies data files in place.
- Downtime window: Schedule the full outage, including a clean shutdown, the tool run and startup, and a rollback plan if the run fails.
- Rehearsal: Run the procedure on a restored copy of production with similar size and storage to measure the window.
- Dependencies: Notify applications, batch jobs and monitoring owners, and confirm no unexpected connections will attempt to reconnect during the change.
- Post-change checks: Confirm checksums are enabled, run a read-only scan of key tables, and check the server logs for page verification warnings in the first days.
Before you close the change, confirm the backup restores and that the cluster reports checksums as enabled.
A cluster with standbys needs a planned order of changes, because the primary and each standby must agree on the checksum setting before replication continues cleanly. Changing the primary alone can leave standbys out of step, and a standby that is rebuilt from an old base backup can reintroduce the old setting. The change plan should show which node changes first, how replicas are handled, and how failover behaves during the work. Confirm the exact order, replica requirements and any failover constraints in the PostgreSQL high availability documentation for the target version before scheduling.
- Failover design: Note that PostgreSQL does not detect failures or promote standbys by itself, so confirm whether your failover tool is paused or reconfigured during the window.
- Replica sequence: Plan whether each standby is rebuilt from a checksummed base backup or converted with the same offline procedure, and document the order.
- Replication lag: Watch replay lag and WAL retention during the change, since standbys may be unavailable while they are being rebuilt.
- Backup and rollback: Keep a verified backup and a documented path back to the previous state for every node.
- Parity checks: Compare the checksum setting on the primary and each standby, and confirm replication is streaming normally before reopening the cluster to applications.
Close the change only after every node reports the same setting and replication lag returns to its normal range.
Why a clean check does not prove the data is intact
A passing corruption check tells you that the pages and indexes it read were consistent when it read them. The cards below cover the gaps that sit around any single check: what it reads, when it runs, which copies it touches, and whether those copies are independent of the one that failed.
Scope of each check
amcheck verifies the indexes and tables you name, and it does not walk every relation in the cluster unless you tell it to. A B-tree check on one index says nothing about its heap, its sibling indexes or tables you left out of the run. List every relation in scope, record which ones were checked and keep that list with the results so a clean run is read against what it actually covered. Ask your team to confirm which amcheck functions and options your PostgreSQL version provides before you build the script.
Continuous archiving docsScheduled checks versus incident checks
A scheduled run shows the state of the cluster on the days it ran, so corruption that appears between runs is missed until the next pass. A check run after an incident answers a narrower question about the objects involved. Keep both, record the time and the relations of each run, and treat a gap between runs as unobserved time. Decide with your database owner how often the scheduled run happens and who reads its output.
Validation limited to what backups read
A backup tool that validates pages checks the blocks it reads during that backup, and a tool that does not validate reads blocks without judging them. Either way, the backup verifies only the data it touched in that run. Pages in files it skipped, relations excluded by a filter or blocks modified after the read are outside its result. Confirm with your backup tool's documentation which checks it performs and which it skips, and do not present a successful backup as proof that the whole cluster is sound.
Replicas can copy bad pages
A standby replays the same write-ahead log as the primary, so a damaged page that came from a bad write or a faulty storage path can appear on the standby too. Streaming replication protects against losing a server, not against carrying a bad page forward. A replica that passes the same checks adds little independent evidence. Plan an independent copy, such as an older base backup or an archive restored to separate storage, and keep it outside the failure path you are testing.
High availability docsGaps in checksum coverage
Data checksums detect many page-level errors when they are enabled on the cluster, but a cluster created or converted without them has no checksum record for its older pages. Checksums also do not verify logical content, such as a wrong value written by an application. Confirm whether your cluster has checksums enabled, which pages were written before that point and which errors your team expects them to catch. Record that answer next to every clean result.
How to run a corruption check on a live cluster
This sequence confirms what your PostgreSQL server can check, enables verification on a copy first, and then runs amcheck on a schedule with recorded results and alerts. The output is a repeatable check that flags corruption early, with a clear record of what was tested and when.
Confirm server version and available extensions
The DBA or platform engineer records the PostgreSQL major and minor version, checks the support status of that major version in the PostgreSQL versioning policy, and confirms that the amcheck extension ships with the installed packages. Run
SELECT version();andSELECT name, default_version FROM pg_available_extensions WHERE name = 'amcheck';on the server. Also runSHOW data_checksums;to see whether checksums are enabled. The step is done when the version, support status, amcheck availability and checksum state are written into the change record. If amcheck is missing from the results, confirm with your package source or vendor before continuing.Install amcheck in each target database
Because amcheck is installed per database, the DBA connects to every database that holds data worth checking and runs
CREATE EXTENSION amcheck;with an account that has the privileges required to create extensions. Installing it in template1 is optional and should be decided by the team, since it affects databases created later. The check passes whenSELECT extname, extversion FROM pg_extension WHERE extname = 'amcheck';returns one row in each database on the list. Keep a list of database names and the results so that a missing installation is visible during the next review.Rehearse verification on a non-production copy
Restore a recent backup or base copy to a separate server with the same major version, then run the checks there before pointing them at production. This shows how long the checks take on your data, which indexes and tables produce errors, and whether the account used has the right permissions. Confirm that the restored copy matches the production major version and that the checks run without connection errors. The step is complete when the team has a dry-run log, has reviewed any messages and has agreed on the scope of the live run.
Run B-tree verification with bt_index_check
On the non-production copy first, and then on the live cluster in the agreed scope, run
SELECT bt_index_check(index => c.oid, heapallindexed => true) FROM pg_class c JOIN pg_am am ON c.relam = am.oid WHERE am.amname = 'btree' AND c.relpersistence <> 't';in each database, or call the function on selected indexes. Theheapallindexedoption adds a check that heap tuples appear in the index, which takes longer, so the team should decide whether to enable it on every run. The step is done when the query returns without errors. Any error message, such as a failed check on a named index, should be saved with its database and index name for investigation.Run heap verification with verify_heapam
Use
verify_heapamto check the table pages themselves, for exampleSELECT * FROM verify_heapam(relation => 'schema.table', on_error_stop => false);, and loop over the tables in scope. Because heap checks read table data, schedule them with the same care as B-tree checks and confirm the function is available on your server version. The check passes when the function returns no rows for each table. Any row returned identifies the block and the problem found, and that output goes into the incident record. Do not run repairs on the live server based on a single result.Schedule runs in low-traffic windows and log timings
Create a scheduled job, for example through cron or the team's job runner, that runs the agreed checks during a low-traffic window selected from your own load data. The job writes the start time, end time, database name, object count and any errors to a log table or file. The platform team owns the schedule and reviews it after the first full run. The step is complete when the first two scheduled runs finish and the log contains timings for every database, which gives a baseline for planning the next change to the schedule.
Check server logs for checksum failures
If data checksums are enabled, review the PostgreSQL server log after each run and search for messages that mention checksum failures or invalid page checksums. Also check the log for amcheck errors and any messages from the storage layer. Confirm that the log level and log destination send these messages to the place where your monitoring reads them. The step is complete when a test message, or a documented sample from a previous run, appears in the monitoring tool and the team confirms it receives the alert.
Set alerts on check errors and record results
Configure your monitoring system to alert on any failed check, any checksum message in the log and any run that does not finish within its window. Route alerts to the on-call group that owns the database. Store the results in a single location with the date, version, database and outcome, so that an auditor or incident responder can see the trend. The step is done when a deliberately failed test check, run against the non-production copy, triggers the alert and the record shows it. Only then should the team treat the check as operational.
What to do when a check reports corruption
A corruption finding from amcheck or a checksum failure starts with containment, not repair. Stop writes to the affected relation if the damage could spread into other pages, indexes or replicas, and keep the server running long enough to capture evidence. Save the full error output, the PostgreSQL and operating system logs covering the failure window, and a copy of the damaged files or pages before anything modifies them. Those copies let you later confirm what was damaged and whether a restore point predates it. Pause scheduled jobs that write to the table, and confirm with the application owner which business functions depend on it.
Then choose a recovery path. The three realistic options are restoring to a point in time from a base backup and archived WAL, restoring a base backup and replaying to the point just before the damage, or failing over to a replica whose own checks came back clean. Each depends on the recovery point objective and recovery time objective the business has agreed to. Replica failover only helps if the corruption did not already replicate, which an amcheck run on the standby will show. In-place fixes such as rebuilding an index with REINDEX or rewriting a damaged table can work, but they run against pages you cannot fully trust and can hide the scope of the problem. Treat them as a last step, after a copy exists, and only with a verified restore path in hand.
Continuous archiving is the recovery basis for all of this. Point-in-time recovery depends on a base backup plus archived WAL files covering the whole period you might need to replay, so check that the archive is complete and readable before you rely on it. Confirm the exact restore steps, recovery target settings and any version-specific behavior against the continuous archiving documentation for the version in use, and rehearse the restore on separate hardware. Record which backup and which WAL position you chose, and rerun amcheck and checksum verification on the restored cluster before it accepts production writes.
Security and operational considerations for corruption checks
Verification tools read every page of your data, so who runs them, how they affect production, and where their output goes matter as much as the checks themselves. The cards below cover the access, load, evidence, backup, replica and restore decisions that connect a corruption check to a recovery plan you can rely on.
Who may run and read verification
Checks such as amcheck need privileges on the tables and indexes they inspect, and their output can reveal table names, row-level problems and sometimes fragments of data. Decide which roles may install the extension, run the functions and view the results, and keep those roles separate from application accounts. Confirm the privilege requirements for each function you plan to use against your PostgreSQL version, since they change between releases.
Authentication methodsLoad and locking on production
A heap or B-tree check reads large parts of a table or index, which adds I/O and CPU load while application traffic continues. Some verification functions take locks that can queue behind long transactions or block DDL, so a check can become its own outage source. Schedule runs in low-traffic windows, test on a copy first, and confirm the lock level and read behavior of each function in the PostgreSQL documentation for your version.
Retention of logs and damaged-page evidence
When a check fails, the error text, the affected relation and the page details are evidence for the investigation and for any vendor or auditor review. Decide where server logs are kept, how long they are retained, and who may export them, and copy the damaged page or relation files before any repair changes them. Treat this evidence as sensitive, because it can contain fragments of customer data.
Backup validation results with backup records
A backup that passes page validation is only useful if the result is recorded with that backup. Store each validation output alongside the backup label, backup time, server version and WAL range, so you can tell which copy is known good when a restore is needed. Ask your backup tool vendor how validation results are stored and whether they can be exported to your retention system.
The role of the replica in recovery
A standby holds a copy of the same corrupted pages if the primary was damaged before replication, so it does not automatically prove the data is clean. Use checks on the replica to compare behavior, but do not assume a failover to it fixes corruption. Decide in advance whether a standby or a restored backup is the source for repair, and document which one you would promote first.
High availability docsTesting the restore path regularly
Corruption findings are only actionable if a point-in-time recovery from a known good base backup and archived WAL works in practice. Schedule restore tests on a separate host, measure how long they take, and verify the restored database with the same checks you used on production. Point-in-time recovery depends on both the base backup and the archived WAL files, so a gap in either breaks the recovery plan.
Continuous archiving docsQuestions teams ask before hiring help with corruption checks
How much effort does enabling checksums and running amcheck take?
The effort depends mostly on cluster size, the number of databases and how much downtime the cluster can tolerate. Enabling data checksums on an existing cluster is a planned offline step, so the cluster must be stopped while the checksums are written, and the time needed grows with data volume. Running amcheck is a read-only verification that can cover many indexes and tables, but its runtime grows with the number of objects and the size of each one. Ask any partner to split its quote into inventory, checksum enablement, verification runs, fixes and handover, and to state which steps need downtime. Before quoting, the partner should review your version and extension setup.
Can our in-house team check for corruption without outside help?
Many teams can run the basic checks themselves, especially if they already manage PostgreSQL and have a tested backup. amcheck is a PostgreSQL extension, and its checks are documented in the PostgreSQL contrib documentation, so a DBA who knows the catalog and the test process can run them. The harder parts are planning the offline checksum window, deciding which findings are harmless and which need action, and recovering from a damaged page without making the problem worse. A partner is most useful when the team lacks spare staff for a first cycle, when the database is large, or when the results must be documented for auditors. Your team keeps ownership of the decisions either way.
What does the work need from our side?
Expect to provide administrative access to the database servers, the ability to run the checks as a privileged role, and a named contact who can approve maintenance windows. You also need current backup records, including the last restore test and the retention policy, because any repair plan depends on them. A test environment built from a recent copy of production lets the team rehearse checksum enablement and verification before touching live data. Ask the partner to list every access grant, change window and evidence item it will request in the written scope, so your change board can approve them in advance.
How long does a first verification cycle take?
A first cycle depends on database size, the number of indexes and heap tables to check, the downtime your organization accepts for checksum enablement, and how many findings need follow-up. If the cluster already has data checksums enabled, the first cycle is mostly verification and reporting. If it does not, the offline enablement step sets the timeline, and you should confirm with your own environment team what downtime is acceptable before any date is agreed. Ask for a schedule that separates the read-only checks from any work that changes data, because the first can often run while the service is live.
What changes when corruption is actually found?
The first step is to stop further damage: identify the affected object, check whether the corruption is limited to indexes that can be rebuilt, and confirm that the current backups are intact. Index corruption often has a rebuild path, while damaged heap pages may need restoration from a backup or point-in-time recovery, which requires archived WAL files and a tested base backup. Recovery targets, meaning how much data loss and how much downtime you can accept, decide which path is used. The partner should write down the decision points, the evidence collected and who approves each action before the first check runs.
Which factors make the cost go up or down?
Cost is mainly driven by cluster size, the number of databases and schemas, how many objects must be checked, and how strict the downtime limit is. Recovery targets also matter: a team that needs fast restoration will need more rehearsal and more monitoring than one that can wait. Environment complexity adds cost, including replicas, multiple clusters, container platforms and separate backup tools. One-time costs include the initial checksum enablement, the first verification cycle and documentation. Recurring costs include scheduled verification, backup restore tests and reviewing findings after each PostgreSQL minor release. Ask for the quote to show these items separately.
Does the engagement include a guarantee that no corruption exists?
No. A verification cycle shows what the checks found at the time they ran, within the scope agreed in writing. amcheck and checksums detect many problems, but they cannot prove that data is free of every fault, and a clean result does not replace ongoing backup testing. DeployOpen plans, runs and documents the checks and fixes within the agreed scope, and prepares evidence for your own compliance or audit reviewers. Independent auditors and certification bodies issue any formal assessment. Ask for the list of checks and the evidence format in the written scope so you know exactly what was verified.
How DeployOpen scopes and delivers corruption detection
DeployOpen scopes corruption detection as a written, fixed-scope piece of work on PostgreSQL clusters in infrastructure you control. The work covers checksum status, amcheck coverage, backup page validation and a tested recovery path, documented so your own team can repeat the checks after handover.
How we scope
- We inventory each PostgreSQL cluster, its version, and whether data checksums are already enabled.
- We agree in writing which databases, indexes and tables amcheck will cover and which are excluded.
- We record which backup tools run, whether they validate pages, and where copies are stored.
How we build
- We set up scheduled amcheck runs with logged results, with schedules and maintenance windows agreed beforehand.
- We plan any checksum enablement on existing clusters as a separate change with its own downtime review.
- We test backup validation and a restore of a copy to confirm the detection path works end to end.
How we hand over
- You receive runbooks for running amcheck, reading its output and deciding when to escalate.
- You receive a findings report listing corruption indicators, affected objects and the fix priorities.
- We walk your operations team through the recovery options for each corruption scenario we tested.
How we support
- Ongoing support, upgrades and continuous testing are available as a retainer after handover.
- Retainers can cover rerunning checks after PostgreSQL minor updates and after major upgrades.
- Pricing follows from the written scope, so ask for a quote that lists each covered cluster and check.

