<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Kolmos</title>
    <description>The latest articles on DEV Community by Kolmos (@kolmos).</description>
    <link>https://dev.to/kolmos</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4108345%2Fc326d413-0faf-4797-8ab6-2e14bd328531.png</url>
      <title>DEV Community: Kolmos</title>
      <link>https://dev.to/kolmos</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kolmos"/>
    <language>en</language>
    <item>
      <title>PostgreSQL Compression: How to Reduce Database Storage Without Sacrificing Performance</title>
      <dc:creator>Kolmos</dc:creator>
      <pubDate>Mon, 16 Nov 2026 14:09:44 +0000</pubDate>
      <link>https://dev.to/kolmos/postgresql-compression-how-to-reduce-database-storage-without-sacrificing-performance-1f52</link>
      <guid>https://dev.to/kolmos/postgresql-compression-how-to-reduce-database-storage-without-sacrificing-performance-1f52</guid>
      <description>&lt;h1&gt;
  
  
  How PostgreSQL Compression Works &amp;amp; How to Reduce Database Storage
&lt;/h1&gt;

&lt;p&gt;PostgreSQL is the world's most loved relational database, but as analytical event streams, time-series metrics, and transactional tables scale into millions of rows, database storage bills can explode on AWS RDS, Aurora, and managed cloud providers.&lt;/p&gt;

&lt;p&gt;In this deep dive, we break down how PostgreSQL compression actually works under the hood, what options you have natively, and how to achieve up to 88% storage reduction.&lt;/p&gt;




&lt;h2&gt;
  
  
  How Does PostgreSQL Compression Work?
&lt;/h2&gt;

&lt;p&gt;PostgreSQL uses &lt;strong&gt;TOAST (The Oversized-Attribute Storage Technique)&lt;/strong&gt; to automatically compress or split variable-length column values (such as &lt;code&gt;TEXT&lt;/code&gt;, &lt;code&gt;JSONB&lt;/code&gt;, and &lt;code&gt;BYTEA&lt;/code&gt;) whenever a row exceeds roughly &lt;strong&gt;2 KB&lt;/strong&gt; inside a standard &lt;strong&gt;8 KB heap page&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;Fixed-width columns (&lt;code&gt;INTEGER&lt;/code&gt;, &lt;code&gt;BIGINT&lt;/code&gt;, &lt;code&gt;TIMESTAMP&lt;/code&gt;, &lt;code&gt;UUID&lt;/code&gt;) are &lt;strong&gt;not&lt;/strong&gt; compressed by TOAST on standard heap pages unless moved into a specialized columnar engine.&lt;/p&gt;




&lt;h2&gt;
  
  
  What Compression Options Does PostgreSQL Have?
&lt;/h2&gt;

