From: Robert Haas <robertmhaas@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Alvaro Herrera <alvherre@commandprompt.com>
Cc: Euler Taveira de Oliveira <euler@timbira.com>
Cc: Emanuel <postgres.arg@gmail.com>
Cc: pgsql-bugs <pgsql-bugs@postgresql.org>
Subject: Re: BUG #6041: Unlogged table was created bad in slave node
Date: Tue, 7 Jun 2011 15:24:53 -0400
Message-ID: <BANLkTikMWGdLgRAL+fCBKGaNs85eQo2K+w@mail.gmail.com> (raw)
In-Reply-To: <BANLkTi=2ewL63njHx7mth1tV6_NYimAR9A@mail.gmail.com>
References: <201105261137.p4QBbTlt077425@wwwmaster.postgresql.org>
<4DDE7905.6050406@timbira.com>
<1306427067-sup-7622@alvh.no-ip.org>
<25332.1306427674@sss.pgh.pa.us>
<BANLkTim433vF5HWjbJ0FSWm_-xA8DDaGNg@mail.gmail.com>
<BANLkTi=e7+0aXyoLoZENsNeBWX7n9Q+4Pw@mail.gmail.com>
<1307120363-sup-3085@alvh.no-ip.org>
<BANLkTinuA4fFnGtPYVrFvW0GssXYkOUGiQ@mail.gmail.com>
<14416.1307461823@sss.pgh.pa.us>
<BANLkTi=2ewL63njHx7mth1tV6_NYimAR9A@mail.gmail.com>
On Tue, Jun 7, 2011 at 2:05 PM, Robert Haas <robertmhaas@gmail.com> wrote:
> On Tue, Jun 7, 2011 at 11:50 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> Robert Haas <robertmhaas@gmail.com> writes:
>>> Patch along these lines attached.
>>
>> Frankly, I find this quite ugly, and much prefer the general approach of
>> your previous patch in <BANLkTim433vF5HWjbJ0FSWm_-xA8DDaGNg@mail.gmail.com>.
>>
>> However, I don't like where you put the execution-time test there. I'd
>> put it in ExecOpenScanRelation instead, so that it covers both seqscan
>> and indexscan accesses.
>
> Ah, OK. I was wondering if there was a better place. I'll do it that
> way, then.
I found a few other holes in my previous patch as well. I think this
plugs them all, but it's hard to be sure there aren't any other calls
to RelationGetNumberOfBlocks() that could bomb out.
--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
Attachments:reject-unlogged-during-recovery-v3.patch (application/octet-stream, 3.0K) downloaddiff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.cindex e71090f..437d74b 100644--- a/src/backend/access/transam/xlog.c+++ b/src/backend/access/transam/xlog.c@@ -24,6 +24,7 @@
#include <unistd.h>
#include "access/clog.h"
+#include "access/xlog.h"
#include "access/multixact.h"
#include "access/subtrans.h"
#include "access/transam.h"
diff --git a/src/backend/executor/execUtils.c b/src/backend/executor/execUtils.cindex 073ef8d..03d7f18 100644--- a/src/backend/executor/execUtils.c+++ b/src/backend/executor/execUtils.c@@ -802,6 +802,7 @@ ExecOpenScanRelation(EState *estate, Index scanrelid)
{
Oid reloid;
LOCKMODE lockmode;
+ Relation rel;
/*
* Determine the lock type we need. First, scan to see if target relation
@@ -829,7 +830,15 @@ ExecOpenScanRelation(EState *estate, Index scanrelid)
/* OK, open the relation and acquire lock as needed */
reloid = getrelid(scanrelid, estate->es_range_table);
- return heap_open(reloid, lockmode);+ rel = heap_open(reloid, lockmode);++ /* We can't scan temporary or unlogged relations during recovery. */+ if (!RelationNeedsWAL(rel) && RecoveryInProgress())+ ereport(ERROR,+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),+ errmsg("cannot access temporary or unlogged relations during recovery")));++ return rel;
}
/* ----------------------------------------------------------------
diff --git a/src/backend/optimizer/util/plancat.c b/src/backend/optimizer/util/plancat.cindex fd8ea45..2555d8f 100644--- a/src/backend/optimizer/util/plancat.c+++ b/src/backend/optimizer/util/plancat.c@@ -106,7 +106,7 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent,
* must leave it zero for now to avoid bollixing the total_table_pages
* calculation.
*/
- if (!inhparent)+ if (!inhparent && (RelationNeedsWAL(relation) || !RecoveryInProgress()))
estimate_rel_size(relation, rel->attr_widths - rel->min_attr,
&rel->pages, &rel->tuples);
@@ -321,7 +321,10 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent,
*/
if (info->indpred == NIL)
{
- info->pages = RelationGetNumberOfBlocks(indexRelation);+ if (RelationNeedsWAL(indexRelation) || !RecoveryInProgress())+ info->pages = RelationGetNumberOfBlocks(indexRelation);+ else+ info->pages = 0;
info->tuples = rel->tuples;
}
else
@@ -374,8 +377,15 @@ estimate_rel_size(Relation rel, int32 *attr_widths,
case RELKIND_RELATION:
case RELKIND_INDEX:
case RELKIND_TOASTVALUE:
- /* it has storage, ok to call the smgr */- curpages = RelationGetNumberOfBlocks(rel);+ /*+ * It has storage; we can call the smgr. But not for temporary+ * or unlogged relations during recovery, when such relations+ * are not available.+ */+ if (RelationNeedsWAL(rel) || !RecoveryInProgress())+ curpages = RelationGetNumberOfBlocks(rel);+ else+ curpages = 0;
/*
* HACK: if the relation has never yet been vacuumed, use a
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-bugs@postgresql.org
Cc: robertmhaas@gmail.com, tgl@sss.pgh.pa.us, alvherre@commandprompt.com, euler@timbira.com, postgres.arg@gmail.com
Subject: Re: BUG #6041: Unlogged table was created bad in slave node
In-Reply-To: <BANLkTikMWGdLgRAL+fCBKGaNs85eQo2K+w@mail.gmail.com>
References: <201105261137.p4QBbTlt077425@wwwmaster.postgresql.org> <4DDE7905.6050406@timbira.com> <1306427067-sup-7622@alvh.no-ip.org> <25332.1306427674@sss.pgh.pa.us> <BANLkTim433vF5HWjbJ0FSWm_-xA8DDaGNg@mail.gmail.com> <BANLkTi=e7+0aXyoLoZENsNeBWX7n9Q+4Pw@mail.gmail.com> <1307120363-sup-3085@alvh.no-ip.org> <BANLkTinuA4fFnGtPYVrFvW0GssXYkOUGiQ@mail.gmail.com> <14416.1307461823@sss.pgh.pa.us> <BANLkTi=2ewL63njHx7mth1tV6_NYimAR9A@mail.gmail.com> <BANLkTikMWGdLgRAL+fCBKGaNs85eQo2K+w@mail.gmail.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