You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
11
11
12
-
For a table with millions of rows, reordering columns can reclaim gigabytes of memory.
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.
13
25
14
26
## Installation
15
27
28
+
Pure SQL/PL/pgSQL — no compilation needed.
29
+
30
+
### Self-hosted PostgreSQL
31
+
16
32
```bash
17
-
# From source
18
33
make install
34
+
```
19
35
20
-
# Then in PostgreSQL
36
+
```sql
21
37
CREATE EXTENSION pg_column_tetris;
22
38
```
23
39
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).
0 commit comments