PDA

View Full Version : Renaming a Database



TPayne
09-12-2008, 01:26 PM
Is it possible to rename a database?

fabio
09-12-2008, 01:36 PM
You can rename your database(s) with pgAdmin

TPayne
09-12-2008, 02:14 PM
I looked around in pgAdmin III and I couldn't find anywhere to rename it. It seems as if the names are locked in and unable to edit.

agc1976
09-14-2008, 11:28 AM
Try this:


Create a backup of your database with PGAdmin.
Create a new database with the name that you want.
Restore the old database on top of the database you just created.

Stick66
10-21-2008, 12:14 PM
(You may want to back up your DB before you try this, but it worked fine for me.)

Found the trick:

- Go into "PSQL to 'postgres'" (not pgAdmin)

- Enter this line exactly, but where xxx = old DB name and nnn = new DB name:

ALTER DATABASE "xxxxxxx" RENAME TO "nnnnnnn" \g

(Here's the PostgreSQL Doc page for it: http://www.postgresql.org/docs/8.3/static/sql-alterdatabase.html ) (the "\g" part is what executes the command)

- When you next open HEM, you will get an error "Database not found" or something. Click "OK" and Database Maintenance should open. Connect and make your newly named DB the default.

Then you're set!!