Running PostgreSQL on ZFS: when the file system choice matters
Choosing ZFS for PostgreSQL changes how you protect data, so decide early whether the storage layer or the database owns each recovery step. PostgreSQL's continuous archiving model is built on a base backup plus archived WAL files, which together allow point-in-time recovery. The PostgreSQL continuous archiving docs describe this model in database terms. A ZFS snapshot is a storage-level tool. It captures the file system at one instant, and it only yields a consistent PostgreSQL copy if the database is in a state the docs allow for that copy. Treat snapshots as a complement to base backups and WAL archiving, not a replacement for them, unless your team has tested that the combination restores correctly.
Confirm three things with your storage and database owners before you rely on snapshots. First, whether the snapshot procedure puts PostgreSQL into a consistent backup state, and whether WAL covering the snapshot window is archived so recovery can reach a chosen point in time. Second, whether PGDATA and any separate WAL location sit on datasets that are snapshotted together, so a restore does not pair data files from one moment with WAL from another. Third, who runs the restore and how long it takes on your hardware, which you should measure rather than assume. Ask your team to write these answers down as part of the backup runbook.
Snapshots also make clones easy, which is useful for test environments and for checking an upgrade, but a clone started from a snapshot is still a PostgreSQL instance that must be started and validated. Keep clones on a separate host or network segment with credentials scoped for that purpose, and confirm that any replication or archiving settings copied with the data cannot send clone WAL back into production archives. The PostgreSQL high availability docs cover the replication behavior you need to plan around.
Dataset options for PostgreSQL and when each fits
This table compares the main ZFS dataset settings for PostgreSQL data, WAL and temporary files, with the workload that favors each choice and the trade-off it carries. Read each row as a starting point to test in your own environment, since the right value depends on write pattern, memory and how the cluster is used.
| Setting | When it fits | Trade-off to weigh |
|---|---|---|
| recordsize on the data dataset | Random-access heap and index files, where a smaller record matches PostgreSQL's 8 kB page size; test values against your workload before settling on one | Smaller records raise metadata overhead and can increase fragmentation; larger records suit sequential scans but may rewrite more data per small update |
| recordsize on the WAL dataset | Sequential, append-only WAL writes, usually on a dedicated dataset so WAL does not share settings with data files | Tuning for large sequential writes helps append patterns but offers little benefit for random reads, so WAL needs its own dataset to keep the trade-off contained |
| compression | Most PostgreSQL datasets benefit from a lightweight algorithm; confirm current compression options and their CPU cost on your ZFS release before enabling | Compression reduces space and I/O volume but adds CPU use on write and read paths, and already compressed or encrypted data gains little |
| atime | Generally off for database datasets, since reads do not need access-time updates and each read would otherwise trigger a metadata write | Disabling access time removes a utility feature that some administrators use to find recently read files, which rarely matters for database directories |
| primarycache | Set to metadata or all according to whether PostgreSQL's shared buffers or the OS cache should hold the data; check how much memory the host keeps for ARC | Caching data in ARC as well as shared buffers can hold the same pages twice, while limiting the cache reduces the benefit of repeated reads from the OS |
| secondarycache | Relevant only where an L2ARC device exists; confirm the device and its role before setting this | An L2ARC adds memory overhead for its index and only helps when the working set exceeds RAM, so it may not justify cost for most clusters |
| logbias | Latency for small synchronous writes such as WAL commits; latency is the usual priority for OLTP, while throughput suits bulk loads | Changing logbias alters how synchronous writes are handled, so test commit latency and throughput together before changing it on a production dataset |
| Separate log device (SLOG) | Useful when synchronous write latency limits commits and the device has power-loss protection; confirm this with your storage vendor | A SLOG adds hardware to protect and monitor, and without power-loss protection it may not improve safety or speed |
ARC versus PostgreSQL shared buffers and the OS cache
On a dedicated database server, ZFS ARC, PostgreSQL shared_buffers and the kernel page cache all draw from the same physical memory. ARC is ZFS's own read cache in kernel memory and it grows to use free RAM by default, so it will not hand memory back to PostgreSQL on its own. PostgreSQL relies on the operating system cache for data beyond shared_buffers, which means ARC effectively becomes the second cache layer for the same pages. Sizing starts by deciding how much memory PostgreSQL, its connections and work memory need at peak, then capping ARC for the rest.
- Cap ARC explicitly: On Linux with OpenZFS, set the
zfs_arc_maxmodule parameter (in bytes) so ARC cannot consume memory that PostgreSQL needs at peak. - Account for double caching: Data read through ARC and also held in shared_buffers occupies memory twice, so a small shared_buffers with a large ARC may still work well, while a large shared_buffers can leave ARC with little value.
- Watch for memory pressure: Confirm the kernel does not swap or reclaim aggressively during peak load, since swapping database memory is far worse than a modest cache miss rate.
- Measure ARC hit ratio and size: Read ARC statistics under a realistic workload and record size and hit ratio before and after changes.
- Confirm the kernel version behavior: Check your OpenZFS release notes for the current ARC limit behavior and parameter names before you change them in production.
Before you go live, confirm the combined peak of PostgreSQL, connections and ARC leaves headroom in a load test that includes a checkpoint and a backup run.
When PostgreSQL runs in a virtual machine on a hypervisor, memory has two owners: the guest operating system, which runs ZFS and PostgreSQL, and the hypervisor, which may overcommit or balloon guest memory. ARC inside the guest can grow to fill memory the guest reports as free, which makes the guest look busy even when the hypervisor has allocated the memory elsewhere. The guest's sizing must match memory that is actually reserved for that VM, not what the hypervisor might lend. Disk layout matters too, because ZFS on top of virtual disks that already cache writes adds another layer to reason about.
- Reserve guest memory: Where the platform allows, reserve or pin the VM's memory so ARC and PostgreSQL are not competing with other guests for host RAM.
- Disable or limit ballooning: Ballooning can reclaim memory from the guest under pressure, which causes unpredictable latency for both ARC and PostgreSQL.
- Size ARC against the VM, not the host: Set
zfs_arc_maxrelative to the guest's assigned memory and the PostgreSQL configuration inside it. - Check the virtual disk path: Confirm with the hypervisor vendor how virtual disk caching and flush behavior reach ZFS, since this affects whether PostgreSQL's fsync calls are honored.
- Test migrations and live moves: Measure ARC warm-up time after a live migration or restart, because a cold ARC can change latency for a period after the move.
Confirm the reserved memory, balloon settings and disk cache mode with your hypervisor administrator before fixing ARC limits.
On a container host, PostgreSQL runs in a container while ZFS and ARC run in the host kernel. Container memory limits, typically set with cgroups, constrain the PostgreSQL process and its page cache charge, but they do not limit ARC, which lives in the host kernel and is not charged to the container. A container can therefore appear to have plenty of memory while the host's ARC takes most of it, or the reverse if ARC is capped and the host is under-used. The sizing has to be done on the host as a whole, with the container limit set to match what PostgreSQL needs.
- Set ARC on the host: Configure
zfs_arc_maxon the host kernel, not inside the container, because the container runtime cannot cap ARC. - Align container limits with shared_buffers: Set the container memory limit above shared_buffers plus connection and work memory, so the kernel does not terminate the PostgreSQL process.
- Plan for other tenants: If other workloads share the host, account for their memory in the ARC cap, since ARC does not know which container owns which blocks.
- Mount the dataset deliberately: Confirm the PGDATA directory sits on the dataset you tuned, not on an overlay or a volume path with different properties.
- Verify cgroup accounting: Read the container memory statistics under load to confirm the limit is not reached during checkpoints.
Before deployment, confirm with the platform team who owns the host ARC setting and whether any other workload's memory has been counted against the cap.
Setting up ZFS datasets for a PostgreSQL cluster
This sequence turns bare disks into a ZFS pool with separate, correctly tuned datasets for PGDATA, WAL and the WAL archive, so each node is configured before PostgreSQL writes its first byte. Each step ends with a check you can run and record.
Confirm the hardware and vdev layout
The storage or platform engineer lists the disks, controllers and write cache behavior on each database node, then chooses the vdev layout (mirrors, RAIDZ or a mix) based on the failure tolerance and capacity the team has agreed. Ask the storage vendor and your ZFS distribution to confirm how the controller handles flushes and whether it has a protected write cache, because PostgreSQL depends on those guarantees. The step is done when the layout is written down with the disk IDs, the controller model and the expected usable capacity, and a peer has reviewed it.
Create the pool with safe defaults
The administrator creates the pool with
zpool createusing stable device paths such as /dev/disk/by-id, setsashiftto match the physical sector size, and turns on the pool properties the team has agreed for this node. Confirm the sector size of each drive with the vendor documentation before choosingashift, since a wrong value cannot be corrected later without rebuilding the pool. The step is complete whenzpool statusshows every device online with no errors andzpool get ashiftreturns the intended value.Create separate datasets for PGDATA, WAL and archive
The administrator creates distinct datasets for the data directory, the WAL directory (pg_wal) and the WAL archive or backup target, so each can carry its own properties and snapshot schedule. Keeping them apart lets you snapshot or replicate the archive without touching the live data set, and it keeps the WAL write pattern from competing with table I/O. The step is done when
zfs listshows the three datasets with the expected mountpoints and each mount is owned by the PostgreSQL service account.Set dataset properties before initdb
Before PostgreSQL writes any data, the administrator sets
recordsize,compression,atime,logbiasandprimarycacheon each dataset according to the workload, and records the reasoning in the build notes. Choose therecordsizefor PGDATA and the WAL dataset based on the PostgreSQL page size and the storage team's benchmark results, and confirm the compression algorithm supported by your ZFS release with its documentation. Runzfs get allon each dataset and save the output, since most of these properties apply only to new writes and changing them later does not rewrite existing blocks.Align PostgreSQL settings with the storage layout
The DBA sets the PostgreSQL configuration to match the storage design, covering
data_directory, the WAL location,full_page_writes,wal_compression, and the memory settings that decide how much work the OS cache does compared withshared_buffers. Leavefull_page_writeson unless the storage team can prove a torn-page-safe guarantee for the full stack, and confirm that statement with the filesystem documentation before any change. The step is done whenSHOWreturns the expected values after a restart and the configuration is stored in version control.Initialize the cluster and verify the dataset properties
The DBA runs
initdbagainst the PGDATA dataset and starts the service, then checks that the cluster sits on the intended dataset and that the properties match the build notes. Usezfs geton each dataset andSHOW data_directoryin PostgreSQL to confirm the paths, and run a short write and checkpoint test to confirm that the WAL dataset receives the expected traffic. The step is complete when the output of both checks is saved alongside the build record and no property differs from the plan.Schedule snapshots and prove a restore
The backup owner sets a snapshot schedule for the data and archive datasets, and then runs a test restore by cloning a snapshot to a scratch host, starting PostgreSQL on it, and checking that the database reaches a consistent state and that the expected rows are present. Snapshots on ZFS are consistent only for the data the application has flushed, so confirm with your backup design whether they are used alone or with WAL archiving and a base backup. The step is done when a restore has been completed and timed, the result is recorded, and the team has written down what the snapshot does and does not protect.
How the ZFS datasets, PostgreSQL directories and backup copies fit together
The diagram starts at the ZFS pool, which holds separate datasets for PGDATA, WAL and the archive. The PostgreSQL instance writes into the data and WAL datasets, and archived WAL plus base backups move into the archive dataset. Snapshots of the data dataset can be cloned for test restores without touching production. Check that each dataset's settings match its workload, and that a snapshot-based backup is paired with a WAL archive that can roll forward to a chosen point in time.
Datasets for data, WAL and archive, with snapshot clones for test restores.
Full-page writes and why ZFS snapshots are not a backup on their own
A ZFS snapshot is an atomic point in time for the dataset, but PostgreSQL does not treat a dataset as a consistent copy unless it has been told to. Its data files are changed in place while the server runs, and a page can be half written when the snapshot is taken. To survive a crash, PostgreSQL relies on full-page writes: after a checkpoint, the first change to any data page is logged in the write-ahead log (WAL) as a complete copy of that page, so recovery can rebuild a torn page from the log. Setting full_page_writes to on is the default and should stay on unless your storage layer makes torn pages impossible and you have verified that claim. Check the setting with your team before changing it on ZFS, and confirm your storage behavior with the vendor or your own tests rather than assuming it.
A snapshot taken without coordination is crash-consistent at best. Its data files may reflect writes that have not been fully flushed in a matching state, and it carries no record of where a restore should stop. The PostgreSQL continuous archiving documentation describes the supported method: call pg_backup_start (named pg_start_backup in releases before 15), take the copy, then call pg_backup_stop, which returns the backup label that must be stored with the copy. Archiving WAL with archive_mode and archive_command, or a tool that does the same, is what makes point-in-time recovery possible, because it lets you replay changes after the snapshot up to a chosen moment. Keep the WAL archive on a separate device or host from the dataset it protects.
Before relying on ZFS snapshots for backups or clones, ask your team to write a runbook that wraps each snapshot in the start and stop calls, stores the backup label with it, and ships WAL to a location that survives loss of the pool. Then restore a snapshot clone to a scratch server, start it, and confirm it reaches a consistent state and can replay archived WAL to a target time. Record how long the restore took and whether it matched your recovery targets. A snapshot that has never been restored is a hypothesis, not a backup. Your own environment, not a general figure, determines how often this test should run.
Using ZFS snapshots safely for backups and clones
ZFS snapshots are fast and cheap, but a snapshot of a running PostgreSQL data directory is only a valid backup when it is taken and restored in a controlled way. The cards below cover the procedure, off-site copies, retention, restore testing and the clone pitfalls that turn a test copy into an accidental primary.
Take consistent snapshots
A crash-consistent snapshot captures the data files and WAL together, but it is only safe when PostgreSQL's write-ahead log, the data directory and any tablespaces sit on datasets that are snapshotted at the same moment. Use a recursive snapshot of the parent dataset, or a pre-snapshot step such as pg_backup_start() followed by pg_backup_stop() so the backup label is captured. Confirm the procedure with your own environment before relying on it.
Pair snapshots with WAL archiving
A snapshot gives you one point in time. To recover to a later moment, you also need archived WAL files that were written after the snapshot. Without archiving, the snapshot is the only recovery point and the recovery point objective is set by how often you snapshot. Plan the archive destination and check that WAL segments reach it before you rely on point-in-time recovery.
Replicate snapshots off site
A snapshot on the same pool does not protect against pool loss, controller failure or deletion of the source dataset. Send snapshots with zfs send to a second pool or host in another failure domain, and use incremental sends so transfers stay small. Record which snapshot is the last one received, and test that the receiving side holds a complete, mountable copy.
Set retention by recovery needs
Retention should follow the recovery scenarios you must survive: a bad deployment discovered the same day, a data change found a week later, or an audit request for an earlier state. Keep frequent short-term snapshots and fewer long-term ones, and make the pruning job explicit. Confirm retention with the team that owns the data, since snapshot storage grows with changed blocks and long retention can fill the pool.
Test restores from clones
A ZFS clone is a writable copy that shares blocks with its snapshot, so it is a fast way to start PostgreSQL from a point in time and check that it recovers, runs queries and passes integrity checks. Run the test on a separate host or with a different port and data directory, and remove the clone when the test ends. A restore that has never been started is not yet a verified backup.
Keep clones out of production
A clone started with the production configuration can accept writes, run cron jobs or attach to replication slots that belong to the real primary. Before starting any clone, change its postgresql.conf and pg_hba.conf so it cannot be reached by application traffic, remove or disable archive_command and scheduled jobs, and document that it is a test copy. If a clone must become a primary, treat that as a planned recovery with its own runbook.
Questions teams ask before running PostgreSQL on ZFS
What drives the cost of running PostgreSQL on ZFS?
The cost depends mostly on how many database servers and datasets are involved, how many recovery paths must be tested, and how much of the design is new to your team. Each cost component has a different payer: your team pays for hardware, storage and licences you choose, while an implementation partner is paid for the design, build, tuning and testing work described in a written scope. Recurring costs include storage growth, snapshot retention capacity, patching and periodic restore tests. Ask any quote to separate one-time build work from recurring support and to name which datasets, servers and recovery tests are included.
How long does it take to build and test a ZFS layout for PostgreSQL?
Duration depends on the number of servers, the number of datasets per cluster, whether replication and backups already exist, and whether the restore procedure must be proven before go-live. The longest part is rarely the ZFS commands themselves. It is the restore testing, the benchmarking of recordsize and compression against your real workload, and the runbooks that your operators will use during an incident. Ask for a written timeline that lists each test, who runs it and what evidence it produces, rather than relying on a single estimate.
What does our team need to provide for a ZFS PostgreSQL engagement?
Your team needs to provide access to the target servers and storage, a clear picture of the workload (write volume, table sizes, peak connections and recovery point targets), and a named owner who can approve storage and retention decisions. Engineers who will operate the system should take part in the design reviews and restore tests, because the snapshot schedule and dataset layout only work if they understand them. You should also confirm which change windows and maintenance policies apply, since ZFS changes and PostgreSQL restarts both need them.
Can our own team set up PostgreSQL on ZFS without a partner?
Yes, a capable team with ZFS and PostgreSQL experience can build this internally. The skills that matter most are dataset design, understanding how PostgreSQL writes WAL and data files, a tested backup and restore process and disciplined change control. The risk is usually not the initial build but the gap between a working setup and one that has been restored from end to end under pressure. Decide early whether your team will own ongoing tuning, upgrades and restore drills, and whether you want an external review of the design before it goes live.
Does ZFS snapshotting replace PostgreSQL backup tools?
No. ZFS snapshots are useful for fast copies and clones, but they are not a complete backup strategy on their own. A snapshot taken without coordination can capture the data directory in an inconsistent state unless PostgreSQL is put into backup mode or the snapshot is taken in a way your team has verified. Point-in-time recovery still depends on archived WAL files and a base backup, as described in the PostgreSQL continuous archiving documentation. Plan snapshots alongside WAL archiving, store copies off the primary server, and prove restores work on a schedule.
What goes wrong most often with ZFS and PostgreSQL?
The most common problems are mismatched recordsize settings across WAL and data datasets, snapshots that were never restored in a test, compression and ARC sizing choices made without measuring the workload, and disks filling up because snapshot retention was not sized. Teams also sometimes assume the operating system cache will help PostgreSQL in the same way it does for other applications, which affects how much memory is left for shared buffers. Ask for a checklist of these checks and verify each one on your hardware before go-live.
How does ZFS affect full-page writes and the cost of WAL?
Full-page writes protect PostgreSQL against torn pages after a crash, and their volume depends on checkpoint frequency and workload, not on ZFS alone. ZFS copy-on-write behavior and the recordsize you choose can change how much I/O the storage layer performs for those writes, so the effect should be measured rather than assumed. Confirm with your own test data how WAL volume changes after you tune the datasets, and keep WAL on a dataset configured for its write pattern.
How DeployOpen scopes and delivers PostgreSQL storage on ZFS
DeployOpen plans, implements, tests and documents the ZFS storage design for PostgreSQL inside your own infrastructure, whether that is bare metal, a virtualized host or an air-gapped network. The work starts with a written scope that names the pools and vdevs, the datasets for data, WAL and backups, the recordsize, compression and atime settings per dataset, the snapshot schedule and retention, and how the design interacts with your PostgreSQL version, replication topology and backup tooling. Because most engagements are fixed-scope, the scope, deliverables and timelines are agreed in writing before any build starts, and the quote follows from that document. Ask for the scope to list each item explicitly so you can see what is excluded.
Delivery centers on proof rather than configuration files alone. DeployOpen builds the dataset layout in a staging environment you designate, runs write-heavy and crash-recovery tests against it, and restores from both snapshot-based and PostgreSQL-native backups into a separate host to confirm that the recovery point and recovery time you need are achievable. The output is a design document, a runbook for snapshot creation, replication and clone use, and the restore evidence, so your storage, database and security teams can review what was built. Ask any partner to show the restore test results and the exact commands used, and confirm who owns the production change window and rollback plan.
Ongoing work is handled through retainers, which can cover ZFS pool maintenance, OpenZFS upgrades, periodic restore tests, snapshot policy reviews and PostgreSQL major upgrades that touch the storage layout. Confirm with the partner which parts of this support are included, how change requests are priced and how quickly they respond to incidents, because those terms belong in the written agreement rather than in general statements. Organizations with formal audit or continuity requirements should also confirm with their own auditors which evidence they need, since DeployOpen prepares systems, controls and evidence but does not issue audit reports or certifications.

