pg_restore restores a PostgreSQL database from an archive file created by pg_dump.
pg_restore
[connection-option...] [option...] [filename]
Example:
We have
dumped a database called mydb into a custom-format dump file:
pg_dump
-Fc mydb > db.dump
To drop
the database and recreate it from the dump:
$
dropdb mydb
$
pg_restore -C -d postgres db.dump
The
database named in the -d switch can be any database existing in the cluster; pg_restore only uses it to issue the
CREATE DATABASE command for mydb. With -C, data is always restored into the
database name that appears in the dump file.
To reload the dump into a new database
called newdb:
$
createdb -T template0 newdb
$
pg_restore -d newdb db.dump
Notice we don't use -C, and instead connect
directly to the database to be restored into. Also note that we clone the new
database from template0 not template1, to ensure it is initially empty.
No comments:
Post a Comment
If you have any doubt or question, please contact us.