&lt;p&gt;Built-in PostgreSQL offers three native compression algorithms across three subsystems:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;pglz&lt;/code&gt;&lt;/strong&gt; — Legacy default TOAST column compression (higher CPU overhead, slower decompression).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;lz4&lt;/code&gt;&lt;/strong&gt; — High-speed TOAST column compression (PostgreSQL 14+) and WAL compression (PostgreSQL 15+).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;zstd&lt;/code&gt; (Zstandard)&lt;/strong&gt; — High-ratio compression for &lt;strong&gt;WAL full-page writes&lt;/strong&gt; (&lt;code&gt;wal_compression = zstd&lt;/code&gt;, PostgreSQL 15+) and &lt;strong&gt;backups&lt;/strong&gt; (&lt;code&gt;pg_basebackup --compress=zstd&lt;/code&gt; &amp;amp; &lt;code&gt;pg_dump&lt;/code&gt;, PostgreSQL 15/16+).&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  PostgreSQL Compression Options Compared
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Subsystem / Layer&lt;/th&gt;
&lt;th&gt;Available Algorithms&lt;/th&gt;
&lt;th&gt;Config / SQL Syntax&lt;/th&gt;
&lt;th&gt;Min PG Version&lt;/th&gt;
&lt;th&gt;Typical Reduction &amp;amp; Trade-Off&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;TOAST Column Storage&lt;/strong&gt; (&lt;code&gt;TEXT&lt;/code&gt;, &lt;code&gt;JSONB&lt;/code&gt; &amp;gt; 2 KB)&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;pglz&lt;/code&gt; (default), &lt;code&gt;lz4&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;&lt;code&gt;SET default_toast_compression = 'lz4';&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;PG 14+ (&lt;code&gt;lz4&lt;/code&gt;)&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;1.5×–3× on large attributes.&lt;/strong&gt; &lt;code&gt;lz4&lt;/code&gt; decodes 3×–5× faster than &lt;code&gt;pglz&lt;/code&gt; with minimal CPU overhead.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;WAL Full-Page Images&lt;/strong&gt; (Write-Ahead Log)&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;pglz&lt;/code&gt;, &lt;code&gt;lz4&lt;/code&gt;, &lt;code&gt;zstd&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;wal_compression = 'zstd'&lt;/code&gt; in &lt;code&gt;postgresql.conf&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;PG 15+ (&lt;code&gt;lz4&lt;/code&gt;, &lt;code&gt;zstd&lt;/code&gt;)&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;30%–60% smaller WAL volume.&lt;/strong&gt; Cuts I/O spikes after checkpoints and lowers replication bandwidth.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Base Backups &amp;amp; Logical Dumps&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;gzip&lt;/code&gt;, &lt;code&gt;lz4&lt;/code&gt;, &lt;code&gt;zstd&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;pg_basebackup -Z zstd:5&lt;/code&gt; or &lt;code&gt;pg_dump -Fc -Z zstd&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;PG 15+ / 16+&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;3×–6× smaller backups.&lt;/strong&gt; &lt;code&gt;zstd&lt;/code&gt; beats &lt;code&gt;gzip&lt;/code&gt; on both compression ratio and backup speed.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;B-Tree Indexes&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Key Deduplication&lt;/td&gt;
&lt;td&gt;Enabled by default (&lt;code&gt;deduplicate_items = on&lt;/code&gt;)&lt;/td&gt;
&lt;td&gt;PG 13+&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;20%–60% smaller non-unique indexes&lt;/strong&gt; by collapsing duplicate keys.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Full-Table Columnar Storage&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Columnar Dictionary, Delta, Bit-packing&lt;/td&gt;
&lt;td&gt;External wire-compatible columnar engine (&lt;a href="https://kolmos.dev" rel="noopener noreferrer"&gt;KOLMOS&lt;/a&gt;)&lt;/td&gt;
&lt;td&gt;Any (via Port 5432)&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;4×–8× smaller total footprint.&lt;/strong&gt; Compresses every column type, not just large strings.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  4 Practical Steps to Cut Storage Costs Immediately
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Upgrade TOAST Compression to LZ4
&lt;/h3&gt;

&lt;p&gt;If you are running PostgreSQL 14 or newer, immediately switch your default TOAST compression from &lt;code&gt;pglz&lt;/code&gt; to &lt;code&gt;lz4&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="n"&gt;default_toast_compression&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'lz4'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;ALTER&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;production_events&lt;/span&gt; &lt;span class="k"&gt;ALTER&lt;/span&gt; &lt;span class="k"&gt;COLUMN&lt;/span&gt; &lt;span class="n"&gt;payload&lt;/span&gt; &lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="no"&gt;COMPRESSION&lt;/span&gt; &lt;span class="n"&gt;lz4&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Enable Zstandard for WAL
&lt;/h3&gt;

&lt;p&gt;On PostgreSQL 15+, enable zstd WAL compression in &lt;code&gt;postgresql.conf&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ini"&gt;&lt;code&gt;&lt;span class="na"&gt;wal_compression&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;zstd&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This reduces WAL write amplification by 30% to 50% without impacting transactional commit latency.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Eliminate Table Bloat with Autovacuum Tuning
&lt;/h3&gt;

&lt;p&gt;Compressing tables that contain dead tuples wastes disk and CPU. Ensure &lt;code&gt;autovacuum_vacuum_scale_factor&lt;/code&gt; is tuned down from &lt;code&gt;0.2&lt;/code&gt; to &lt;code&gt;0.05&lt;/code&gt; on high-churn tables:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;ALTER&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;user_activity&lt;/span&gt; &lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;autovacuum_vacuum_scale_factor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;0.05&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4. Move Historical Analytical Data to Columnar Storage
&lt;/h3&gt;

&lt;p&gt;Row-oriented 8KB heap pages are fundamentally inefficient for historical tables and analytics because reading even one column forces the entire 8KB page into RAM. &lt;/p&gt;

&lt;p&gt;For high-volume append logs, time-series metrics, and transactional history, storing data in columnar format cuts storage footprints by &lt;strong&gt;up to 88%&lt;/strong&gt; and offloads to zero-egress cloud object storage.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Read the full in-depth guide, benchmarks, and interactive storage calculator on &lt;a href="https://kolmos.dev/blog/postgresql-compression-how-to-reduce-database-storage-without-sacrificing-performance" rel="noopener noreferrer"&gt;kolmos.dev/blog&lt;/a&gt; and explore our live benchmark suite at &lt;a href="https://kolmos.dev/benchmarks" rel="noopener noreferrer"&gt;kolmos.dev/benchmarks&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>postgres</category>
      <category>database</category>
      <category>rust</category>
      <category>performance</category>
    </item>
  </channel>
</rss>
