Search code examples
postgresqlindexingb-tree

Postgres B-Tree order and height


Is there a way to find the order of B-Tree used for the specific index in Postgres? And the actual height as well?

Is the order supposed to be fixed or rather dependent on size of the index fields (to fit the page size)?

Sort of ambiguous, the order is sometimes referred to a maximum number of children of the node, sometimes to a minimum number (for non-root node). But it's interesting either way.


Solution

  • I know of no place where you can see that information at a single glance, but you can use the B-tree functions of the “pageinspect” extension for that: bt_metap() will point you to the root node, and bt_page_stats() for the root node will show you the level btpo_level. By using bt_page_items() on a couple of index pages, you can see how many children each has.