Re: "mirroring" a table - PostgreSQL 7.3.2

From: Reece Hart <reece(at)in-machina(dot)com>
To: "C(dot) Bensend" <benny(at)bennyvision(dot)com>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: "mirroring" a table - PostgreSQL 7.3.2
Date: 2004-01-24 22:48:08
Message-ID: 1074984488.5591.29.camel@whoville
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

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

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Bruce Momjian 2004-01-25 02:49:16 Re: setting statement_timeout on live postmaster
Previous Message Mark Kirkwood 2004-01-24 21:56:07 Re: High Performance/High Reliability File system on SuSE64