All Products
Search
Document Center

PolarDB:Flashback table

Last Updated:Mar 30, 2026

Flashback table lets you restore a PolarDB for PostgreSQL table to the state it was in at any point within the retention window — without a full cluster restore. Use this feature to recover data after an accidental delete or corruption, then merge the recovered rows back into the original table.

When to use flashback table:

  • Accidental delete: A DELETE removed rows you need to recover.

  • Data corruption: A batch update wrote incorrect values and you need to retrieve the prior state.

  • Data verification: You want to compare the current table state against a historical snapshot.

How it works

Flashback table works by periodically saving page snapshots to flashback logs and retaining transaction information in the fast recovery area. When you trigger a flashback, PolarDB reads those logs to reconstruct the table as it existed at the target timestamp and writes the result to a new table.

The original table is not modified. The restored table is named polar_flashback_<OID>, where <OID> is the object identifier of the original table.

Prerequisites

Before you begin, ensure that you have:

  • A PolarDB for PostgreSQL cluster running PostgreSQL 11, revision version 1.1.22 or later. To check the revision version, run:

    SHOW polar_version;
  • Flashback table enabled. See Enable flashback table.

Enable flashback table

Enabling flashback table requires setting two parameters and restarting the cluster. Review the resource impact before enabling in production.

  1. Set the two mandatory parameters:

    ALTER SYSTEM SET polar_enable_flashback_log = on;
    ALTER SYSTEM SET polar_enable_fast_recovery_area = on;
  2. Restart the cluster for the changes to take effect.

  3. (Optional) Tune additional parameters based on your retention and performance requirements. See Parameters.

polar_enable_flashback_log and polar_enable_fast_recovery_area take effect after SIGHUP, but enabling these features requires a full restart to apply the associated memory changes.

Syntax

FLASHBACK TABLE [ schema. ]table TO TIMESTAMP expr;
Parameter Description
[ schema. ]table Name of the table to flash back, optionally qualified with a schema name
expr Target timestamp — the point in time to restore the table to
A flashback creates a new table named polar_flashback_<OID>; it does not modify the original. The operation acquires an exclusive lock on the source table, so only read queries on that table are allowed while the flashback is running.

Timestamp examples

Relative offset (5 minutes ago):

FLASHBACK TABLE orders TO TIMESTAMP now() - interval '5 min';

Absolute timestamp:

FLASHBACK TABLE orders TO TIMESTAMP '2026-03-28 10:00:00';

Flash back a table

The following example shows how to flash back a table after an accidental delete.

Step 1: Prepare test data

Create the test table and insert 10,000 rows:

CREATE TABLE test(id int);
INSERT INTO test SELECT * FROM generate_series(1, 10000);

Verify the initial state:

SELECT count(1) FROM test;
-- count: 10000

SELECT sum(id) FROM test;
-- sum: 50005000

Step 2: Delete data and confirm the loss

SELECT pg_sleep(10);
DELETE FROM test;

SELECT * FROM test;
-- id
-- ----
-- (0 rows)

Step 3: Flash back the table

Restore the table to the state it was in 10 seconds ago:

FLASHBACK TABLE test TO TIMESTAMP now() - interval '10s';

Expected output:

NOTICE:  Flashback the relation test to new relation polar_flashback_65566, please check the data
FLASHBACK TABLE

The NOTICE message shows the name of the restored table (polar_flashback_65566).

Step 4: Verify the restored data

SELECT count(1) FROM polar_flashback_65566;
-- count: 10000

SELECT sum(id) FROM polar_flashback_65566;
-- sum: 50005000

Step 5: Merge missing rows back

After verifying that the restored data is correct, insert the missing rows back into the original table:

INSERT INTO test SELECT * FROM polar_flashback_65566
WHERE id NOT IN (SELECT id FROM test);
No indexes are created on the flashback table. Create indexes manually if your queries require them.

Limitations

Unsupported object types

Flashback table restores only common tables. It cannot restore:

  • Indexes

  • TOAST tables

  • Materialized views

  • Partitioned tables and child partitioned tables

  • System tables

  • Foreign tables

  • Tables that contain child TOAST tables

DDL operations that block flashback

If any of the following DDL operations were executed on the table between the target timestamp and now, the flashback will fail:

  • DROP TABLE

  • TRUNCATE TABLE

  • ALTER TABLE SET WITH OIDS or ALTER TABLE SET WITHOUT OIDS

  • Modifying a column data type where the old and new types cannot be implicitly converted and the USING clause does not provide a secure forced conversion

  • Changing the table to UNLOGGED or LOGGED

  • Adding a column as IDENTITY

  • Adding a column where only limited data types can be selected

  • Adding a column where the default value expression contains volatile functions

