Re: Failure while inserting parent tuple to B-tree is not fun - Mailing list pgsql-hackers

From Heikki Linnakangas
Subject Re: Failure while inserting parent tuple to B-tree is not fun
Date
Msg-id 52E6AC71.9010905@vmware.com
Whole thread Raw
In response to Re: Failure while inserting parent tuple to B-tree is not fun  (Peter Geoghegan <pg@heroku.com>)
Responses Re: Failure while inserting parent tuple to B-tree is not fun  (Peter Geoghegan <pg@heroku.com>)
List pgsql-hackers
On 01/23/2014 11:36 PM, Peter Geoghegan wrote:
> That's all I have for now. I've written plenty of notes, and will work
> back through other points of possible concern. I don't suppose you
> have any testing infrastructure that you could publish?

Okay, promise not to laugh. I did write a bunch of hacks, to generate
graphviz .dot files from the btree pages, and render them into pictures.
It consist of multiple parts, all in the attached tarball. Here's how to
use it:

After installing all the parts (instructions below), launch the
btree-snapshot.sh script. It will poll every seconds, and generate a
.dot graph out of an index called 'i_foo'. It compares the snapshot with
the previous one, and if it differs, it generates a new .png file from
it under /tmp.

With that, you can get a slideshow of how the index changes, when you
execute commands that modify it. However, because it only polls once per
second, you'll have to insert some sleeps into the code you're testing,
so that the script can catch the changes in action. See attached
nbtinsert-sleeps.patch.

For example:

create table foo (t text);
create index i_foo on foo (t);

-- launch btree-snapshot.sh in another terminal

insert into foo select 'aaa' || g from generate_series(1, 10000) g;

Once that finishes, the btree-snapshot.sh script should've generated a
bunch of .png files in /tmp/:

~$ ls /tmp/*.png
/tmp/g1.png  /tmp/g3.png  /tmp/g5.png  /tmp/g7.png
/tmp/g2.png  /tmp/g4.png  /tmp/g6.png  /tmp/g8.png

Each shows the structure of the tree, after something changed. It shows
how a page is split, and then the downlink to it is inserted into the
parent as a separate step. I've attached those files in
graphs-example.tar. I view them with "eog /tmp/g*.png", it lets you flip
through the pictures easily.

To install this hack, do the following:

1. Patch pageinspect contrib module to not lock the pages while it looks
at them. (otherwise you won't be able to snapshot transient states where
a backend is holding pages locked)

2. Install extensions pageinspect and pgstattuple:

create extension pageinspect;
create extension pgstattuple;

3. Run btree-graphviz2.sql. It creates a bunch of functions.

That's it. Have fun :-)

- Heikki

Attachment

pgsql-hackers by date:

Previous
From: Peter Geoghegan
Date:
Subject: Re: Failure while inserting parent tuple to B-tree is not fun
Next
From: Alvaro Herrera
Date:
Subject: Re: [PATCH] Use MAP_HUGETLB where supported (v3)