Skip to content

Database Index Size Calculator

Estimate the size of a B-tree index in PostgreSQL or MySQL InnoDB from the row count and key size: pages, levels, bytes per row and growth.

Calculator Details

Estimated index size:224.6 MBSee results ↓

PostgreSQL B-tree index, or a MySQL InnoDB secondary index

Rows in the table (entries in the index)

Total of the indexed columns: integer 4, bigint 8, timestamp 8, uuid 16, short text = length + 1

Your Results

Estimated index size: 224.6 MB

Estimated index size

224.6 MB

214.2 MiB · 224,641,024 bytes

Pages

27,422

8 KB each; 27,323 leaf pages

Tree levels

3

Pages read to find one key (most are cached)

Bytes per row

22.5

Raw key data 80 MB

A PostgreSQL B-tree index of this size takes about 224.641 MB (27,422 pages of 8 KB, 3 levels), 22.464 bytes per row.

Compare scenarios

Save these inputs as a scenario, change them, and compare the results side by side.

Loading, available in a moment

Index size as the table grows

Index size as the table grows

Detailed Breakdown

Pages by level of the B-tree
LevelPagesSize
Leaf27,323223.8 MB
Internal 197794.6 kB
Root18.2 kB
Metapage18.2 kB

366 entries per leaf page (20 bytes each) and 284 per internal page.

How This Calculator Works

How it's calculated

entry = round up to 8 (8-byte header + key) + 4-byte pointer

entries per page = (8,192 − 40 bytes of headers − 8,192 × (100 − fill factor)%) ÷ entry, rounded down

leaf pages = rows ÷ entries per leaf page; each level above = pages below ÷ entries per internal page, up to one root

Your numbers: each entry takes 20 bytes, so a leaf page at 90% holds 366. 10,000,000 rows ÷ 366 = 27,323 leaf pages; the levels above add 98 and the metapage 1, 27,422 pages × 8,192 bytes = 224,641,024 bytes.

Frequently Asked Questions

How big is a PostgreSQL index on an integer column?

About 22 MB per million rows when freshly built: each entry takes 20 bytes (an 8-byte header and the 4-byte key padded to 16, plus a 4-byte pointer), and pages are filled to 90%. A million-row int index is 2,745 pages of 8 KB, 22,487,040 bytes.

Is a bigint index bigger than an integer index in PostgreSQL?

No. On 64-bit systems index tuples are padded to a multiple of 8 bytes, so a 4-byte integer and an 8-byte bigint both make a 16-byte tuple, and the indexes are the same size. A 16-byte uuid makes 24-byte tuples, about 40% larger.

Why are MySQL secondary indexes affected by the primary key?

InnoDB stores the primary key in every secondary index record, so it can find the row in the clustered index. A long primary key, such as a 36-character uuid stored as text, makes every secondary index on the table larger. Store UUIDs as BINARY(16) to keep them small.

Why is my real index bigger than the estimate?

Usually because rows were inserted in random order or have been updated and deleted. Page splits leave pages around 70% full instead of 90–100%, and dead entries wait for vacuum (PostgreSQL) or purge (InnoDB). Set the fill factor to 70% to model a randomly filled index; REINDEX or OPTIMIZE TABLE rebuilds it compactly.

How do I check an index’s actual size?

In PostgreSQL, select pg_relation_size('index_name'), or wrap it in pg_size_pretty() for MB and GB. In MySQL, look up the index’s row with stat_name = 'size' in mysql.innodb_index_stats: its stat_value is the number of pages, so multiply it by @@innodb_page_size.

What does the fill factor do?

It sets how full pages are left when an index is built, leaving the rest free for later inserts so pages don’t split straight away. PostgreSQL B-trees default to 90%; MySQL’s innodb_fill_factor defaults to 100. A lower fill factor makes the index larger but can reduce page splits on tables with many updates in the middle of the key range.

How many levels does a B-tree have?

Very few, because each page holds hundreds of entries. Ten million bigint keys in PostgreSQL fit in 3 levels; a billion would need 4. Finding a key reads one page per level, and the upper levels are almost always in memory.

Included: a freshly built B-tree index with unique keys of a fixed size, using PostgreSQL 18's page layout (8 KB pages, 8-byte alignment, leaf fill factor, internal pages at 70%, metapage) or a MySQL 8.4 InnoDB secondary index (16 KB pages, 5-byte record headers, the primary key in every record). The InnoDB page overheads come from MySQL's source rather than its manual and are marked for review. Left out: PostgreSQL deduplication of repeated keys (version 13+, which shrinks indexes on low-cardinality columns), NULLs and variable-length key headers beyond what you enter, compression, bloat from updates and deletes, InnoDB extent allocation (indexes grow in 1 MB steps once past 32 pages), and other index types (GIN, GiST, hash, BRIN, full-text).

Database Index Size Calculator: PostgreSQL and MySQL B-tree Estimates

By FindMySum · Last reviewed

An index size calculator estimates how much disk and memory a B-tree index will take before you create it. Enter the number of rows and the size of the indexed key, choose PostgreSQL or MySQL, and the calculator works through the database's page layout to give the number of pages, the tree's height, the size in megabytes and the cost per row. It is useful when planning a new index on a large table, comparing key types such as bigint and UUID, or checking whether an existing index has bloated.

