Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 71F4FB623CA for ; Wed, 1 Jun 2011 15:28:46 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 33017-04 for ; Wed, 1 Jun 2011 18:28:39 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-pv0-f174.google.com (mail-pv0-f174.google.com [74.125.83.174]) by mail.postgresql.org (Postfix) with ESMTP id 93940B623C0 for ; Wed, 1 Jun 2011 15:28:38 -0300 (ADT) Received: by pvg12 with SMTP id 12so34014pvg.19 for ; Wed, 01 Jun 2011 11:28:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=Tgj6ejx7i4dXBZ9KEVl/iBDM3nFwC5YluweADvPHXnE=; b=rZx5bEsUIYOWG+TfJZ+xntDEMiwTY1NpizjjCI0iZcYAhod+zXWAUoBt8PSQQcPX7C 4nUduh++BRpXxxiTMPdS9MWnUhFe/sXN9QBsZWMA/bm5TcJxMkloli4+H2HKjIxvjGnJ /SZg/kurFjljhMFoi623pinmVWhCOeBodz7CE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=da9xMtUefdKAC8MKK0ea9DMBUQe8HNbjPv5T34hgZafqd9605ZCM3cxAkBxDVvgh3/ vAGx5TsJ8lfqjwSCd3Viyz9ePCLysP3LW5m9G0JDHKywKVJ8rByrnKT/+21b8kiKASuu r/IWJk+4XfEjS6rlqyS1jnuMzWgfU7x6rC5A8= MIME-Version: 1.0 Received: by 10.68.52.105 with SMTP id s9mr3224390pbo.245.1306952917942; Wed, 01 Jun 2011 11:28:37 -0700 (PDT) Received: by 10.68.56.70 with HTTP; Wed, 1 Jun 2011 11:28:37 -0700 (PDT) In-Reply-To: <25332.1306427674@sss.pgh.pa.us> References: <201105261137.p4QBbTlt077425@wwwmaster.postgresql.org> <4DDE7905.6050406@timbira.com> <1306427067-sup-7622@alvh.no-ip.org> <25332.1306427674@sss.pgh.pa.us> Date: Wed, 1 Jun 2011 14:28:37 -0400 Message-ID: Subject: Re: BUG #6041: Unlogged table was created bad in slave node From: Robert Haas To: Tom Lane Cc: Alvaro Herrera , Euler Taveira de Oliveira , Emanuel , pgsql-bugs Content-Type: multipart/mixed; boundary=bcaec543177a69813d04a4aab061 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.898 tagged_above=-5 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, RFC_ABUSE_POST=0.001 X-Spam-Level: X-Archive-Number: 201106/8 X-Sequence-Number: 30387 --bcaec543177a69813d04a4aab061 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Thu, May 26, 2011 at 12:34 PM, Tom Lane wrote: > Alvaro Herrera writes: >> Excerpts from Euler Taveira de Oliveira's message of jue may 26 12:00:05= -0400 2011: >>> I think we should emit the real cause in those cases, if possible (not = too >>> much overhead). The message would be "Unlogged table content is not ava= ilable >>> in standby server". > >> I guess what it should do is create an empty file in the slave. > > Probably it should, because won't the table malfunction after the slave > is promoted to master, if there's no file at all there? =A0Or will the > process of coming live create an empty file even if there was none? Coming live creates an empty file. > But Euler is pointing out a different issue, which is usability. =A0If th= e > slave just acts like the table is present but empty, we are likely to > get bug reports about that too. =A0An error telling you you aren't allowe= d > to access such a table on slaves would be more user-friendly, if we can > do it without too much pain. I looked into this a bit. A few observations: (1) This problem is actually not confined to unlogged tables; temporary tables have the same issue. For example, if you create a temporary table on the master and then, on the slave, do SELECT * FROM pg_temp_3.hi_mom (or whatever the name of the temp schema where the temp table is) you get the same error. In fact I suspect if you took a base backup that included the temporary relation and matched the backend ID you could even manage to read out the old contents (modulo any fun and exciting XID wraparound issues). But the problem is of course more noticeable for unlogged tables since they're not hidden away in a special funny schema. (2) It's somewhat difficult to get a clean fix for this error because it's coming from deep down in the bowels of the system, inside mdnblocks(). At that point, we haven't got a Relation available, just an SMgrRelation, so the information that this relation is unlogged is not really available, at least not without some sort of gross modularity violation like calling smgrexists() on the init fork. It doesn't particularly seem like a good idea to conditionalize the behavior of mdnblocks() on relpersistence anyway; that's a pretty gross modularity violation all by itself. (3) mdnblocks() gets called twice during the process of doing a simple select on a relation - once from the planner, via estimate_rel_size, and again from the executor, via initscan. A fairly obvious fix for this problem is to skip the call to estimate_rel_size() if we're dealing with a temporary or unlogged relation and are in recovery; and make heap_beginscan_internal() throw a suitable error under similar circumstances (or do we want to throw the error at plan time? tossing it out from all the way down in estimate_rel_size() seems a bit wacky). Patch taking this approach attached. (4) It strikes me that it might be possible to address this problem a bit more cleanly by allowing mdnblocks() and smgrnblocks() and RelationGetNumberOfBlocksInFork() to take a boolean argument indicating whether or not an error should be thrown if the underlying physical file happens not to exist. When no error is to be signaled, we simply return 0 when the main fork doesn't exist, rather than throwing an error. We could then make estimate_rel_size() use this variant, eliminating the need for an explicit test in get_relation_info(). I'm sort of inclined to go this route even though it would require touching a bit more code. We've already whacked around RelationGetNumberOfBlocks() a bit in this release (the function that formerly had that name is now RelationGetNumberOfBlocksInFork(), and RelationGetNumberOfBlocks() is now a macro that calls that function w/MAIN_FORKNUM) so it doesn't seem like a bad time to get any other API changes that might be useful out of our system. Thoughts? --=20 Robert Haas EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company --bcaec543177a69813d04a4aab061 Content-Type: application/octet-stream; name="reject-unlogged-during-recovery.patch" Content-Disposition: attachment; filename="reject-unlogged-during-recovery.patch" Content-Transfer-Encoding: base64 X-Attachment-Id: f_goem0mrq0 ZGlmZiAtLWdpdCBhL3NyYy9iYWNrZW5kL2FjY2Vzcy9oZWFwL2hlYXBhbS5jIGIvc3JjL2JhY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