pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Oliver Elphick <olly@lfix.co.uk>
To: Naomi Walker <nwalker@eldocomp.com>
Cc: Chris Ruprecht <chrup999@yahoo.com>
Cc: PostGreSQL Admin Group <pgsql-admin@postgresql.org>
Subject: Re: Re-nameing a database?
Date: 11 Feb 2002 16:43:34 +0000
Message-ID: <1013445816.12184.44.camel@linda> (raw)
In-Reply-To: <4.2.2.20020211085032.00adcc00@ecint.ecinet.com>
References: <4.2.2.20020211085032.00adcc00@ecint.ecinet.com>

On Mon, 2002-02-11 at 15:50, Naomi Walker wrote:
> Not in postgres, unfortunately.  I'd love to be wrong.
> 
> At 04:26 PM 2/10/02 -0600, Chris Ruprecht wrote:
> 
> >Hi all,
> >
> >is there an easy way to re-name a database?

In 7.1.3, you can do it by updating the row in pg_database and then
restarting the postmaster:

$ psql template1
...

template1=# \l
        List of databases
 Database  |  Owner   | Encoding  
-----------+----------+-----------
 junk      | olly     | SQL_ASCII
...
 template0 | postgres | SQL_ASCII
 template1 | postgres | SQL_ASCII
(8 rows)

template1=# update pg_database set datname = 'rubbish' where datname =
'junk';
UPDATE 1
template1=# \l
        List of databases
 Database  |  Owner   | Encoding  
-----------+----------+-----------
 rubbish   | olly     | SQL_ASCII
...
 template0 | postgres | SQL_ASCII
 template1 | postgres | SQL_ASCII
(8 rows)

template1=# \c rubbish
FATAL 1:  Database "rubbish" does not exist in the system catalog.
Previous connection kept
template1=# \c junk
FATAL 1:  Database "junk", OID 44062648, has disappeared from
pg_database
Previous connection kept
template1=# \q
$ sudo /etc/init.d/postgresql restart
Password:
Restarting PostgreSQL database: postmaster
Stopped /usr/lib/postgresql/bin/postmaster (pid 15397).
Starting PostgreSQL postmaster.
postmaster successfully started

$ psql template1
...
template1=# \c rubbish
You are now connected to database rubbish.
rubbish=# \c junk
FATAL 1:  Database "junk" does not exist in the system catalog.
Previous connection kept
rubbish=# 


An alternative method would be to dump everything with pg_dumpall and
then edit the dump to change the database name.

-- 
Oliver Elphick                                Oliver.Elphick@lfix.co.uk
Isle of Wight                              http://www.lfix.co.uk/oliver
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839  932A 614D 4C34 3E1D 0C1C





view thread (6+ messages)  latest in thread

Message-ID: <1013445816.12184.44.camel@linda>
Permalink:  ../1013445816.12184.44.camel@linda/
Also on:    postgresql.org/message-id/1013445816.12184.44.camel@linda

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-admin@postgresql.org
  Cc: olly@lfix.co.uk, nwalker@eldocomp.com, chrup999@yahoo.com
  Subject: Re: Re-nameing a database?
  In-Reply-To: <1013445816.12184.44.camel@linda>
  References: <4.2.2.20020211085032.00adcc00@ecint.ecinet.com> <1013445816.12184.44.camel@linda>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox