Iaroslav Kozlov Русский

Databases Deep dive

Greenplum backups to S3

WAL-G takes a base backup of every segment and archives each completed WAL file to S3-compatible storage. To restore is to fetch a base backup and replay the log up to a chosen point. Taking the backup is half of the work: keeping it from being deleted, cleaning up without losing the wrong copy, and proving that it restores are the other half.

My part

  • I set up backups of the cluster with WAL-G to MinIO S3 storage, with retention and cleanup policies.

Architecture

A generalised layout from the WAL-G, PostgreSQL and MinIO documentation. The number of segments, the schedule and the retention periods of a real site are not shown.

data control

Step by step

  1. A scheduler starts wal-g backup-push on the coordinator.
  2. The coordinator drives a base backup on every segment and sets a restore point, so that the pieces belong to one consistent moment.
  3. Each segment streams its backup to the bucket in compressed parts of about a gigabyte.
  4. Between backups PostgreSQL hands every completed WAL file to wal-g wal-push. A failed upload returns non-zero, and the database retries until the file is stored.
  5. A restore fetches the base backup onto the target hosts and replays the log from the bucket up to the chosen restore point.
  6. A separate job checks the WAL chain for gaps and removes what retention no longer needs: first as a dry run, then with --confirm.

Point at a step and its path lights up on the diagram.

Components

Scheduler
Starts a backup on schedule. Archiving of WAL needs no schedule: the database does it by itself.
Coordinator
wal-g backup-push runs here and drives the backup of every segment; a restore point ties the pieces to one moment.
Segment 1
A primary segment. Streams its base backup and, between backups, hands every completed WAL file to wal-g through archive_command.
Segment N
Every other primary segment does the same, under its own content ID.
MinIO bucket
S3-compatible storage for base backups and WAL. Versioning and object locking keep a stored object from being deleted or overwritten.
Restore host
Where a backup is unpacked and the log replayed: for a real recovery, and regularly as a test.
Upkeep job
Checks that the WAL chain has no gaps and removes backups that retention no longer needs.

Decisions

  • archive_command fails loudly

    PostgreSQL requires the command to return zero only when the file is safely stored, and repeats it until it does. WALG_PREVENT_WAL_OVERWRITE adds the other half: a different file under a name that is already archived is refused, not written over. 1 3

  • Delta backups, chosen on purpose

    They are off by default. With WALG_DELTA_MAX_STEPS above zero only changed data is stored, which shortens the backup window; a restore then has to apply the chain. On Greenplum this is verified on the exact version in use: the WAL-G page for Greenplum contradicts itself on deltas. 3 4

  • Compression is a trade, not a default

    lz4, the default, is the fastest and compresses worst. zstd and brotli give roughly three times the ratio, lzma about six times and is much slower. On a cluster of this size the choice shows directly in the backup window and in the storage bill. 6

  • Retention is a dry run first

    wal-g delete only prints what it would remove; it deletes with --confirm. After a major upgrade it is given --use-sentinel-time, because ordering by backup name can then keep the old copies and remove the new. A backup that must stay is marked permanent. 3 6

  • The bucket protects itself

    The bucket is created with object locking, which turns versioning on. In compliance mode a locked version cannot be deleted by anyone, the root account included, until its retention ends. A backup that an attacker or a script can erase is not a backup. 7

  • One config on every host, one point for all

    On Greenplum the same wal-g config sits at the same path on every host, each segment archives under its own content ID, and a restore names a restore point and a file that maps content IDs to hosts, ports and data directories. 4

Where it breaks

  • A backup without its WAL is not a backup

    A restore needs an unbroken sequence of WAL from the moment the backup started. One missing file makes everything after it unreachable. That is why the chain is verified on a schedule, and a backup counts as done only once the WAL it needs is in the archive. 1 3

  • The last archived file proves nothing

    Files are not always archived strictly in order, so last_archived_wal does not mean that every earlier file is stored. And an idle server archives nothing until a segment fills, unless archive_timeout is set. 2 1

  • Archiving stops, the disk fills, the database stops

    While uploads fail, WAL stays on the server. When the file system that holds it is full, PostgreSQL shuts down in a panic. Failed archiving is an alert, not a line in a log. 1

  • Cleanup removes every version

    On a versioned bucket wal-g delete --confirm permanently removes all versions and delete markers. Versioning alone is therefore not a safety net against the cleanup job; a lock is. And lifecycle rules of the storage are a second thing that deletes: the two must not contradict each other. 5 7

  • Greenplum support has rough edges

    Continuous recovery is marked alpha and not recommended for production, and a partial restore works only under conditions. What matters is tried on a staging cluster before anyone relies on it. 4

What to check

  • pg_stat_archiver on every segment: failed_count is not growing, last_archived_time is recent.
  • The WAL chain has no gaps on any segment (on PostgreSQL this is what wal-g wal-verify checks).
  • A scheduled restore to a separate host, to a named restore point, ends with a cluster that answers queries.
  • The output of the retention dry run is read before --confirm is added.
  • A locked object in the bucket cannot be deleted before its retention ends: tried, not assumed.
  • One more copy lives outside the primary site.

Next deep dive

Deploying Greenplum 6 with Ansible

A repeatable Greenplum 6 rollout with Ansible: idempotent host preparation, a guarded one-time initialisation, mirrors on other hosts and a verification play that can fail.

Read Databases