Skip to content

Instantly share code, notes, and snippets.

@jeremykendall
Last active April 27, 2021 20:27
Show Gist options
  • Save jeremykendall/1a1151c2082c40bb566a to your computer and use it in GitHub Desktop.
Save jeremykendall/1a1151c2082c40bb566a to your computer and use it in GitHub Desktop.
PostgreSQL: dump and restore (to db with different name and roles even)

Postgres Export and Import

Export

pg_dump -U [superuser] -Fc [dbname] > db.dump

Import

This syntax allows importing to a database with the name of your choice.

Create the database (if it does not exist):

createdb -T template0 [dbname]

Import:

pg_restore --clean --if-exists --no-acl --no-owner --verbose -d [dbname] -U [superuser] db.dump

Reference

@at-longhoang
Copy link

i got this error pg_restore: [custom archiver] could not read from input file: end of file

@juniorUsca
Copy link

juniorUsca commented Jul 11, 2018

@at-longhoang your file dumped db.dump has been corrupted. You need to regenerate it

@aksharj
Copy link

aksharj commented Sep 24, 2020

hi,

I am facing the same issue pg_restore: [custom archiver] could not read from input file: end of file and regenerating did not fix the issue. Any ideas?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment