X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (neptune.hub.org [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 43466D1B7E5 for ; Sat, 24 Jan 2004 22:48:38 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 45987-08 for ; Sat, 24 Jan 2004 18:48:15 -0400 (AST) Received: from whoville.in-machina.com (m208-10.dsl.rawbw.com [198.144.208.10]) by svr1.postgresql.org (Postfix) with ESMTP id C59AFD1E872 for ; Sat, 24 Jan 2004 18:48:06 -0400 (AST) Received: by whoville.in-machina.com (Postfix, from userid 13922) id CB5A2F6298; Sat, 24 Jan 2004 14:48:08 -0800 (PST) Subject: Re: "mirroring" a table - PostgreSQL 7.3.2 From: Reece Hart To: "C. Bensend" Cc: pgsql-admin@postgresql.org 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> Content-Type: multipart/alternative; boundary="=-AkoXC6kZgVEkgb4rOvuc" Message-Id: <1074984488.5591.29.camel@whoville> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.5 Date: Sat, 24 Jan 2004 14:48:08 -0800 X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200401/193 X-Sequence-Number: 12056 --=-AkoXC6kZgVEkgb4rOvuc Content-Type: text/plain Content-Transfer-Encoding: 7bit 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 --=-AkoXC6kZgVEkgb4rOvuc Content-Type: text/html; charset=utf-8 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
--=-AkoXC6kZgVEkgb4rOvuc--