How a B-tree index is stored

Both PostgreSQL and MySQL's InnoDB store B-tree indexes in fixed-size pages: 8 KB in PostgreSQL and 16 KB in InnoDB by default. The leaf pages hold one entry per row, in key order, each pointing to the row. Above them, internal pages hold one entry per page below, until a single root page covers everything. Because each page holds hundreds of entries, even huge indexes are only three or four levels deep.

The size of an index is therefore the number of pages times the page size, and the number of pages depends on how many entries fit on one.

PostgreSQL

In PostgreSQL every page starts with a 24-byte header, and B-tree pages end with 16 bytes of special space for sibling links. Each entry is an index tuple, an 8-byte header plus the key, padded to a multiple of 8 bytes on 64-bit systems, and a 4-byte line pointer in the page's item array. When an index is built, leaf pages are filled to the fill factor (90% by default) and internal pages to 70%.

For the default example, a bigint key: 8 + 8 = 16 bytes, already a multiple of 8, plus the 4-byte pointer, makes 20 bytes per entry. A leaf page has 8,192 − 40 = 8,152 usable bytes, less the 819 bytes the 90% fill factor leaves free, so 366 entries fit. Ten million rows need 27,323 leaf pages; the internal levels add 98 pages and the metapage 1, for 27,422 pages or about 225 MB, 22.5 bytes per row.

The padding has a surprising consequence: an index on a 4-byte integer is exactly the same size as one on an 8-byte bigint. The check against real databases is reassuring here: a million-row integer index built this way is 2,745 pages, the figure PostgreSQL itself reports.

MySQL InnoDB

InnoDB secondary index records have a 5-byte header, the indexed columns and, crucially, the table's primary key, which InnoDB uses to find the row in the clustered index. Pages carry about 128 bytes of headers, trailer and boundary records, plus a 2-byte directory slot for every few records. With a bigint key and a bigint primary key, each record is 21 bytes and a full 16 KB page holds 755 of them; ten million rows take 13,268 pages, about 217 MB.

Because the primary key is copied into every secondary index, a wide primary key inflates them all. A UUID stored as 36 characters of text costs 37 bytes per record per index; stored as BINARY(16) it costs 16.

Why real indexes are often bigger

The calculator gives the size of an index built in one pass, or filled with keys in increasing order, such as an auto-increment ID or a timestamp. Indexes filled in random order behave differently. When a new key lands on a full page, the page splits into two half-full pages, and over time leaf pages settle around 70% full. Random UUIDv4 primary keys are the classic case. Choose a 70% fill factor in the advanced options to model it.

Updates and deletes add more: dead entries remain until vacuum (PostgreSQL) or purge (InnoDB) removes them, and freed space inside a page is only reused by keys that belong there. Rebuilding the index with REINDEX or OPTIMIZE TABLE returns it to the compact size.

Using the estimate

Two numbers matter most. The total size tells you the disk you need and how long building or rebuilding the index will take. The leaf size compared with your memory (PostgreSQL's shared_buffers and the operating system cache, or InnoDB's buffer pool) tells you whether lookups will be served from memory. The bar chart shows how the size grows as the table does: linearly with the rows, with the tree adding a level only every few hundred times the row count.

More questions

Do indexes need to fit in memory?

Ideally the parts you use often should. The upper levels of a B-tree are small and stay cached; the leaf pages are where most of the size is. If the leaves of a busy index don't fit in the buffer pool or shared buffers, lookups start reading from disk. Compare the index size with your cache memory, not your disk.

How much does a composite index cost?

Add the sizes of all its columns to get the key size. A PostgreSQL index on (user_id bigint, created_at timestamp) has a 16-byte key, padded tuples of 24 bytes and 28-byte entries, about 40% larger than an index on user_id alone. Put the column you filter on with equality first.

What is index deduplication in PostgreSQL?

Since PostgreSQL 13, a B-tree can store a repeated key once with a list of row pointers, instead of repeating the key for every row. Indexes on columns with few distinct values, such as status or country, shrink a lot. Unique and nearly unique columns don't benefit, which is what this calculator assumes.

Are partial indexes smaller?

Yes. A partial index only includes rows matching its WHERE clause, so enter only those rows. An index on unprocessed jobs (WHERE processed = false) can stay tiny even when the table holds millions of finished ones.

Why does my PostgreSQL index grow even though the row count is stable?

Updates create new row versions, and every index gets an entry for the new version unless the update is a HOT update that changes no indexed column and fits on the same page. Old entries are cleaned up by vacuum, but the pages they free are reused only within the same index. Frequent updates to indexed columns cause this bloat; REINDEX CONCURRENTLY rebuilds it.

Sources

This article explains how the calculator works and is general information, not financial, tax, legal or medical advice. Rules change; check the sources above or a qualified professional before you act.

Spotted a wrong result or a bug? Report a problem

May we count your visits with Invoker Analytics? It keeps a random visitor number in your browser. Your calculator inputs are never sent. Privacy policy