BRIN index bug due to WAL refactoring
BRIN index WAL is broken in HEAD.
Commit 2c03216d831160bedd72d4, the Revamp the WAL record format, is the
culprit.
The easiest way to see this is via streaming replication.
On master:
create table foobar as select * from generate_series(1,10000);
create index on foobar using brin (generate_series );
On replica:
set enable_seqscan TO off;
explain (analyze) select count(*) from foobar ;
ERROR: corrupted BRIN index: inconsistent range map
Cheers,
Jeff
Jeff Janes wrote:
BRIN index WAL is broken in HEAD.
Thanks for all the details. Looking into it.
--
�lvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
Jeff Janes wrote:
On replica:
set enable_seqscan TO off;
explain (analyze) select count(*) from foobar ;
ERROR: corrupted BRIN index: inconsistent range map
Nice. As I understand it, the problem is that the replay is using the
block number of the revmap page as target blkno of the revmap entry,
when it should be using the block number of the data page. This should
fix it.
--
�lvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Attachments:
brin-wal-replay.patchtext/x-diff; charset=us-asciiDownload
commit 622a903cf88931878cbaba9bdd25c9835af0d055
Author: Alvaro Herrera <alvherre@alvh.no-ip.org>
Date: Fri Jun 26 15:33:19 2015 -0300
Fix BRIN xlog replay
diff --git a/src/backend/access/brin/brin_xlog.c b/src/backend/access/brin/brin_xlog.c
index 49261aa..e68f623 100644
--- a/src/backend/access/brin/brin_xlog.c
+++ b/src/backend/access/brin/brin_xlog.c
@@ -47,6 +47,7 @@ brin_xlog_insert_update(XLogReaderState *record,
{
XLogRecPtr lsn = record->EndRecPtr;
Buffer buffer;
+ BlockNumber blkno;
Page page;
XLogRedoAction action;
@@ -66,6 +67,8 @@ brin_xlog_insert_update(XLogReaderState *record,
action = XLogReadBufferForRedo(record, 0, &buffer);
}
+ blkno = BufferGetBlockNumber(buffer);
+
/* insert the index item into the page */
if (action == BLK_NEEDS_REDO)
{
@@ -97,7 +100,6 @@ brin_xlog_insert_update(XLogReaderState *record,
if (action == BLK_NEEDS_REDO)
{
ItemPointerData tid;
- BlockNumber blkno = BufferGetBlockNumber(buffer);
ItemPointerSet(&tid, blkno, xlrec->offnum);
page = (Page) BufferGetPage(buffer);
On Fri, Jun 26, 2015 at 11:35 AM, Alvaro Herrera <alvherre@2ndquadrant.com>
wrote:
Jeff Janes wrote:
On replica:
set enable_seqscan TO off;
explain (analyze) select count(*) from foobar ;
ERROR: corrupted BRIN index: inconsistent range mapNice. As I understand it, the problem is that the replay is using the
block number of the revmap page as target blkno of the revmap entry,
when it should be using the block number of the data page. This should
fix it.
Thanks, that worked.
The way the blkno and buffer refer to different block/buffers is pretty
confusing. Could we rename a variable to make it clearer which buffer's
number is contained in blkno?
Thanks,
Jeff
Jeff Janes wrote:
The way the blkno and buffer refer to different block/buffers is pretty
confusing. Could we rename a variable to make it clearer which buffer's
number is contained in blkno?
Sure thing. Pushed that way.
--
�lvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers