PostgreSQL 17 Overview
PostgreSQL 17 is a major release featuring SQL/JSON standard compliance for JSONB, incremental backup, and significant performance improvements.
SQL/JSON Standard Support
JSON_TABLE
Handle JSON data as relational tables.
SELECT *
FROM JSON_TABLE(
'[{"id": 1, "name": "Alice"}, {"id": 2, "name": "Bob"}]',
'$[*]'
COLUMNS (
id INT PATH '$.id',
name TEXT PATH '$.name'
)
) AS users;
-- Result:
-- id | name
-- ---+------
-- 1 | Alice
-- 2 | Bob
JSON_QUERY / JSON_VALUE
-- JSON_VALUE: Get scalar value
SELECT JSON_VALUE(data, '$.user.name') as name
FROM events;
-- JSON_QUERY: Get JSON value (array/object)
SELECT JSON_QUERY(data, '$.user.tags' WITH WRAPPER) as tags
FROM events;
JSON_EXISTS
-- Check if JSON matching condition exists
SELECT *
FROM products
WHERE JSON_EXISTS(attributes, '$.colors[*] ? (@ == "red")');
Incremental Backup
Back up only changes since the last backup.
# Take full backup
pg_basebackup -D /backup/base --checkpoint=fast
# Take incremental backup
pg_basebackup -D /backup/incr1 \
--incremental=/backup/base/backup_manifest
# Merge during restore
pg_combinebackup /backup/base /backup/incr1 -o /restore
Benefits
| Item | Full Backup | Incremental |
|---|---|---|
| Time | Long | Short |
| Size | Large | Small |
| Restore | Simple | Merge required |
Performance Improvements
VACUUM Speedup
PostgreSQL 16 vs 17:
- Large table VACUUM: Up to 20x faster
- Memory usage: Up to 20x reduction
I/O Optimization
-- New I/O statistics
SELECT * FROM pg_stat_io;
-- Results include I/O statistics per backend type
Index Improvements
-- BRIN (Block Range Index) improvements
CREATE INDEX ON events USING BRIN (created_at)
WITH (pages_per_range = 32);
-- More efficient multi-column BRIN
New Features
MERGE Statement Extensions
MERGE INTO inventory t
USING new_items s
ON t.product_id = s.product_id
WHEN MATCHED THEN
UPDATE SET quantity = t.quantity + s.quantity
WHEN NOT MATCHED THEN
INSERT (product_id, quantity)
VALUES (s.product_id, s.quantity)
RETURNING *; -- Added in PostgreSQL 17
Partial Aggregate Pushdown
-- Faster aggregation on partitioned tables
SELECT date_trunc('month', created_at), COUNT(*)
FROM events -- Partitioned table
GROUP BY 1;
New System Views
-- Progress of running queries
SELECT * FROM pg_stat_progress_copy;
SELECT * FROM pg_stat_progress_basebackup;
Logical Replication Improvements
Failover Slots
-- Sync replication slots on standby server
ALTER SUBSCRIPTION my_sub
SET (failover = true);
Conflict Resolution on Subscriber
-- Configure behavior on conflict
ALTER SUBSCRIPTION my_sub
SET (disable_on_error = false);
Migration Tips
# Pre-upgrade check
pg_upgrade --check
# Upgrade with pg_upgrade
pg_upgrade \
-b /usr/lib/postgresql/16/bin \
-B /usr/lib/postgresql/17/bin \
-d /var/lib/postgresql/16/main \
-D /var/lib/postgresql/17/main
Summary
PostgreSQL 17 makes enterprise use even easier with SQL/JSON standard compliance, incremental backup, and significant performance improvements. Applications handling JSON data will particularly benefit from the new JSON functions.
← Back to list