pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Markus Schaber <schabios@logi-track.com>
To: pgsql-sql@postgresql.org
Subject: Re: Move table between schemas
Date: Sat, 20 Nov 2004 11:44:11 +0100
Message-ID: <20041120114411.28c05fcf@kingfisher.intern.logi-track.com> (raw)
In-Reply-To: <20041116110538.GA15247@phlogiston.dyndns.org>
References: <20041116100234.635fcd7e@kingfisher.intern.logi-track.com>
	<20041116110538.GA15247@phlogiston.dyndns.org>

Hi, Andrew,

On Tue, 16 Nov 2004 06:05:38 -0500
Andrew Sullivan <ajs@crankycanuck.ca> wrote:

> > Is there an easy way to move a table to another schema in PostgreSQL 7.4?
> > 
> > ALTER TABLE and ALTER SCHEMA don't have this options.
> 
> CREATE TABLE newschema.newtable AS SELECT * FROM oldschema.oldtable 
> oughta work.

This has several drawbacks I can see for now:

- For large tables (some Gigs of data), this needs a long time and
produces heavy I/O load on the server.

- You need twice the disk space until you can delete the old table.

- Indices, triggers, sequences and constraints are not transferred. When
the target schema is first in the search path of the application, this
means that the application works on an incomplete table until I finished
the transition..

- It does not automatically convert views or foreign key constraints
that point to the table.

- The operation is not atomic, thus there may be inserts and updates
into the old table that get lost while the "CREATE...SELECT...;DROP
TABLE...;" runs.


Is there any (possibly ugly, fiddling with system tables) atomic way to
move a table between schemas? It should not be much more difficult
compared to e. G. renaming a table to implement this, so I couuld not
imagine this does not exist until I tried to find out how to do it.


Thanks,
markus
-- 
markus schaber | dipl. informatiker
logi-track ag | rennweg 14-16 | ch 8001 zürich
phone +41-43-888 62 52 | fax +41-43-888 62 53
mailto:schabios@logi-track.com | www.logi-track.com



view thread (6+ messages)  latest in thread

Message-ID: <20041120114411.28c05fcf@kingfisher.intern.logi-track.com>
Permalink:  ../20041120114411.28c05fcf@kingfisher.intern.logi-track.com/
Also on:    postgresql.org/message-id/20041120114411.28c05fcf@kingfisher.intern.logi-track.com

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: schabios@logi-track.com
  Subject: Re: Move table between schemas
  In-Reply-To: <20041120114411.28c05fcf@kingfisher.intern.logi-track.com>

* 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