Trying Out the New Features of PostgreSQL 19.0 in the Amazon RDS Database Preview Environment

Trying Out the New Features of PostgreSQL 19.0 in the Amazon RDS Database Preview Environment

REPACK (CONCURRENTLY) shrank the table and indexes, and INSERTs made during REPACK were not lost. Logical replication of sequence values worked, and pg_plan_advice and pg_stash_advice could specify execution plans.
2026.11.25

This page has been translated by machine translation. View original

Introduction

On November 23, 2026, PostgreSQL 19.0 became available in the Amazon RDS Database Preview Environment (hereafter, the Preview environment).

https://aws.amazon.com/jp/about-aws/whats-new/2026/11/postgresql-19-amazon-rds-database-preview-environment/

PostgreSQL 19 was released on November 19, 2026, and is scheduled to be supported until November 2031.

https://www.postgresql.org/about/news/postgresql-19-released-3449/

In this article, I try out REPACK, which resolves table bloat, logical replication of sequences, and the advice features that specify execution plans (pg_plan_advice and pg_stash_advice) on a DB instance in the Preview environment.

Test Environment

  • Region: us-east-2
  • Endpoint: https://rds-preview.us-east-2.amazonaws.com
  • Engine: PostgreSQL 19.0 (engine name postgres, parameter group family postgres19)
  • Instance class: db.t3.medium
  • Storage: gp3
  • Configuration: Single-AZ
  • Public access: Disabled
  • Connection source: EC2 (t3.micro) in the same VPC
  • Execution method: Run psql with Systems Manager Run Command

Creating the Instance

Parameter Group

I set the following two items in the parameter group.

  • shared_preload_libraries: Add pg_plan_advice and pg_stash_advice
  • rds.logical_replication: 1

Specify postgres19 as the family. When creating it, also specify the Preview environment endpoint.

aws rds create-db-parameter-group \
  --db-parameter-group-name <パラメータグループ名> \
  --db-parameter-group-family postgres19 \
  --description pg19-verify \
  --region us-east-2 \
  --endpoint-url https://rds-preview.us-east-2.amazonaws.com

The default value of shared_preload_libraries is pg_stat_statements,pg_tle. The value with pg_plan_advice and pg_stash_advice added to it is passed in the following params.json.

[
  {
    "ParameterName": "shared_preload_libraries",
    "ParameterValue": "pg_stat_statements,pg_tle,pg_plan_advice,pg_stash_advice",
    "ApplyMethod": "pending-reboot"
  },
  {
    "ParameterName": "rds.logical_replication",
    "ParameterValue": "1",
    "ApplyMethod": "pending-reboot"
  }
]
aws rds modify-db-parameter-group \
  --db-parameter-group-name <パラメータグループ名> \
  --parameters file://params.json \
  --region us-east-2 \
  --endpoint-url https://rds-preview.us-east-2.amazonaws.com

The apply type of both items is static.

DB Instance

I created the DB instance for the test environment with this parameter group specified. It took about 6 minutes to become available.

When I connected and checked, shared_preload_libraries contained rdsutils and rds_casts in addition to the values I had set.

SELECT version();
                                             version                                              
--------------------------------------------------------------------------------------------------
 PostgreSQL 19.0 on x86_64-pc-linux-gnu, compiled by x86_64-pc-linux-gnu-gcc (GCC) 12.4.0, 64-bit
(1 row)

SHOW shared_preload_libraries;
                          shared_preload_libraries                           
-----------------------------------------------------------------------------
 rdsutils,pg_tle,pg_stat_statements,pg_plan_advice,pg_stash_advice,rds_casts
(1 row)

SHOW rds.logical_replication;
 rds.logical_replication 
-------------------------
 on
(1 row)

SHOW wal_level;
 wal_level 
-----------
 logical
(1 row)

REPACK (CONCURRENTLY)

In this test, I ran REPACK (CONCURRENTLY) with rds.logical_replication set to on (wal_level is logical).

Shrinking Tables and Indexes

I created a table with 1 million rows, deleted 900,000 rows, ran VACUUM, and then ran REPACK (CONCURRENTLY). Autovacuum was disabled only for the target table. There are three indexes: the primary key, the k column, and the payload column.

