How to rename a database in 6.3.2 - Mailing list pgsql-general

From Douglas T. Brown
Subject How to rename a database in 6.3.2
Date
Msg-id 3651AC14.4413C278@gwi.net
Whole thread Raw
List pgsql-general
The General mail list archive does cover this, but for novices like me a more
explicit set of directions might be helpful.  Here's my attempt to contribute,
but I make no guarantees. Basically, as I understand it, you need to create a
new database with the name you want and then load it with your old data.  In BASH:

1:  create the database you want your old one (which we'll call OldName) to be
called.  We'll call it NewName:  type:  CREATEDB NewName

2: create an SQL file that contains your data and most of your metadata:
type:  pg_dump OldName > OldName.sql

3: you can now edit the SQL that you will use to create your new database with
a text editor, if you want, but the 'renaming' actually occurs when you load
the database into NewName.  type: psql -e NewName < OldName.sql

4: destroy your old db if you want -- and after you make sure all this worked!
 type:  DESTROYDB OldName

Comments:

1:  If you don't need to edit the SQL file, you can combine steps 2 and 3.
type:  pg_dump OldName | psql NewName -e

2: Be aware of the limitations of pg_dump, notably that it does not cover
views and some other stuff you've created.  You may want to consider creating
your views by building your SQL in a file and then running the SQL on your
database.  That makes editing your views and reloading them in the future
quite a lot easier.

3:  Before you do this and risk your data, check out each of these commands at http://www.postgresql.org/docs/man/

:-)

DTB

pgsql-general by date:

Previous
From: "Jeff Hoffmann"
Date:
Subject: where to find dbf2pg-3.0?
Next
From: Charles-Edouard Ruault
Date:
Subject: problem of upper/lower case in table names