Skip site navigation (1) Skip section navigation (2)

Re: renaming a db

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: jik(at)foxinternet(dot)net
Cc: psql <pgsql-novice(at)postgresql(dot)org>
Subject: Re: renaming a db
Date: 2001-09-03 21:35:41
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-novice
jik(at)foxinternet(dot)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 ruined my database, I bet they fire
> me :P

> jik-=# UPDATE pg_database SET datname='test34' WHERE datname='test2';
> 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';
foo=# checkpoint;
-- now I can connect to 'bar'

			regards, tom lane

In response to

pgsql-novice by date

Next:From: John E. MichelsenDate: 2001-09-04 01:37:49
Subject: Is postgreSql really suitable?
Previous:From: jikDate: 2001-09-03 20:27:51
Subject: Re: renaming a db

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group