CREATE TABLE bloat_t (id serial PRIMARY KEY, payload text, k int, ins_at timestamptz DEFAULT clock_timestamp()) WITH (autovacuum_enabled = false);
INSERT INTO bloat_t (payload, k) SELECT md5(g::text) || md5((g+1)::text), g % 1000 FROM generate_series(1, 1000000) g;
CREATE INDEX bloat_t_k_idx ON bloat_t (k);
CREATE INDEX bloat_t_payload_idx ON bloat_t (payload);
ANALYZE bloat_t;
DELETE FROM bloat_t WHERE id % 10 <> 0;
VACUUM bloat_t;
REPACK (CONCURRENTLY, VERBOSE) bloat_t;

I measured the size at each stage with the following query.

SELECT pg_size_pretty(pg_relation_size('bloat_t')) AS table_size, pg_size_pretty(pg_indexes_size('bloat_t')) AS index_size, pg_size_pretty(pg_total_relation_size('bloat_t')) AS total_size;
Stage Table Indexes Total
Right after creation (1 million rows) 112 MB 120 MB 231 MB
After DELETE of 900,000 rows and VACUUM 112 MB 120 MB 231 MB
After REPACK (CONCURRENTLY) 12 MB 12 MB 24 MB

Running While Writes Continue

On a table where 1 million of 2 million rows had been deleted and VACUUM had been run, I ran REPACK (CONCURRENTLY) while INSERTs continued in another session.

SQL for preparing the table
CREATE TABLE bloat_t2 (id serial PRIMARY KEY, payload text, k int, ins_at timestamptz DEFAULT clock_timestamp()) WITH (autovacuum_enabled = false);
INSERT INTO bloat_t2 (payload, k) SELECT md5(g::text) || md5((g+1)::text), g % 1000 FROM generate_series(1, 2000000) g;
CREATE INDEX bloat_t2_k_idx ON bloat_t2 (k);
CREATE INDEX bloat_t2_payload_idx ON bloat_t2 (payload);
ANALYZE bloat_t2;
DELETE FROM bloat_t2 WHERE id % 2 = 0;
VACUUM bloat_t2;
SELECT pg_size_pretty(pg_total_relation_size('bloat_t2')) AS total_size_before;

In the writing session, I ran the following DO block. It repeats 4000 times a process that INSERTs one row, COMMITs, and waits 10 ms.

DO $$ BEGIN FOR i IN 1..4000 LOOP INSERT INTO bloat_t2 (payload, k) VALUES ('w', -1); COMMIT; PERFORM pg_sleep(0.01); END LOOP; END $$;

Three seconds after starting the DO block, I ran REPACK in another session.

REPACK (CONCURRENTLY, VERBOSE) bloat_t2;

The INSERT interval was calculated from the difference between each row's ins_at (insertion time) and the ins_at of the previous row. All values in the table are the results of a single run.

Item Value
REPACK duration (difference of clock_timestamp() taken before and after the REPACK statement) 8.85 seconds
Total size (before REPACK) 462 MB
Total size (after REPACK) 232 MB
Total number of writes 4000 (all reflected)
Number of INSERTs during REPACK 439
Maximum INSERT interval during REPACK 0.747 seconds
Median INSERT interval over the whole period 0.0109 seconds
Invalid indexes 0

Logical Replication of Sequences

Using two databases within the same instance, I made pubdb the publisher and subdb the subscriber.

Creating the Subscription and Initial Synchronization

I first created a slot with pg_create_logical_replication_slot, and then subscribed to the database within the same instance by specifying create_slot = false and slot_name for the subscription.

The steps for creating the roles and databases and preparing the publisher (pubdb) were as follows. A publication that targets sequences is created with FOR ALL SEQUENCES.

CREATE ROLE repl LOGIN PASSWORD '<パスワード>';
CREATE ROLE
GRANT rds_replication TO repl;
GRANT ROLE
CREATE DATABASE pubdb;
CREATE DATABASE
CREATE DATABASE subdb;
CREATE DATABASE
\c pubdb
CREATE SEQUENCE orders_seq;
CREATE SEQUENCE
SELECT nextval('orders_seq') FROM generate_series(1, 100) \g /dev/null
GRANT SELECT, USAGE ON SEQUENCE orders_seq TO repl;
GRANT
SELECT * FROM pg_get_sequence_data('orders_seq');
 last_value | is_called |  page_lsn  
------------+-----------+------------
        100 | t         | 0/05D54488
(1 row)

CREATE PUBLICATION pub_seq FOR ALL SEQUENCES;
CREATE PUBLICATION
SELECT slot_name FROM pg_create_logical_replication_slot('sub_seq_slot', 'pgoutput');
  slot_name   
