Skip to content

Commit 35465fb

Browse files
committed
tweak readme
1 parent b0229fb commit 35465fb

1 file changed

Lines changed: 24 additions & 6 deletions

File tree

README.md

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,41 @@ A PostgreSQL extension that enforces optimal column alignment to minimize row pa
55
<img src="logo.jpg" alt="pg_column_tetris logo" width="230">
66

77

8-
## Why It Matters
8+
## Why Column Order Matters
99

10-
PostgreSQL aligns columns to their type's natural boundary (1, 2, 4, or 8 bytes). When columns are ordered poorly, padding bytes fill the gaps. These wasted bytes don't just cost disk space — they cost **memory**. Padding is loaded as-is into `shared_buffers` and OS page cache, meaning more bytes per row → fewer rows per 8 KB page → more cache pressure → more disk I/O.
10+
Every heap tuple in PostgreSQL starts with a 23-byte header, followed by a null bitmap, then the actual column data. Each column must start at an address that is a multiple of its type's alignment requirement — `bigint` needs an 8-byte boundary, `integer` needs 4, `smallint` needs 2, and `boolean` just 1. When a column's natural offset doesn't land on its required boundary, PostgreSQL inserts invisible **padding bytes** to close the gap.
1111

12-
For a table with millions of rows, reordering columns can reclaim gigabytes of memory.
12+
Consider this table:
13+
14+
```
15+
boolean (1 byte) | 7 bytes padding | bigint (8 bytes) | integer (4 bytes) | 4 bytes padding
16+
```
17+
18+
That's 11 bytes of wasted padding in a single row. Reorder the columns largest-first and the padding drops to zero:
19+
20+
```
21+
bigint (8 bytes) | integer (4 bytes) | boolean (1 byte) | no padding
22+
```
23+
24+
This padding isn't just on disk — it's loaded as-is into `shared_buffers` and the OS page cache. More bytes per row means fewer rows per 8 KB page, more cache pressure, and more disk I/O. For a table with millions of rows, fixing column order can reclaim gigabytes of memory.
1325

1426
## Installation
1527

28+
Pure SQL/PL/pgSQL — no compilation needed.
29+
30+
### Self-hosted PostgreSQL
31+
1632
```bash
17-
# From source
1833
make install
34+
```
1935

20-
# Then in PostgreSQL
36+
```sql
2137
CREATE EXTENSION pg_column_tetris;
2238
```
2339

24-
No compilation needed — pure SQL/PL/pgSQL. Works on any PostgreSQL instance that supports event triggers (RDS, Cloud SQL, Supabase, Neon, etc.).
40+
### Managed services
41+
42+
Most managed PostgreSQL providers (RDS, Cloud SQL, etc.) don't allow installing custom extensions or creating event triggers. This extension requires a self-hosted instance or a provider that supports custom extensions (e.g. [Supabase](https://supabase.com), [Neon](https://neon.tech) custom builds).
2543

2644
## Quick Start
2745

0 commit comments

Comments
 (0)