Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I want to restore the database with a different schema

I have taken a dump of a database named temp1, by using the follwing command

$  pg_dump -i -h localhost  -U postgres -F c -b -v -f pub.backup temp1  

Now I want to restore the dump in a different database called "db_temp" , but in that I just want that all the tables should be created in a "temp_schema" ( not the default schema which is in the fms temp1 database ) which is in the "db_temp" database.

Is there any way to do this using pg_restore command?

Any other method also be appreciated!

like image 656
abubacker Avatar asked Nov 16 '10 06:11

abubacker


People also ask

How do I restore a Database from one Database to another?

Connect to the appropriate instance of the SQL Server Database Engine, and then in Object Explorer, select the server name to expand the server tree. Right-click Databases, and then select Restore Database. The Restore Database dialog box opens. Select the database to restore from the drop-down list.

How do I restore a SQL Database from a BAK file to a new Database?

Restore the database from a BAK fileRight-click on the database server in the left navigation pane, click Tasks, click Restore. The name of the restoring database appears in the To database list box. To create a new database, enter its name in the list box. Select 'From device'.


1 Answers

A quick and dirty way:

1) rename default schema:

alter schema public rename to public_save; 

2) create new schema as default schema:

create schema public; 

3) restore data

pg_restore -f pub.backup db_temp [and whatever other options] 

4) rename schemas according to need:

alter schema public rename to temp_schema; alter schema public_save rename to public; 
like image 63
shaunc Avatar answered Oct 04 '22 13:10

shaunc