pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Reece Hart <reece@in-machina.com>
To: C. Bensend <benny@bennyvision.com>
Cc: pgsql-admin@postgresql.org
Subject: Re: "mirroring" a table - PostgreSQL 7.3.2
Date: Sat, 24 Jan 2004 14:48:08 -0800
Message-ID: <1074984488.5591.29.camel@whoville> (raw)
In-Reply-To: <56251.63.227.74.41.1074979320.squirrel@webmail.stinkweasel.net>
References: <53076.63.227.74.41.1074972926.squirrel@webmail.stinkweasel.net>
	<5233.1074978599@sss.pgh.pa.us>
	<56251.63.227.74.41.1074979320.squirrel@webmail.stinkweasel.net>

On Sat, 2004-01-24 at 13:21, C. Bensend wrote:

>    I've looked at this, and it seems to be on the same level as a quick
> DROP/CREATE.  Is there no way to "mirror" a table structure in real time?



Benny-

If I understand what you want correctly, inheritance seems like a pretty
good option. Changes to the definition of a super table are inherited by
the sub table immediately. Data will be preserved in both tables (except
when you drop a column). This is NOT "on the same level as a quick
DROP/CREATE".

The primary gotcha for you is that selects on super tables implicitly
select from the super and all its children (see "select * from ONLY
table" to prevent this). 

Here's a proposal to get what you want: Create a super table bob_def and
two sub tables bob and bob_test. Changes to the definition of bob_def
(e.g., alter table add column...) will get immediately reflected in both
children. You'll insert data into bob and bob_test; bob_def contains no
rows. Selects on bob and bob_test are independent. In short, the
definitions will always be consistent and the data will be completely
independent. You could periodically truncate bob_test and insert ...
select to mirror the data too.

A lesser option is to have bob_test inherit from bob, then use rules to
enforce the ONLY keyword for select/insert/update on bob. The
implementation of this option is less clear to me and there are a few
likely gotchas.



> CREATE TABLE test_bob AS ( SELECT * FROM bob WHERE '1' = '2' );


I don't understand why this does what you want... it requires explicit
intervention (meaning not "real time") to mirror the table definition.


-Reece

-- 
Reece Hart, http://www.in-machina.com/~reece/, GPG:0x25EC91A0 0xD178AAF9

view thread (6+ messages)  latest in thread

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

 · 

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: reece@in-machina.com, benny@bennyvision.com
  Subject: Re: "mirroring" a table - PostgreSQL 7.3.2
  In-Reply-To: <1074984488.5591.29.camel@whoville>
  References: <53076.63.227.74.41.1074972926.squirrel@webmail.stinkweasel.net> <5233.1074978599@sss.pgh.pa.us> <56251.63.227.74.41.1074979320.squirrel@webmail.stinkweasel.net> <1074984488.5591.29.camel@whoville>

* 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