--------------
 sub_seq_slot
(1 row)

On the subscriber (subdb), I prepared a sequence with the same name as on the publisher and then created the subscription.

\c subdb
CREATE SEQUENCE orders_seq;
CREATE SEQUENCE
SELECT * FROM pg_get_sequence_data('orders_seq');
 last_value | is_called |  page_lsn  
------------+-----------+------------
          1 | f         | 0/05D55DE8
(1 row)

CREATE SUBSCRIPTION sub_seq
  CONNECTION 'host=<DB エンドポイント> port=5432 dbname=pubdb user=repl password=<パスワード>'
  PUBLICATION pub_seq
  WITH (create_slot = false, slot_name = 'sub_seq_slot');
CREATE SUBSCRIPTION
SELECT pg_sleep(10);
SELECT srrelid::regclass, srsubstate FROM pg_subscription_rel;
  srrelid   | srsubstate 
------------+------------
 orders_seq | r
(1 row)

SELECT * FROM pg_get_sequence_data('orders_seq');
 last_value | is_called |  page_lsn  
------------+-----------+------------
        100 | t         | 0/05D569F8
(1 row)

When I checked 10 seconds after creating the subscription, orders_seq on the subscriber had the same value as on the publisher.

Applying Changes with REFRESH SEQUENCES

After calling nextval another 100 times on the publisher, I ran ALTER SUBSCRIPTION ... REFRESH SEQUENCES on the subscriber, and 10 seconds later the value on the subscriber also became 200.

\c pubdb
SELECT nextval('orders_seq') FROM generate_series(1, 100) \g /dev/null
SELECT * FROM pg_get_sequence_data('orders_seq');
 last_value | is_called |  page_lsn  
------------+-----------+------------
        200 | t         | 0/05D56C80
(1 row)

\c subdb
ALTER SUBSCRIPTION sub_seq REFRESH SEQUENCES;
ALTER SUBSCRIPTION
SELECT pg_sleep(10);
SELECT * FROM pg_get_sequence_data('orders_seq');
 last_value | is_called |  page_lsn  
------------+-----------+------------
        200 | t         | 0/05D56E90
(1 row)

pg_plan_advice

Obtaining the Advice String

On a DB instance where pg_plan_advice is registered in shared_preload_libraries, you can use the PLAN_ADVICE option of EXPLAIN. CREATE EXTENSION is not needed, and it does not appear in pg_available_extensions either.

SQL for preparing the tables
CREATE TABLE join_dim (id int PRIMARY KEY, name text);
CREATE TABLE join_fact (id serial PRIMARY KEY, dim_id int NOT NULL, val int);
INSERT INTO join_dim SELECT g, 'dim' || g FROM generate_series(1, 1000) g;
INSERT INTO join_fact (dim_id, val) SELECT (g % 1000) + 1, g FROM generate_series(1, 100000) g;
CREATE INDEX ON join_fact (dim_id);
ANALYZE join_dim; ANALYZE join_fact;

When you specify PLAN_ADVICE in EXPLAIN, the advice string is output after the plan.

EXPLAIN (COSTS OFF, PLAN_ADVICE)
SELECT * FROM join_fact f JOIN join_dim d ON f.dim_id = d.id WHERE d.id < 5;
                      QUERY PLAN                       
-------------------------------------------------------
 Nested Loop
   ->  Index Scan using join_dim_pkey on join_dim d
         Index Cond: (id < 5)
   ->  Bitmap Heap Scan on join_fact f
         Recheck Cond: (dim_id = d.id)
         ->  Bitmap Index Scan on join_fact_dim_id_idx
               Index Cond: (dim_id = d.id)
 Generated Plan Advice:
   JOIN_ORDER(d f)
   NESTED_LOOP_PLAIN(f)
   BITMAP_HEAP_SCAN(f)
   INDEX_SCAN(d public.join_dim_pkey)
   NO_GATHER(f d)
(13 rows)

Specifying the Plan with Advice

When you set an advice string in pg_plan_advice.advice, it is reflected in the plan. I specified the join order, join method, and scan method to change the scan of join_fact.

SET pg_plan_advice.advice = 'JOIN_ORDER(d f) NESTED_LOOP_PLAIN(f) INDEX_SCAN(f join_fact_dim_id_idx)';
SET
EXPLAIN (COSTS OFF)
SELECT * FROM join_fact f JOIN join_dim d ON f.dim_id = d.id WHERE d.id < 5;
                         QUERY PLAN                         
