Re: Is renaming a database easy or dangerous - Mailing list pgsql-general

From Tom Lane
Subject Re: Is renaming a database easy or dangerous
Date
Msg-id 7379.1046303275@sss.pgh.pa.us
Whole thread Raw
In response to Is renaming a database easy or dangerous  (Hadley Willan <hadley.willan@deeperdesign.co.nz>)
List pgsql-general
Hadley Willan <hadley.willan@deeperdesign.co.nz> writes:
>    I'd like to rename one of my databases. Is it is simple as changing
> the datname field in the pg_databases table?
> If so, is it done through ALTER database or a SQL update?

There is no ALTER DATABASE command for this.  I believe that since 7.1
you can get away with an UPDATE on the pg_database row, with a couple of
caveats:

* It's unwise to do this while there are any backends connected to the
target database.  I'm not sure whether they'd get seriously confused
because their database changed name, but you don't want to find out the
hard way.

* You will have to issue a CHECKPOINT (or wait for one to occur
automatically) before the change will be visible to incoming new
connections.  A "vacuum pg_database" command before checkpointing might
be helpful as well, though I think it's probably not necessary in most
cases.

            regards, tom lane

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Still intrigued... (was: Socket command type e unknown)
Next
From: Dennis Gearon
Date:
Subject: Re: Still intrigued... (was: Socket command type e unknown)