<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/postgres-19-compression-from-pglz-to-lz4-p8yrk9v3c" -->

---
title: Postgres 19 Compression: from pglz to LZ4 | daily.dev
description: Postgres 19 is switching its default TOAST compression algorithm from pglz to LZ4. The post covers the history of Postgres compression starting from version...
canonical: https://daily.dev/posts/postgres-19-compression-from-pglz-to-lz4-p8yrk9v3c
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Postgres 19 Compression: from pglz to LZ4 | daily.dev
og:description: Postgres 19 is switching its default TOAST compression algorithm from pglz to LZ4. The post covers the history of Postgres compression starting from version...
og:url: https://daily.dev/posts/postgres-19-compression-from-pglz-to-lz4-p8yrk9v3c
og:image: https://api.daily.dev/og/posts/p8YrK9V3C.png
og:image:alt: Postgres 19 Compression: from pglz to LZ4
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Postgres 19 Compression: from pglz to LZ4

**[Crunchy Data](https://daily.dev/sources/crunchydata)** · 9 min read · 3 upvotes · 0 comments

## Summary

Postgres 19 is switching its default TOAST compression algorithm from pglz to LZ4. The post covers the history of Postgres compression starting from version 7.0, explains why pglz was originally built (speed, minimal memory, no external dependencies), and details why LZ4 is a better fit for modern hardware — roughly 8× faster compression and better ratios due to a larger 64 kB sliding window. It also walks through Postgres storage strategies (EXTENDED, PLAIN, EXTERNAL, MAIN), the varlena format for variable-length types, the step-by-step compression decision tree Postgres uses when writing rows, and how compression works in B-tree indexes including the 510-byte threshold and the 2704-byte maximum index row size limit.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.crunchydata.com/blog/postgres-19-compression-from-pglz-to-lz4>

## Questions this post answers

### Is Postgres 19 changing the default TOAST compression algorithm from pglz to LZ4?

Yes, Postgres 19 is planned to switch the default TOAST compression algorithm from pglz to LZ4. LZ4 has been available since Postgres 14 via the default_toast_compression setting or per-column COMPRESSION lz4, but this change makes it the default rather than an opt-in choice, following the same first-optional-then-standard rollout pattern pglz itself went through decades earlier.

_Track how this default shift affects existing schemas by following Postgres 19 changes on daily.dev._

### Why is LZ4 considered better than pglz for Postgres TOAST compression?

LZ4 compresses significantly faster than pglz, roughly 8x faster in one informal test (about 6ms versus 50ms for a 2,000 row insert of ~10kB values). LZ4 also uses a larger 64kB sliding window versus pglz's 4kB window, letting it find more back-references and often achieve better compression ratios, though pglz sometimes wins depending on the data.

_Compare pglz versus LZ4 tradeoffs before tuning storage on daily.dev when evaluating Postgres compression settings._

### Why does inserting repeat('x', 5000) succeed as a B-tree indexed value while a similarly sized random string fails?

Highly repetitive data like repeat('x', 5000) compresses down to roughly 38 bytes with LZ4, easily fitting under the 2704-byte btree index row size cap (TOAST_INDEX_TARGET of 510 bytes triggers compression, about 1/16 of an 8kB page). Random or pseudo-random data of the same length compresses to nearly its original size, exceeding the cap and causing an index row size error.

_Debug btree index size errors with concrete compression thresholds like these on daily.dev._

## Similar posts on daily.dev

- [All Your GUCs in a Row: default\_toast\_compression](https://daily.dev/posts/all-your-gucs-in-a-row-default-toast-compression-qjk0nja2b) · Planet PostgreSQL · 0 upvotes · 0 comments
- [Using JSON: json vs. jsonb, pglz vs. lz4, key optimization, parsing speed? – select \* from depesz;](https://daily.dev/posts/using-json-json-vs-jsonb-pglz-vs-lz4-key-optimization-parsing-speed-select-from-depesz--bua0yvhuq) · depesz · 3 upvotes · 0 comments
- [pgBackRest Compression: How Much CPU Is a Smaller Backup Worth?](https://daily.dev/posts/pgbackrest-compression-how-much-cpu-is-a-smaller-backup-worth--ummheq8vi) · Percona Blog · 18 upvotes · 8 comments

---

Tags: [#postgresql](https://daily.dev/tags/postgresql), [#compression](https://daily.dev/tags/compression)

[View this post on daily.dev](https://daily.dev/posts/postgres-19-compression-from-pglz-to-lz4-p8yrk9v3c)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Postgres 19 Compression: from pglz to LZ4","url":"https://daily.dev/posts/postgres-19-compression-from-pglz-to-lz4-p8yrk9v3c","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/postgres-19-compression-from-pglz-to-lz4-p8yrk9v3c"},"datePublished":"2026-07-16T17:25:57.547Z","dateModified":"2026-09-14T08:15:29.323Z","description":"Postgres 19 is switching its default TOAST compression algorithm from pglz to LZ4. The post covers the history of Postgres compression starting from version...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/147d1a8e51b6ed94fc28e7b6b22657c4?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/147d1a8e51b6ed94fc28e7b6b22657c4?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Crunchy Data","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Crunchy Data","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/689da8cf2d2a4fa4b09736e4f4b18fce","url":"https://daily.dev/sources/crunchydata"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/postgres-19-compression-from-pglz-to-lz4-p8yrk9v3c","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":3},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"postgresql,compression","timeRequired":"PT9M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Crunchy Data","item":"https://daily.dev/sources/crunchydata"},{"@type":"ListItem","position":3,"name":"Postgres 19 Compression: from pglz to LZ4"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/postgres-19-compression-from-pglz-to-lz4-p8yrk9v3c#faq","mainEntity":[{"@type":"Question","name":"Is Postgres 19 changing the default TOAST compression algorithm from pglz to LZ4?","acceptedAnswer":{"@type":"Answer","text":"Yes, Postgres 19 is planned to switch the default TOAST compression algorithm from pglz to LZ4. LZ4 has been available since Postgres 14 via the default_toast_compression setting or per-column COMPRESSION lz4, but this change makes it the default rather than an opt-in choice, following the same first-optional-then-standard rollout pattern pglz itself went through decades earlier. Track how this default shift affects existing schemas by following Postgres 19 changes on daily.dev."}},{"@type":"Question","name":"Why is LZ4 considered better than pglz for Postgres TOAST compression?","acceptedAnswer":{"@type":"Answer","text":"LZ4 compresses significantly faster than pglz, roughly 8x faster in one informal test (about 6ms versus 50ms for a 2,000 row insert of ~10kB values). LZ4 also uses a larger 64kB sliding window versus pglz's 4kB window, letting it find more back-references and often achieve better compression ratios, though pglz sometimes wins depending on the data. Compare pglz versus LZ4 tradeoffs before tuning storage on daily.dev when evaluating Postgres compression settings."}},{"@type":"Question","name":"Why does inserting repeat('x', 5000) succeed as a B-tree indexed value while a similarly sized random string fails?","acceptedAnswer":{"@type":"Answer","text":"Highly repetitive data like repeat('x', 5000) compresses down to roughly 38 bytes with LZ4, easily fitting under the 2704-byte btree index row size cap (TOAST_INDEX_TARGET of 510 bytes triggers compression, about 1/16 of an 8kB page). Random or pseudo-random data of the same length compresses to nearly its original size, exceeding the cap and causing an index row size error. Debug btree index size errors with concrete compression thresholds like these on daily.dev."}}]}
```