To recover from an accidental DROP TABLE, use the Flashback delete feature instead.

Resource impact

Enabling flashback table increases memory and disk usage and may degrade performance. Evaluate the following before enabling in production.

Memory

After enabling flashback logging, shared memory increases by:

  • polar_flashback_log_buffers × 8 KB

  • polar_flashback_logindex_mem_size MB

  • polar_flashback_logindex_queue_buffers MB

After enabling the fast recovery area, shared memory increases by approximately 32 KB.

Disk

Flashback table retains flashback logs, Write-Ahead Logging (WAL) logs, and LogIndex files. Disk usage scales with the value of polar_fast_recovery_area_rotation. For example, setting it to 300 retains 5 hours of historical data.

As a rough estimate: if 20 GB of WAL logs are generated in 5 hours, the flashback log volume is approximately 1 GB (a 1:20 ratio). The actual ratio depends on write volume and the values of polar_flashback_point_segments and polar_flashback_point_timeout — larger values produce fewer flashback logs.

Flashback points are a type of checkpoint created periodically after flashback logging is enabled. Set these parameters to align flashback points with your WAL and checkpoint cadence:

  • Set polar_flashback_point_segments to a multiple of max_wal_size.

  • Set polar_flashback_point_timeout to a multiple of checkpoint_timeout.

Performance

  • Background processes: Flashback logging requires two additional background processes (bgwriter and bginserter) to consume flashback logs, increasing CPU overhead. The default values of polar_flashback_log_bgwrite_delay and polar_flashback_log_insert_list_delay are tuned to minimize this impact — avoid lowering them unless necessary.

  • Write performance: Flashback log flushing occurs before page flushing to prevent log loss. In most workloads, performance degradation is less than 5%.

  • Flashback operation: While a table is being flashed back, the related pages are swapped in and out of the shared memory pool. This may cause temporary jitter in query performance on other databases in the cluster.

Run flashback operations during off-peak hours to minimize the impact on production workloads.

Best practices

  • Recover from accidental deletes: Check the audit log to identify the exact time of the unintended operation, then flash back the table to a point just before that time.

  • Large tables: Increase polar_workers_per_flashback_table to enable parallel flashback and reduce recovery time.

  • Post-recovery workflow: After flashback completes, compare the restored table against the original using the table name from the NOTICE output. Confirm the data is correct, then insert the missing rows back into the original table.

  • Parameter changes: Modify parameters one at a time and schedule cluster restarts during off-peak hours.

Parameters

Parameter Description Default Valid values Unit Takes effect
polar_enable_flashback_log Enables flashback logging. off on, off SIGHUP
polar_enable_fast_recovery_area Enables the fast recovery area. off on, off SIGHUP
polar_flashback_log_keep_segments Number of flashback log files to retain. Each file is 256 MB. 8 3–2147483647 SIGHUP
polar_fast_recovery_area_rotation How long transaction information is retained in the fast recovery area. 180 1–14400 Minutes SIGHUP
polar_flashback_point_segments Minimum number of WAL log segments between two flashback points. Each WAL log is 1 GB. 16 1–2147483647 SIGHUP
polar_flashback_point_timeout Minimum time interval between two flashback points. 300 1–86400 Seconds SIGHUP
polar_flashback_log_buffers Shared memory size for flashback logs. 2048 4–262144 KB Restart
polar_flashback_logindex_mem_size Shared memory size for flashback log indexes. 64 3–1073741823 MB Restart
polar_flashback_logindex_bloom_blocks Number of Bloom filter pages for flashback log indexes. 512 8–1073741823 Restart
polar_flashback_log_insert_locks Number of flashback log insertion locks. 8 1–2147483647 Restart
polar_workers_per_flashback_table Number of parallel workers for a table flashback. Set to 0 to disable parallel flashback. 5 0–1024 Immediately
polar_flashback_log_bgwrite_delay Latency between activity rounds for the bgwriter process. 100 1–10000 ms SIGHUP
polar_flashback_log_flush_max_size Maximum log size flushed to disk per bgwriter round. Set to 0 for no limit. 5120 0–2097152 KB SIGHUP
polar_flashback_log_insert_list_delay Latency between activity rounds for the bginserter process. 10 1–10000 ms SIGHUP
polar_flashback_log_size_limit Maximum total size of flashback logs. Set to 0 for no limit. When exceeded, log recycling is triggered. 20480 0–2147483647

What's next