Skip to content

Instantly share code, notes, and snippets.

@meagar
Created August 14, 2013 17:19
Show Gist options
  • Save meagar/6233236 to your computer and use it in GitHub Desktop.
Save meagar/6233236 to your computer and use it in GitHub Desktop.

This is a really fast way to restore a large Postgres database by omiting the indexes and restoring them later (if necessary).

  1. Dump database.

    pg_dump -Fc --no-owner my_db -f ~/my_db.dump

  2. Create the summary files. One for the indexes and another for everything else.

    pg_restore -l ~/my_db.dump | grep -v 'INDEX public' > ~/my_db.list pg_restore -l ~/my_db.dump | grep 'INDEX public' > ~/my_db-indexes.list

  3. Restore everything except the indexes (should be pretty fast).

    pg_restore --no-owner --jobs=4 --verbose --use-list=$HOME/my_db.list --dbname=my_db ~/my_db.dump

  4. If desired, restore the indexes (this part's slow and index creation locks the database).

    pg_restore --no-owner --jobs=4 --verbose --use-list=$HOME/my_db-indexes.list --dbname=my_db ~/my_db.dump

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