How to Choose a Database Storage Format for Long-Term Portability

A portable database storage format is one you can read without the tool that wrote it, on a machine you do not own yet, using only software you can still obtain. The safest choice is a plain SQL text dump from a relational engine whose file format is documented, combined with keeping the schema and the data in the same file. Everything else, including the engine you pick, is a trade between how much structure you want to keep and how much freedom you want later.

This is not really a question about which database is best. It is a question about what survives a move: the bytes on disk, the tool that reads them, and the person who has to restore them without help. A portable database storage format is the one that still opens when two of those three have changed.

What actually makes a storage format portable

Start with the difference between the storage format and the dump format. The storage format is what the engine writes to its data directory: page files, WAL or redo logs, a control file, a system catalog. The dump format is what a logical export tool produces: text or a binary archive of statements and rows. The storage format is tied to one engine version and often to one architecture. The dump format is tied to a parser, and parsers are far easier to reimplement than page layouts.

So a dump is portable in a way a data directory is not. But not all dumps are equal. A plain SQL text dump is readable with `cat`, diffable, and greppable. A custom binary archive is faster to restore and supports selective restore, but you need the matching restore tool. A physical base backup is not portable at all across major versions. Choose the format whose reader you could plausibly write yourself if the vendor disappeared.

Then look at the header. Most dump formats begin with a magic string and a version number. If you are unsure what you are holding, read the first bytes:

head -c 64 dump.sql
head -c 16 dump.custom | xxd

A text dump starts with comments or SET statements. A custom archive starts with a magic block that names the format and its version. If you cannot identify the file from its first line, that is a warning sign for a restore you will attempt years from now.

Choosing an engine with a portable database storage format in mind

Favour engines that separate the catalog from the data files and document both. A relational engine that lets you export schema and data as SQL, and import that SQL into a different major version, gives you the widest escape route. Engines that keep everything in one opaque file, or that require a proprietary client to read their own backups, are portable only as long as that client exists.

Two practical checks. First, can you create a dump with a single command and no running server, from a stopped copy of the files? Second, can you load that dump into a fresh instance of the same engine on a different OS without editing it? If the answer to both is yes, you have a format worth keeping. If either is no, the format is a lock-in risk regardless of how good the engine is day to day.

Text formats age well because the syntax is stable and the encoding is explicit. Watch for encoding and collation though: a dump that assumes one locale can restore into garbage text elsewhere. Set the client encoding explicitly at dump time and check the header records it.

pg_dump --format=plain --encoding=UTF8 \
  --schema-only mydb > schema.sql
pg_dump --format=plain --encoding=UTF8 \
  --data-only mydb > data.sql

Keeping schema and data in separate files makes it easy to diff the structure between environments and to reload data without touching indexes. It also makes the dump readable in a code review, which is where you will catch a dropped column before it reaches production.

Testing that the format survives a move

A dump you have never restored is a hope, not a backup. The only way to know a portable database storage format works is to restore it on a clean machine with a different engine version, or at least a different OS, and run a query that touches every table. Do this on a schedule, not once.

createdb restore_test
psql -v restore_test < schema.sql
psql -v restore_test < data.sql
psql restore_test -c "\dt"

The ON_ERROR_STOP flag matters. Without it, a load can fail halfway and still exit zero, leaving you with a partial database and no clear signal. Check the row counts against the source before you trust the restore. If the counts differ, the dump or the load is wrong, and you want to find that out now rather than during a migration.

Also test the reverse direction: export from the new host back to a plain dump and diff it against the original. A round trip that loses no rows and keeps the schema identical is the strongest evidence that the format is portable. If the round trip changes column order or type widths, note that in the runbook so the next person is not surprised.

Config and conventions that keep you free

The engine matters less than the habits around it. Keep the dump command in version control next to the schema, so the exact flags that produced a file are recorded with it. Set a default encoding and timezone in the dump command rather than relying on the server's locale. Avoid features that have no equivalent elsewhere unless you have decided the lock-in is worth it.

Store at least one copy in a plain text format even if your primary backup is a binary archive. Text is the format most likely to be readable by something you have not installed yet. And keep the restore instructions in the same place as the dump, written for someone who has never seen your setup.

Do not name a company in your runbook as the only way to read a file. Name the format and the command. If your notes say "ask the vendor," the format is not portable, whatever its header claims.

What to do next

Take your current database, produce a plain SQL dump with an explicit encoding, and restore it into a fresh instance on a different machine. Time the restore, check the row counts, and write down every step you had to guess. That document, plus the dump command, is your portability plan. Repeat the restore on a schedule so the plan stays true, and keep one plain text copy of the data somewhere you can reach without any particular vendor's tooling.

Related articles

Subscribe to our newsletter

Get the latest hosting tips, performance insights, and industry news.