diff options
| author | Tom Lane <tgl@sss.pgh.pa.us> | 2005-11-06 19:29:01 +0000 |
|---|---|---|
| committer | Tom Lane <tgl@sss.pgh.pa.us> | 2005-11-06 19:29:01 +0000 |
| commit | 766dc45d9f133aaa12d952052e1e512dbf3f5ec0 (patch) | |
| tree | 9ab560a2274467ac31af307471129d4cdbee272e /src/backend/access/nbtree/nbtree.c | |
| parent | 18691d8ee3e4729948f6348d25ee1e4bba2379fe (diff) | |
| download | postgresql-766dc45d9f133aaa12d952052e1e512dbf3f5ec0.tar.gz | |
Add defenses to btree and hash index AMs to do simple sanity checks
on every index page they read; in particular to catch the case of an
all-zero page, which PageHeaderIsValid allows to pass. It turns out
hash already had this idea, but it was just Assert()ing things rather
than doing a straight error check, and the Asserts were partially
redundant with PageHeaderIsValid anyway. Per recent failure example
from Jim Nasby. (gist still needs the same treatment.)
Diffstat (limited to 'src/backend/access/nbtree/nbtree.c')
| -rw-r--r-- | src/backend/access/nbtree/nbtree.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/backend/access/nbtree/nbtree.c b/src/backend/access/nbtree/nbtree.c index 10e2fe6190..9ddc326bd2 100644 --- a/src/backend/access/nbtree/nbtree.c +++ b/src/backend/access/nbtree/nbtree.c @@ -12,7 +12,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/access/nbtree/nbtree.c,v 1.132 2005/10/15 02:49:09 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/access/nbtree/nbtree.c,v 1.133 2005/11/06 19:29:00 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -734,8 +734,8 @@ btvacuumcleanup(PG_FUNCTION_ARGS) * buffer and it will be fully initialized before we can examine it. (See * also vacuumlazy.c, which has the same issue.) * - * We can skip locking for new or temp relations, however, since no one else - * could be accessing them. + * We can skip locking for new or temp relations, however, since no one + * else could be accessing them. */ needLock = !RELATION_IS_LOCAL(rel); @@ -772,9 +772,17 @@ btvacuumcleanup(PG_FUNCTION_ARGS) Page page; BTPageOpaque opaque; - buf = _bt_getbuf(rel, blkno, BT_READ); + /* + * We can't use _bt_getbuf() here because it always applies + * _bt_checkpage(), which will barf on an all-zero page. + * We want to recycle all-zero pages, not fail. + */ + buf = ReadBuffer(rel, blkno); + LockBuffer(buf, BT_READ); page = BufferGetPage(buf); opaque = (BTPageOpaque) PageGetSpecialPointer(page); + if (!PageIsNew(page)) + _bt_checkpage(rel, buf); if (_bt_page_recyclable(page)) { /* Okay to recycle this page */ |
