pg_restore Command Generator
Restoring a PostgreSQL dump goes wrong in the same few ways every time: the archive format does not match the tool, -j is silently ignored, ownership errors flood the log, or a half-finished restore leaves the database in a broken state. Fill in your dump file, target database and connection details below and this generator writes the exact pg_restore command — or the psql command, when your dump is a plain SQL script — along with a full runbook: inspect the archive, create the database, restore, and verify. Everything is generated in your browser; no dump file or credential is uploaded.
Do more than pg_restore command generator — meet Chat2DB
Chat2DB is an AI-powered SQL client for Windows, macOS and Linux. Write SQL in natural language, format and optimize queries automatically, and manage MySQL, PostgreSQL, Oracle and 20+ other databases in one workspace.
How to use
- Pick the format your dump was created with (custom/directory/tar from pg_dump -Fc/-Fd/-Ft, or plain for a .sql script) and enter the file path and target database.
- Toggle the options you need — clean before restore, no owner, schema or data only, parallel jobs, single transaction — and the command updates live.
- Copy the command, or use the full runbook below it to inspect the archive first and verify the restore afterwards.
Frequently asked questions
How do I restore a PostgreSQL database from a dump file?
It depends on how the dump was created. For an archive made with pg_dump -Fc, -Fd or -Ft, run pg_restore -h host -U user -d target_db mydb.dump. For a plain .sql dump made without a format flag, pg_restore cannot read it — replay the script with psql -h host -U user -d target_db -f mydb.sql instead. If the target database does not exist yet, create it first with createdb, or pass -C to pg_restore and point -d at the postgres maintenance database.
What is the difference between pg_restore and psql for restoring?
pg_dump can write two kinds of output. Plain format is a SQL script that you replay with psql, which executes it top to bottom with no ability to reorder or filter. The custom, directory and tar formats are archives with a table of contents, and pg_restore reads them — which is what unlocks selective restores with -t and -n, listing contents with -l, reordering via -L, and parallel restore with -j. If you expect to restore selectively or quickly, dump with -Fc or -Fd.
Why does my pg_restore fail with role or ownership errors?
The dump records the roles that owned each object, and those roles usually do not exist on the machine you are restoring into. Add -O to skip the ALTER ... OWNER TO statements, so everything ends up owned by the connecting user, and -x to skip GRANT/REVOKE statements as well. Note that by default pg_restore reports these as errors but still exits 0 — pass -e or --single-transaction if you want the restore to stop on the first real failure. To browse the restored schema and run checks with AI-assisted SQL, try Chat2DB: download at https://chat2db.ai/download or use https://app.chat2db.ai.
