Re: renaming a db - Mailing list pgsql-novice

From Tom Lane
Subject Re: renaming a db
Date
Msg-id 6597.999552941@sss.pgh.pa.us
Whole thread Raw
In response to Re: renaming a db  (jik@foxinternet.net)
List pgsql-novice
jik@foxinternet.net writes:
> Tom Lane wrote:
>>> I have a feeling I can't do it, but is there a way to rename a dB?
>>
>> In 7.1 or later I think it would work to just UPDATE the db's row in
>> pg_database.  But don't blame me if this fails to work ... make a
>> backup before you try it.

> Doesn't look like that works....you ruined my database, I bet they fire
> me :P

> jik-=# UPDATE pg_database SET datname='test34' WHERE datname='test2';
> UPDATE 1
> jik-=# \c test34
> FATAL 1:  Database "test34" does not exist in the system catalog.
> Previous connection kept

I find that it starts working after you do a CHECKPOINT ... or wait for
one to happen automatically.  (A would-be backend won't see the
pg_database change until the table update is flushed to disk.)

foo=# update pg_database set datname = 'bar' where datname='foo';
UPDATE 1
foo=# checkpoint;
CHECKPOINT
-- now I can connect to 'bar'

            regards, tom lane

pgsql-novice by date:

Previous
From: jik@foxinternet.net
Date:
Subject: Re: renaming a db
Next
From: "Robert J. Sanford, Jr."
Date:
Subject: the best way? (maybe a PL/pgSQL question)