pg_restore loads an archive made by pg_dump in custom, directory or tar format into a database: pg_restore -d target_db --no-owner -j 4 backup.dump. By default it does not stop at the first error: it carries on, prints errors ignored on restore: N at the end and exits with code 1, so a restore that “finished” can still be missing tables, owners or indexes.
This guide is about the restore side and its errors: every message below was reproduced in November 2026 on the official Docker images of PostgreSQL 16.16, 17.12 and 18.7, plus PostGIS 3.5.2 on PostgreSQL 17.5, with a 520 MB test database (two schemas, three tables, 6.2 million rows, foreign keys, a view and the pgcrypto extension). How to make the backup, choose the format and save roles with pg_dumpall --globals-only is covered in the pg_dump backup and restore guide.
pg_restore in 60 seconds
pg_restore -l backup.dump | head -15 # what is inside, and which pg_dump made it
createdb -O appuser shop_new # restore into a NEW, empty database
pg_restore -d shop_new -j 4 backup.dump # parallel restore (custom or directory format only)
pg_restore -d shop_new --no-owner -x backup.dump # roles missing on the target: skip owners and GRANTs
pg_restore -d shop --clean --if-exists backup.dump # overwrite objects in an existing database
pg_restore -d shop_new -e backup.dump # stop at the first error instead of carrying on
pg_restore -l backup.dump > full.list # selective restore: edit the list, then...
pg_restore -d shop_new -L full.list backup.dump # ...restore only the lines you kept
vacuumdb -d shop_new --analyze-in-stages # rebuild planner statistics afterwards
Two rules prevent most problems. Use a pg_restore binary at least as new as the pg_dump that wrote the archive (the client can be newer than the server). And restore into an empty database whenever you can: most of the errors below come from restoring on top of something that already exists.
How pg_restore handles errors (and why “ignore errors” is the default)
When a statement fails, pg_restore prints it and moves to the next object. This is what a restore onto a server without the original roles looks like:
$ pg_restore -h pg17 -U postgres -d shop shop.dump
pg_restore: error: could not execute query: ERROR: role "appuser" does not exist
Command was: ALTER SCHEMA sales OWNER TO appuser;
...
pg_restore: error: could not execute query: ERROR: role "reporting" does not exist
Command was: GRANT SELECT ON TABLE sales.order_lines TO reporting;
pg_restore: warning: errors ignored on restore: 9
$ echo $?
1
All the tables and the 2 million orders were there; what was lost were the owners and the permissions. That is the point of the default: a partial restore is often better than nothing at 3 a.m. The danger is in scripts that only look at the end of the log, or in a cron job that never checks the exit code. You have four ways to control the behaviour:
| Option | What happens on the first error | State of the database |
|---|---|---|
| (none) | Continues, prints errors ignored on restore: N, exit 1 |
Everything that could be restored |
-e, --exit-on-error |
Stops immediately, exit 1 | Half-built: in my test the sales schema existed, no tables |
-1, --single-transaction |
Stops and rolls back, exit 1 | Empty, as before the restore |
--transaction-size=N (17+) |
Commits every N objects, implies --exit-on-error |
Everything up to the last commit |
-1 is the cleanest choice for small and medium databases, but it cannot be combined with parallel jobs (cannot specify both --single-transaction and multiple jobs). For a large restore with -j, the practical approach is: restore into a new database, read the log, and if it is not clean drop that database and start again. Nothing in production has been touched in the meantime.
role “…” does not exist
The most common error, shown above. pg_dump saves a single database; roles belong to the cluster and are not in the archive. When the role is missing, the ALTER ... OWNER TO fails and the object stays owned by the user running pg_restore:
$ psql -d shop -Atc "select schemaname, tablename, tableowner from pg_tables where schemaname in ('public','sales')"
public|customers|postgres
sales|order_lines|postgres
sales|orders|postgres
Two fixes, depending on the target:
- Rebuilding production or a faithful copy: create the roles first, from
pg_dumpall --globals-onlyrun on the source server (the procedure is in the pg_dump guide), then restore without extra options. Owners and GRANTs come back exactly as they were. - Development, test, a laptop:
--no-owner(-O) and--no-privileges(-x). Every object belongs to whoever runs the restore and no GRANT is attempted. In my test the same restore ran with exit code 0.
Creating a role by hand with the same name works too, but only for the owner: the GRANTs to other roles (reporting here) will fail until those exist as well. To see in advance which roles the archive needs: the owner is the last field of each line of pg_restore -l, while the roles that receive permissions only appear in the SQL, pg_restore -f - backup.dump | grep -E '^(GRANT|REVOKE)'.
must be able to SET ROLE “appuser”
The non-superuser version of the same problem. I created a restorer role with only CREATEDB, made it the owner of the target database, and restored:
$ pg_restore -h localhost -U restorer -d u1 shop.dump 2>&1 | grep -E "ERROR|warning" | sort | uniq -c
5 pg_restore: error: could not execute query: ERROR: must be able to SET ROLE "appuser"
1 pg_restore: warning: errors ignored on restore: 5
Here the role exists, but a non-superuser can only hand objects to roles it is allowed to become. Either grant membership (GRANT appuser TO restorer;, which also lets restorer act as appuser) or use --no-owner. With --no-owner -x the restore finished cleanly, pgcrypto included: since PostgreSQL 13 it is a trusted extension that a database owner can create, so the extension ended up owned by restorer. Untrusted extensions still need a superuser.
“already exists”, duplicate keys and silently duplicated rows
Run the same restore twice into the same database and the second run produces dozens of errors like these:
pg_restore: error: could not execute query: ERROR: schema "sales" already exists
pg_restore: error: could not execute query: ERROR: relation "customers" already exists
pg_restore: error: COPY failed for table "customers": ERROR: duplicate key value violates unique constraint "customers_pkey"
DETAIL: Key (id)=(1) already exists.
pg_restore: error: could not execute query: ERROR: multiple primary keys for table "customers" are not allowed
pg_restore: warning: errors ignored on restore: 23
The noisy errors are harmless. The real damage is silent: CREATE TABLE fails, but pg_restore still loads the data into the existing table. Tables with a primary key reject the rows (that is the duplicate key error); a table without one accepts them all. In my test sales.order_lines, which has no primary key, went from 4,000,000 rows to 8,000,000 after the second run and 12,000,000 after the third, with no error mentioning that table.
The documented protection is --no-data-for-failed-tables: if the creation of a table fails, its data is skipped. Rerunning with that option on a database that was already populated, the only errors were already exists, with no duplicate key, and sales.orders stayed at 2,000,000 rows: the data of the failed tables was skipped. Better still, do not restore on top of an existing database at all; if you have to, use --clean.
Overwriting an existing database: --clean --if-exists
--clean drops every object in the archive before recreating it. On its own it fails on a database where those objects do not exist yet:
$ pg_restore -d shop3 --clean --no-owner -x shop.dump
pg_restore: error: could not execute query: ERROR: schema "sales" does not exist
Command was: ALTER TABLE ONLY sales.orders DROP CONSTRAINT orders_customer_id_fkey;
That is why it always goes together with --if-exists, which turns every DROP into DROP ... IF EXISTS. On the database with 12 million duplicated rows, --clean --if-exists took 15.5 seconds and left order_lines at the correct 4,000,000 rows. Two things it does not do:
- It only drops what is in the archive. A table
public.notescreated after the backup was still there afterwards.--cleanis not “make the database identical to the dump”. - It does not use CASCADE. A view created after the backup on top of a table in the dump blocks the drop:
pg_restore: error: could not execute query: ERROR: cannot drop table sales.orders because other objects depend on it
DETAIL: view public.big_orders depends on table sales.orders
HINT: Use DROP ... CASCADE to drop the dependent objects too.
Command was: DROP TABLE IF EXISTS sales.orders;
The table that could not be dropped then receives the data again: the same duplication described above. If the target may contain objects that are not in the backup, the reliable way to overwrite is to restore into a new database and swap the names:
createdb -O appuser shop_new
pg_restore -d shop_new -j 4 backup.dump # check the log: no errors
psql -d postgres -c "ALTER DATABASE shop RENAME TO shop_old" \
-c "ALTER DATABASE shop_new RENAME TO shop"
The rename only works when nobody is connected to shop, which is also the moment of the switch for the applications. shop_old remains as an immediate rollback.
--create and “database is being accessed by other users”
With --create (-C) pg_restore connects to the database given in -d (usually postgres), runs CREATE DATABASE with the name stored in the archive and restores into it. If that database exists you get ERROR: database "shop" already exists. Adding --clean makes it run DROP DATABASE IF EXISTS shop first, and that drop fails if anyone is connected. What happens next is the surprising part:
$ pg_restore -d postgres --create --clean --if-exists --no-owner -x shop.dump
pg_restore: error: could not execute query: ERROR: database "shop" is being accessed by other users
DETAIL: There is 1 other session using the database.
Command was: DROP DATABASE IF EXISTS shop;
pg_restore: error: could not execute query: ERROR: database "shop" already exists
Command was: CREATE DATABASE shop WITH TEMPLATE = template0 ENCODING = 'UTF8' LOCALE_PROVIDER = libc LOCALE = 'en_US.utf8';
...
pg_restore: warning: errors ignored on restore: 16
pg_restore did not stop: it connected to the old shop and restored into it, and order_lines went from 4 to 8 million rows. One forgotten psql session or connection pool is enough. Close the connections before you start (DROP DATABASE shop WITH (FORCE) since PostgreSQL 13, or pg_terminate_backend()), or add -e so that the first error ends the run.
unsupported version (1.16) in file header
$ pg_restore --version
pg_restore (PostgreSQL) 16.16 (Debian 16.16-1.pgdg13+1)
$ pg_restore -l shop.dump
pg_restore: error: unsupported version (1.16) in file header
The number is the archive format, not the PostgreSQL version. Each pg_dump writes the newest format it knows, and an older pg_restore refuses a format it does not understand. The header tells you who made the file (any recent pg_restore can read it):
$ pg_restore -l shop.dump | head -12
;
; Archive created at 2026-11-15 08:50:37 UTC
; dbname: shop
; TOC Entries: 25
; Compression: gzip
; Dump Version: 1.16-0
; Format: CUSTOM
...
; Dumped from database version: 18.7 (Debian 18.7-1.pgdg13+2)
; Dumped by pg_dump version: 18.7 (Debian 18.7-1.pgdg13+2)
| Archive written by | Dump Version | pg_restore 16 | pg_restore 17 | pg_restore 18 |
|---|---|---|---|---|
| pg_dump 16.16 | 1.15 | yes | yes | yes |
| pg_dump 17.12 | 1.16 | unsupported version (1.16) | yes | yes |
| pg_dump 18.7 | 1.16 | unsupported version (1.16) | yes | yes |
The fix is on the client side: install a newer pg_restore (on Debian and Ubuntu the postgresql-client-18 package from the PGDG repository) and point it at the old server. The client may be newer than the server, not the other way round. Many guides still suggest --ignore-version: that option no longer exists, pg_restore 16 answers unrecognized option '--ignore-version'.
In this test pg_restore 17 read the archive written by pg_dump 18 and restored it into PostgreSQL 17 without errors, because both use format 1.16 and the schema contained nothing specific to 18. That is luck, not a rule: the pg_dump documentation states that loading a dump into an older major version “is not guaranteed”, and may require editing the SQL by hand.
unrecognized configuration parameter “transaction_timeout”
The other side of restoring into an older server. With pg_restore 18 and a PostgreSQL 16 server:
$ pg_restore -h pg16 -U postgres -d shop --no-owner -x shop.dump
pg_restore: error: could not execute query: ERROR: unrecognized configuration parameter "transaction_timeout"
Command was: SET transaction_timeout = 0;
pg_restore: warning: errors ignored on restore: 1
transaction_timeout exists from PostgreSQL 17 on. This error is harmless: all 4,000,000 rows of order_lines were restored. It does turn the exit code into 1, and with -e or -1 it stops the restore at the very first statement. For a script that has to go through, generate the SQL with pg_restore -f shop.sql backup.dump, remove that line (line 13 in my file) and load it with psql -v ON_ERROR_STOP=1. If instead the error is pg_dump: error: aborting because of server version mismatch, the problem is the backup side: pg_dump must be at least as new as the server it reads.
extension “…” is not available
An archive only contains CREATE EXTENSION, not the extension itself. I dumped a database with PostGIS 3.5.2 and restored it into a plain PostgreSQL 17:
pg_restore: error: could not execute query: ERROR: extension "postgis" is not available
DETAIL: Could not open extension control file "/usr/share/postgresql/17/extension/postgis.control": No such file or directory.
HINT: The extension must first be installed on the system where PostgreSQL is running.
Command was: CREATE EXTENSION IF NOT EXISTS postgis WITH SCHEMA public;
pg_restore: error: could not execute query: ERROR: type "public.geometry" does not exist
LINE 4: pos public.geometry(Point,4326)
...
pg_restore: error: could not execute query: ERROR: relation "public.shops" does not exist
Command was: COPY public.shops (id, name, pos) FROM stdin;
pg_restore: warning: errors ignored on restore: 7
The first error explains the other six: without the extension the geometry type does not exist, so the table is not created and its data has nowhere to go. In a long log only the first error matters; the cascade that follows is a consequence. The fix is to install the extension package on the target server before restoring (for PostGIS on Debian/Ubuntu, postgresql-17-postgis-3), ideally in the same version as the source. Check what the source uses with SELECT extname, extversion FROM pg_extension; before the migration, not after.
Using the wrong tool or the wrong input
$ pg_restore -d postgres shop.sql
pg_restore: error: input file appears to be a text format dump. Please use psql.
$ cat shop.dump | pg_restore -d postgres -j 4
pg_restore: error: parallel restore from standard input is not supported
A plain-format dump (pg_dump without -F, or -Fp) is an SQL script: load it with psql -v ON_ERROR_STOP=1 -f shop.sql. Parallel restore needs a real file or directory, so download or decompress the archive to disk before running it with -j.
pg_restore: error: unable to find a dll needed by the utility (pgAdmin on Windows)
This message is not printed by pg_restore. It comes from pgAdmin 4, which in web/pgadmin/utils/constants.py maps the Windows exit code 3221225781 (0xC0000135, DLL not found) to the text “Unable to find a dll needed by the utility. Ensure .dll files needed by the utility are in the same folder as your executable.” In other words, Windows could not even start pg_restore.exe, because a library it depends on (typically libpq.dll and its dependencies) is not next to it.
It usually happens when pgAdmin is pointed at a folder containing a copied pg_restore.exe without its DLLs, or at the bin folder of an incomplete installation. I could not reproduce it in a Linux container, so this is based on the pgAdmin source and documentation. The fix is in pgAdmin under File > Preferences > Paths > Binary paths: per the pgAdmin preferences documentation, set the “PostgreSQL Binary Path” for your server version to the bin folder of a complete PostgreSQL installation (for example C:\Program Files\PostgreSQL\18\bin), the one that contains both pg_restore.exe and libpq.dll. Use a version at least as new as the pg_dump that made the backup, or you will move on to the unsupported version error described above.
Parallel restore with -j: how many jobs
With -j N pg_restore uses N connections: each loads a different table or builds a different index. On the test database, pg_restore 18 against PostgreSQL 18 on a 32-core machine:
| Archive | Command | Time |
|---|---|---|
| custom (31 MB) | pg_restore -j 1 |
16.8 s |
| custom | pg_restore -j 4 |
8.6 s |
| custom | pg_restore -j 8 |
8.4 s |
| directory | pg_restore -j 8 |
9.0 s |
| plain SQL (172 MB) | psql -f |
15.9 s |
From 4 to 8 jobs nothing changes: the archive has three tables, three indexes and two primary keys, and a single table is always loaded by one worker. The time is set by the largest table plus its indexes. The rule of thumb is to start from the number of CPU cores of the database server (not of the machine running pg_restore), capped at the number of large tables, and to check that max_connections has room for N extra connections. The custom format is enough for a parallel restore; the directory format only matters for a parallel dump.
Restoring a single table or schema: -t, -n and -L
This is where pg_restore behaves differently from what most people expect. Three tests, three surprises.
-t restores the table, not its primary key
$ pg_restore -d t1 -t customers shop.dump
$ psql -d t1 -Atc "select count(*) from customers"
200000
$ psql -d t1 -Atc "select count(*) from pg_indexes where tablename='customers'"
0
Data yes, primary key no. The pg_restore documentation says so explicitly: unlike pg_dump’s -t, it does not include subsidiary objects such as indexes, and makes no attempt to restore the objects the table depends on. The consequences show up later: when I then restored the sales schema, the foreign key to customers failed with there is no unique constraint matching given keys for referenced table "customers". To bring an index with you, add it by name with -I index_name; for a constraint, -L is the simpler route.
-n does not create the schema
$ pg_restore -d t2 -n sales shop.dump
pg_restore: error: could not execute query: ERROR: schema "sales" does not exist
LINE 1: CREATE TABLE sales.orders (
...
pg_restore: warning: errors ignored on restore: 17
-n restores the objects inside the schema, but the CREATE SCHEMA entry itself is not selected. In an empty database you get 17 errors and nothing restored. Create it first (CREATE SCHEMA sales AUTHORIZATION appuser;) and the same command restores tables, data and indexes.
-l and -L: the reliable way
The list shows every object in the archive, in restore order. You save it, keep the lines you need and pass the file back with -L:
$ pg_restore -l shop.dump > full.list
$ grep -E "(SCHEMA - sales|TABLE sales orders|TABLE DATA sales orders|orders_pkey|INDEX sales orders_)" full.list > orders.list
$ cat orders.list
7; 2615 16425 SCHEMA - sales appuser
222; 1259 16435 TABLE sales orders appuser
3497; 0 16435 TABLE DATA sales orders appuser
3344; 2606 16440 CONSTRAINT sales orders orders_pkey appuser
3341; 1259 16463 INDEX sales orders_created_at_idx appuser
3342; 1259 16462 INDEX sales orders_customer_id_idx appuser
$ pg_restore -d t3 -L orders.list shop.dump
$ psql -d t3 -Atc "select count(*) from sales.orders"
2000000
Schema, table, data, primary key and both indexes, exit code 0. The foreign key to customers was left out on purpose, because that table is not being restored. Instead of grep you can also edit the full list and comment out lines with a leading ;. To recover a few rows rather than a whole table, restore the table into a scratch database this way and copy the rows across with SQL.
For an even coarser cut there is --section: pre-data (tables, types, functions), data and post-data (indexes, constraints, triggers). Since PostgreSQL 18 there are also --no-schema, --no-data and --statistics-only.
After the restore: statistics and verification
A restored database has no planner statistics, and the first queries may get bad plans until autovacuum catches up. On PostgreSQL 18 pg_dump can save them, but it does not by default (--no-statistics is the default, per the pg_dump documentation). Measured on the test database:
$ pg_restore -l shop.dump | grep -c "STATISTICS DATA" # pg_dump 18, default
0
$ pg_dump -Fc --statistics -f shop_stats.dump shop
$ pg_restore -l shop_stats.dump | grep -c "STATISTICS DATA"
8
# after restoring each archive into a new database:
shop.dump -> pg_stats rows for sales.orders: 0
shop_stats.dump -> pg_stats rows for sales.orders: 4
With an archive without statistics, run vacuumdb -d shop --analyze-in-stages right after the restore: it produces rough statistics in seconds and refines them in two further passes, so the database is usable quickly. Then check what you restored, comparing against the source:
psql -d shop -c "SELECT schemaname, relname, n_live_tup FROM pg_stat_user_tables ORDER BY 1,2"
psql -d shop -c "SELECT count(*) FROM sales.orders" # exact count on the critical tables
pg_restore -l backup.dump | grep -c "TABLE DATA" # tables in the archive vs tables restored
A restore you have never tried is a hope, not a backup: the 3-2-1-1-0 backup rule ends with the 0 for exactly this reason, zero errors in a verified restore.
Summary: error, cause, fix
| Message | Cause | Fix |
|---|---|---|
role "x" does not exist |
Roles are not in the pg_dump archive | Load pg_dumpall --globals-only first, or --no-owner -x |
must be able to SET ROLE "x" |
Non-superuser cannot assign that owner | --no-owner, or GRANT x TO restorer |
relation "x" already exists |
Restoring on top of existing objects | New database, or --clean --if-exists; --no-data-for-failed-tables |
duplicate key value violates unique constraint |
Data loaded into a table that already had it | As above; check tables without a primary key |
cannot drop table x because other objects depend on it |
--clean does not cascade |
Restore into a new database and rename |
database "x" is being accessed by other users |
Open sessions during --create --clean |
Close them, DROP DATABASE ... WITH (FORCE), add -e |
unsupported version (1.16) in file header |
pg_restore older than the pg_dump that wrote the archive | Newer pg_restore client |
unrecognized configuration parameter "transaction_timeout" |
Archive from 17+ restored into 16 or older | Harmless; for scripts, edit the SQL from pg_restore -f |
extension "x" is not available |
Extension package missing on the target server | Install it, then restore |
input file appears to be a text format dump |
Plain SQL dump | psql -f |
parallel restore from standard input is not supported |
-j with a pipe |
Save the archive to disk first |
unable to find a dll needed by the utility |
pgAdmin on Windows, pg_restore.exe without its DLLs | Binary paths to a complete PostgreSQL bin folder |
Frequently Asked Questions
How do I make pg_restore ignore errors?
It already does by default: it skips every statement that fails, continues with the next object and ends with the warning errors ignored on restore followed by the number of errors, and exit code 1. Read the first error in the log, because the following ones are often a consequence of it. If you want the opposite, use --exit-on-error or --single-transaction.
How do I overwrite an existing database with pg_restore?
Use --clean together with --if-exists, which drops and recreates the objects contained in the archive. Objects created after the backup stay in place, and those that depend on restored tables block the drop. If the database may contain extra objects, restore into a new database and swap the names with ALTER DATABASE RENAME.
Can I restore a dump from a newer PostgreSQL version into an older server?
It is not guaranteed. You need a pg_restore at least as new as the pg_dump that made the archive, and the SQL may use features the old server does not have. In my tests a dump from 18 went into 17 without errors and into 16 with only the transaction_timeout error, but on a real schema you should expect to edit the generated SQL.
How many jobs should I use with pg_restore -j?
Start from the number of CPU cores of the database server and do not go beyond the number of large tables, because each table is loaded by a single worker. In my test four jobs halved the time and eight changed nothing. Each job is a connection, so check max_connections, and remember that -j cannot be combined with --single-transaction.
Why does pgAdmin say it cannot find a DLL needed by pg_restore?
Windows could not start pg_restore.exe because a library it needs, usually libpq.dll, is not in the same folder. In pgAdmin open the preferences, go to Paths and then Binary paths, and set the bin folder of a complete PostgreSQL installation, of a version at least as new as the one that created the backup.