From bb4d6db02d79828cc7665690a9272b71970ead65 Mon Sep 17 00:00:00 2001 From: Vishal Prasanna Date: Wed, 25 Feb 2026 15:17:25 +0530 Subject: [PATCH 1/2] Test specinsert cleanup in ReorderBufferProcessTXN error path --- src/test/subscription/t/100_bugs.pl | 41 +++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/test/subscription/t/100_bugs.pl b/src/test/subscription/t/100_bugs.pl index 50223054918..4344eb581da 100644 --- a/src/test/subscription/t/100_bugs.pl +++ b/src/test/subscription/t/100_bugs.pl @@ -605,4 +605,45 @@ $node_publisher->safe_psql('postgres', "DROP DATABASE regress_db"); $node_publisher->stop('fast'); +# Ensure logical decoder doesn't crash if error occurs +# while processing an INSERT ... ON CONFLICT statement. +$node_publisher = PostgreSQL::Test::Cluster->new('logical_decoder'); +$node_publisher->init(allows_streaming => 'logical'); +$node_publisher->start; + +# The publication row filter WHERE ((a / 0) > 0) will trigger a division by zero error. +$node_publisher->safe_psql( + 'postgres', qq( + CREATE TABLE tab_upsert (a INT PRIMARY KEY, b INT); + CREATE PUBLICATION pub_rowfilter_error FOR TABLE tab_upsert WHERE ((a / 0) > 0); + SELECT * FROM pg_create_logical_replication_slot('upsert_slot', 'pgoutput'); + INSERT INTO tab_upsert (a, b) VALUES (1, 1) + ON CONFLICT(a) DO UPDATE SET b = excluded.b; +)); + +# Decode the changes with a publication whose row filter causes a +# division by zero error, and verify that the logical decoder doesn't crash. +($ret, $stdout, $stderr) = $node_publisher->psql( + 'postgres', qq( + SELECT * + FROM pg_logical_slot_peek_binary_changes( + 'upsert_slot', + NULL, + NULL, + 'proto_version', '1', + 'publication_names', 'pub_rowfilter_error' + ); +)); + +ok( $stderr =~ qr/division by zero/, + 'peek logical changes with row filter causing division by zero throws error' +); + +# Clean up +$node_publisher->safe_psql('postgres', "SELECT pg_drop_replication_slot('upsert_slot')"); +$node_publisher->safe_psql('postgres', "DROP PUBLICATION pub_rowfilter_error"); +$node_publisher->safe_psql('postgres', "DROP TABLE tab_upsert"); + +$node_publisher->stop('fast'); + done_testing(); -- 2.50.1 (Apple Git-155)