TransWikia.com

Restoring multiple files to multiple database with pg_restore

Database Administrators Asked by Irakli Ugulava on September 2, 2020

I have multiple dump files and want to restore them with single command. something like this

pg_restore  -h localhost -p 5432 -U postgres 
    -d gl_election gl_world gl_tourism 
    -c "gl_election" "gl_world" "gl_tourism"

This command doesn’t work and I can’t find how to do it correctly. It works fine for one file.

One Answer

pg_restore doesn't take multiple filenames, nor multiple databases (-d) end of story. So use a simple shell loop. I assume you're trying to

  1. Clear out the old database
  2. Load up a dump to the database with the same name

That loop will look like this

for dump in gl_election gl_world gl_tourism; do
  echo Clearing and reloading "$dump"
  pg_restore -h localhost -p 5432 -U postgres -d "$dump" -c "$dump"
done;

Answered by Evan Carroll on September 2, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP