PostgreSQL 17 introduces a host of exciting features and improvements that enhance performance, usability, and scalability. This tutorial will guide you through some of the most significant updates in PostgreSQL 17, helping you make the most of the new capabilities.
PostgreSQL 17 introduces a brand-new memory manager for VACUUM, which significantly reduces RAM spikes and speeds up vacuuming of large tables. This improvement makes maintenance operations more predictable and efficient.
To vacuum a table with the new memory manager:
VACUUM (FULL) my_large_table;
PostgreSQL 17 introduces several SQL/JSON++ features, including JSON_TABLE()
, identity constructors, and full JSON path query support. These features make it easier to work with JSON data without resorting to PL/pgSQL hacks.
Given the following JSON data:
{
"users": [
{"name": "John Doe", "age": 30},
{"name": "Jane Smith", "age": 25}
]
}
You can use JSON_TABLE()
to shred the JSON into rows:
SELECT *
FROM JSON_TABLE(
'{"users":[{"name":"John Doe","age":30},{"name":"Jane Smith","age":25}]}',
'$.users[*]' COLUMNS (
name TEXT PATH '$.name',
age INT PATH '$.age'
)
) AS users;
This will return: | name | age | |-----------|-----| | John Doe | 30 | | Jane Smith | 25 |
PostgreSQL 17 introduces Logical Replication 2.0, which includes built-in fail-over control, pg_createsubscriber
, and improved pg_upgrade
that maintains replication slots for zero-downtime switchover.
To create a subscriber:
SELECT pg_createsubscriber('my_subscriber', 'my_publisher');
PostgreSQL 17 introduces incremental base backups using pg_basebackup --incremental
. This feature only ships changed blocks, making it ideal for cheap and efficient long-term retention in storage systems like S3.
To perform an incremental base backup:
pg_basebackup --incremental --pgdata=/var/lib/postgresql/data --write-recovery-conf
PostgreSQL 17 introduces the sslnegotiation=direct
option, which skips unnecessary SSL negotiation round-trips for faster connections.
To enable direct SSL negotiation, update your postgresql.conf
:
sslnegotiation = direct
PostgreSQL 17 introduces COPY ... ON_ERROR ignore
, which allows you to ignore errors during large data ingests and keeps the process alive.
To ignore errors during a COPY operation:
COPY my_table (name, age)
FROM 'data.csv'
ON_ERROR IGNORE;
PostgreSQL 17 supports both dump/restore
and pg_upgrade
for upgrades. Note that some statistics columns have been renamed, and old_snapshot_threshold
has been removed.
pg_dump
and pg_restore
if you prefer a dump/restore approach.pg_upgrade
for in-place upgrades.To upgrade using pg_upgrade
:
pg_upgrade --old-datadir=/var/lib/postgresql/old --new-datadir=/var/lib/postgresql/new
PostgreSQL 17 brings significant improvements in performance, usability, and scalability. From the VACUUM overhaul to incremental base backups, these features make PostgreSQL 17 a powerful and efficient database system. By leveraging these new capabilities, you can optimize your database operations and take advantage of the latest advancements in PostgreSQL.