Postgresql extension pageinspect – mean bt_metap

btreedbmspostgresqlpostgresql-extensions

I am using Postgresql extension pageinspect.

Could someone tell me the meaning of these columns: magic, version, root, level, fastroot, fastlevel of the bt_metap function.

This information is not presents in the documentation 1[https://www.postgresql.org/docs/9.6/static/pageinspect.html]

The height of the b-tree (position of node farthest from root to leaf), is the column Level?

See below a return query that I ran on an index called idx_l_shipmodelineitem000

------------------------------------------------------------------
postgres # SELECT * FROM bt_metap ('idx_l_shipmodelineitem000');
postgres # magic    | version   | root     | level | fastroot | fastlevel
postgres # 340322   | 2         | 41827 | 3       | 41827   | 3

Best regards

Best Answer

src/include/access/nbtree.h:

/*
 * The Meta page is always the first page in the btree index.
 * Its primary purpose is to point to the location of the btree root page.
 * We also point to the "fast" root, which is the current effective root;
 * see README for discussion.
 */

typedef struct BTMetaPageData
{
    uint32      btm_magic;      /* should contain BTREE_MAGIC */
    uint32      btm_version;    /* should contain BTREE_VERSION */
    BlockNumber btm_root;       /* current root location */
    uint32      btm_level;      /* tree level of the root page */
    BlockNumber btm_fastroot;   /* current "fast" root location */
    uint32      btm_fastlevel;  /* tree level of the "fast" root page */
} BTMetaPageData;

So I suggest reading src/backend/access/nbtree/README