Export and import a PostgreSQL database with a different name?

Posted by J. Pablo Fernández on Server Fault See other posts from Server Fault or by J. Pablo Fernández
Published on 2011-01-28T15:31:08Z Indexed on 2011/01/28 23:28 UTC
Read the original article Hit count: 292

Filed under:
|
|
|

Is there a way to export a PostgreSQL database and later import it with another name?

I'm using PostgreSQL with Rails and I often export the data from production, where the database is called blah_production and import it on development or staging with names blah_development and blah_staging. On MySQL this is trivial as the export doesn't have the database anywhere (except a comment maybe), but on PostgreSQL it seems to be impossible. Is it impossible?

I've seen out there some people using sed scripts to modify the dump. I'd like to avoid that solution but if there are no alternative I'll take it. Has anybody wrote a script to alter the dump's database name ensure no data is ever altered?

© Server Fault or respective owner

Related posts about database

Related posts about postgresql