Re: amcheck (B-Tree integrity checking tool)

Поиск
Список
Период
Сортировка
От Peter Geoghegan
Тема Re: amcheck (B-Tree integrity checking tool)
Дата
Msg-id CAM3SWZQRwBbyGOcATfYBg9hRLG10mAZV8b5ZJ+93QYt3o737gg@mail.gmail.com
обсуждение исходный текст
Ответ на Re: amcheck (B-Tree integrity checking tool)  (Michael Paquier <michael.paquier@gmail.com>)
Ответы Re: amcheck (B-Tree integrity checking tool)  (Peter Geoghegan <pg@heroku.com>)
Список pgsql-hackers
On Fri, Mar 11, 2016 at 8:24 AM, Michael Paquier
<michael.paquier@gmail.com> wrote:
> You can use for example dd in non-truncate mode to corrupt on-disk
> page data, say that for example:
> dd if=/dev/random bs=8192 count=1 \
>     seek=$BLOCK_ID of=base/$DBOID/$RELFILENODE \
>     conv=notrunc

Sure, but that would probably fail at the first hurdle -- the page
header would be corrupt. Which is a valid test, but not all that
interesting.

One testing workflow I tried is overwriting some page in a B-Tree
relfilenode with some other page in the same file:

$:~/pgdata/base/12413$ dd if=somefile of=somefile conv=notrunc bs=8192
count=1 skip=2 seek=3

That should fail due to the key space not being in order across pages,
which is slightly interesting. Or, you could selectively change one
item with a hex editor, as Anastasia did.

Or, you could add code like this to comparetup_index_btree(), to
simulate a broken opclass:

diff --git a/src/backend/utils/sort/tuplesort.c
b/src/backend/utils/sort/tuplesort.c
index 67d86ed..23712ff 100644
--- a/src/backend/utils/sort/tuplesort.c
+++ b/src/backend/utils/sort/tuplesort.c
@@ -3562,6 +3562,9 @@ comparetup_index_btree(const SortTuple *a, const
SortTuple *b,       compare = ApplySortComparator(a->datum1, a->isnull1,

b->datum1, b->isnull1,                                                                 sortKey);
+
+       if (random() <= (MAX_RANDOM_VALUE / 1000))
+               compare = -compare;       if (compare != 0)               return compare;

There are many options when you want to produce a corrupt B-Tree index!

-- 
Peter Geoghegan



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Robert Haas
Дата:
Сообщение: Re: [COMMITTERS] pgsql: Provide much better wait information in pg_stat_activity.
Следующее
От: Peter Geoghegan
Дата:
Сообщение: Re: amcheck (B-Tree integrity checking tool)