Postgres Is Releasing An Incredible New Feature
Key Takeaway
Postgres 19 introduces major performance and syntax upgrades, including native graph queries, atomic insert-or-select operations, and built-in table disk space reclamation.
Highlights
Postgres 19 introduces native graph query support, eliminating complex multi-table join syntax for related data.
The new on conflict do select clause enables atomic insert-or-select operations in a single query.
A built-in repack feature rewrites tables to reclaim unused disk space without locking tables when using the concurrently keyword.
A new module called pg plan advice allows developers to capture and pin fast query execution plans.
Just-in-Time compilation is now turned off by default due to unreliable cost estimates.
Timeline
On Conflict Do Select
Standard workflows requiring an insert followed by a select lacked atomicity. Postgres 19 solves this by adding an on conflict do select clause to single statements. This update simplifies common code patterns for checking and returning existing records.
- A single query handles inserting a row or returning it if it already exists.
- The operation is atomic, preventing race conditions between separate insert and select statements.
- The syntax supports row-level locking modifiers like for update.
Native Graph Queries
Complex database schemas involving customers, orders, and products previously required lengthy join syntax across multiple pivot tables. Postgres 19 lets developers define a property graph pointing to existing tables. This allows simpler query patterns while keeping the underlying schema intact.
- Property graphs define vertices and edges using existing tables without altering the underlying schema.
- Graph syntax replaces long chains of table joins with simpler traversal patterns.
- Dedicated graph databases remain superior for heavy storage and traversal performance needs.
Built-in Repack for Disk Space
Postgres updates write new row versions rather than modifying them in place, leaving dead space behind. While vacuum made this space reusable, it never decreased actual disk usage. Postgres 19 includes a built-in repack feature that removes wasted space without requiring external extensions like pg repack.
- Vacuum only marks dead space reusable without returning disk space to the operating system.
- The new built-in repack command rewrites tables into fresh files to reclaim physical disk space.
- Using the concurrently keyword keeps tables readable and writable during the rewrite process.
Query Hints and Additional Features
The Postgres 19 release includes several smaller enhancements aimed at developer workflow and performance tuning. Query execution plans can now be locked to prevent performance regressions caused by shifting planner decisions. Additionally, parallel workers speed up index cleanup during vacuum operations.
- The pg plan advice module captures and pins fast query execution plans.
- JIT compilation is disabled by default due to unreliable planner cost estimates.
- The copy keyword now supports direct export to JSON format.
Description
Postgres 19 is close, and it brings native graph queries to the database you already run. Writing five table joins to answer one simple question has been the price of a relational schema for decades. Plus ON CONFLICT DO SELECT, REPACK, and the smaller wins worth knowing before you upgrade. 🔗 Relevant Links https://www.postgresql.org/docs/19/release-19.html ❤️ More about us Radically better observability stack: https://betterstack.com/ Written tutorials: https://betterstack.com/community/ Example projects: https://github.com/BetterStackHQ 📱 Socials Twitter: https://twitter.com/betterstackhq Instagram: https://www.instagram.com/betterstackhq/ TikTok: https://www.tiktok.com/@betterstack LinkedIn: https://www.linkedin.com/company/betterstack 📌 Chapters: 00:00 Intro 00:30 ON CONFLICT DO SELECT 01:38 Native graph queries 02:13 Demo: joins vs. graph syntax 03:32 CREATE PROPERTY GRAPH 04:48 Does this replace Neo4j? 05:10 REPACK and reclaiming disk space 06:09 Quick fire: hints, JIT, vacuum, COPY 07:11 Release timing