------------------------------------------------------------
 Nested Loop
   ->  Index Scan using join_dim_pkey on join_dim d
         Index Cond: (id < 5)
   ->  Index Scan using join_fact_dim_id_idx on join_fact f
         Index Cond: (dim_id = d.id)
 Supplied Plan Advice:
   INDEX_SCAN(f join_fact_dim_id_idx) /* matched */
   JOIN_ORDER(d f) /* matched */
   NESTED_LOOP_PLAIN(f) /* matched */
(9 rows)

The scan of join_fact changed from Bitmap Heap Scan to Index Scan. When I removed the setting with RESET pg_plan_advice.advice;, the plan returned to the same Bitmap Heap Scan plan as in the previous section.

pg_stash_advice

Registering Advice

pg_stash_advice saves advice strings in a storage location called a stash, associated with a query ID. CREATE EXTENSION makes the functions that manage stashes available. It could be run by the master user (a member of rds_superuser).

CREATE EXTENSION pg_stash_advice;

The query ID of the query to associate advice with is read from the Query Identifier in the output of EXPLAIN (VERBOSE). The target is the following query. At this point, pg_stash_advice.stash_name is empty, so no advice is applied.

EXPLAIN (VERBOSE, COSTS OFF)
SELECT f.val, d.name AS stash_target FROM join_fact f JOIN join_dim d ON f.dim_id = d.id WHERE d.id < 5 LIMIT 1;
                         QUERY PLAN                          
-------------------------------------------------------------
 Limit
   Output: f.val, d.name
   ->  Nested Loop
         Output: f.val, d.name
         ->  Seq Scan on public.join_dim d
               Output: d.id, d.name
               Filter: (d.id < 5)
         ->  Bitmap Heap Scan on public.join_fact f
               Output: f.id, f.dim_id, f.val
               Recheck Cond: (f.dim_id = d.id)
               ->  Bitmap Index Scan on join_fact_dim_id_idx
                     Index Cond: (f.dim_id = d.id)
 Query Identifier: 1104987876549015255
(13 rows)

Create a stash, and register the advice by specifying the query ID you read as the second argument.

SELECT pg_create_advice_stash('s1');
SELECT pg_set_stashed_advice('s1', 1104987876549015255, 'JOIN_ORDER(f d) HASH_JOIN(d) SEQ_SCAN(f d)');

You can check the registered content with pg_get_advice_stash_contents.

SELECT * FROM pg_get_advice_stash_contents('s1');
 stash_name |      query_id       |               advice_string                
------------+---------------------+--------------------------------------------
 s1         | 1104987876549015255 | JOIN_ORDER(f d) HASH_JOIN(d) SEQ_SCAN(f d)
(1 row)

Automatic Application of Advice

When you set the stash name in pg_stash_advice.stash_name in a session, the registered advice is applied to the execution plan of queries whose query ID matches. Without rewriting the query, just by changing a setting, the plan changed to Hash Join and Seq Scan.

SET pg_stash_advice.stash_name = 's1';
SET
EXPLAIN (COSTS OFF)
SELECT f.val, d.name AS stash_target FROM join_fact f JOIN join_dim d ON f.dim_id = d.id WHERE d.id < 5 LIMIT 1;
                QUERY PLAN                
------------------------------------------
 Limit
   ->  Hash Join
         Hash Cond: (f.dim_id = d.id)
         ->  Seq Scan on join_fact f
         ->  Hash
               ->  Seq Scan on join_dim d
                     Filter: (id < 5)
 Supplied Plan Advice:
   SEQ_SCAN(f) /* matched */
   SEQ_SCAN(d) /* matched */
   JOIN_ORDER(f d) /* matched */
   HASH_JOIN(d) /* matched */
(12 rows)

Summary

On RDS in the Preview environment, I was able to verify new features of PostgreSQL 19.0, such as shrinking tables and indexes with REPACK (CONCURRENTLY), which runs while writes continue.

If you want to evaluate the new features of PostgreSQL 19 on RDS, you can use the Preview environment in Ohio (us-east-2).

However, DB instances in the Preview environment are retained for at most 60 days, and after the retention period they are automatically deleted, including backups and snapshots. Snapshots created in the Preview environment cannot be copied to the production environment, so please use it as an evaluation-only environment.

Share this article

AWSのお困り事はクラスメソッドへ