@ -30,6 +30,7 @@ sub create_sub_pub_w_errors
qq[
BEGIN ;
CREATE TABLE $ table_name ( a int ) ;
ALTER TABLE $ table_name REPLICA IDENTITY FULL ;
INSERT INTO $ table_name VALUES ( 1 ) ;
COMMIT ;
] ) ;
@ -91,20 +92,36 @@ sub create_sub_pub_w_errors
# subscriber due to violation of the unique constraint on test table.
$ node_publisher - > safe_psql ( $ db , qq( INSERT INTO $table_name VALUES ( 1 ) ) ) ;
# Wait for the apply error to be reported.
# Wait for the subscriber to report both an apply error and an
# insert_exists conflict.
$ node_subscriber - > poll_query_until (
$ db ,
qq[
SELECT apply_error_count > 0
SELECT apply_error_count > 0 AND confl_insert_exists > 0
FROM pg_stat_subscription_stats
WHERE subname = '$sub_name'
] )
or die
qq( Timed out while waiting for apply error for subscription '$sub_name' ) ;
qq( Timed out while waiting for apply error and insert_exists conflict for subscription '$sub_name' ) ;
# Truncate test table so that apply worker can continue.
$ node_subscriber - > safe_psql ( $ db , qq( TRUNCATE $table_name ) ) ;
# Delete data from the test table on the publisher. This delete operation
# should be skipped on the subscriber since the table is already empty.
$ node_publisher - > safe_psql ( $ db , qq( DELETE FROM $table_name; ) ) ;
# Wait for the subscriber to report a delete_missing conflict.
$ node_subscriber - > poll_query_until (
$ db ,
qq[
SELECT confl_delete_missing > 0
FROM pg_stat_subscription_stats
WHERE subname = '$sub_name'
] )
or die
qq( Timed out while waiting for delete_missing conflict for subscription '$sub_name' ) ;
return ( $ pub_name , $ sub_name ) ;
}
@ -123,17 +140,19 @@ my ($pub1_name, $sub1_name) =
create_sub_pub_w_errors ( $ node_publisher , $ node_subscriber , $ db ,
$ table1_name ) ;
# Apply and Sync errors are > 0 and reset timestamp is NULL
# Apply errors, sync errors, and conflicts are > 0 and stats_ reset timestamp is NULL
is ( $ node_subscriber - > safe_psql (
$ db ,
qq( SELECT apply_error_count > 0,
sync_error_count > 0 ,
confl_insert_exists > 0 ,
confl_delete_missing > 0 ,
stats_reset IS NULL
FROM pg_stat_subscription_stats
WHERE subname = '$sub1_name' )
) ,
qq( t|t|t ) ,
qq( Check that apply errors and sync errors are both > 0 and stats_reset is NULL for subscription '$sub1_name'. )
qq( t|t|t|t|t ) ,
qq( Check that apply errors, sync errors, and conflicts are > 0 and stats_reset is NULL for subscription '$sub1_name'. )
) ;
# Reset a single subscription
@ -141,17 +160,19 @@ $node_subscriber->safe_psql($db,
qq( SELECT pg_stat_reset_subscription_stats ( ( SELECT subid FROM pg_stat_subscription_stats WHERE subname = '$sub1_name' ) ) )
) ;
# Apply and Sync errors are 0 and stats reset is not NULL
# Apply errors, sync errors, and conflicts are 0 and stats_reset timestamp is not NULL
is ( $ node_subscriber - > safe_psql (
$ db ,
qq( SELECT apply_error_count = 0,
sync_error_count = 0 ,
confl_insert_exists = 0 ,
confl_delete_missing = 0 ,
stats_reset IS NOT NULL
FROM pg_stat_subscription_stats
WHERE subname = '$sub1_name' )
) ,
qq( t|t|t ) ,
qq( Confirm that apply errors and sync errors are both 0 and stats_reset is not NULL after reset for subscription '$sub1_name'. )
qq( t|t|t|t|t ) ,
qq( Confirm that apply errors, sync errors, and conflicts are 0 and stats_reset is not NULL after reset for subscription '$sub1_name'. )
) ;
# Get reset timestamp
@ -181,46 +202,52 @@ my ($pub2_name, $sub2_name) =
create_sub_pub_w_errors ( $ node_publisher , $ node_subscriber , $ db ,
$ table2_name ) ;
# Apply and Sync errors are > 0 and reset timestamp is NULL
# Apply errors, sync errors, and conflicts are > 0 and stats_ reset timestamp is NULL
is ( $ node_subscriber - > safe_psql (
$ db ,
qq( SELECT apply_error_count > 0,
sync_error_count > 0 ,
confl_insert_exists > 0 ,
confl_delete_missing > 0 ,
stats_reset IS NULL
FROM pg_stat_subscription_stats
WHERE subname = '$sub2_name' )
) ,
qq( t|t|t ) ,
qq( Confirm that apply errors and sync errors are both > 0 and stats_reset is NULL for sub '$sub2_name'. )
qq( t|t|t|t|t ) ,
qq( Confirm that apply errors, sync errors, and conflicts are > 0 and stats_reset is NULL for sub '$sub2_name'. )
) ;
# Reset all subscriptions
$ node_subscriber - > safe_psql ( $ db ,
qq( SELECT pg_stat_reset_subscription_stats ( NULL ) ) ) ;
# Apply and Sync errors are 0 and stats reset is not NULL
# Apply errors, sync errors, and conflicts are 0 and stats_reset timestamp is not NULL
is ( $ node_subscriber - > safe_psql (
$ db ,
qq( SELECT apply_error_count = 0,
sync_error_count = 0 ,
confl_insert_exists = 0 ,
confl_delete_missing = 0 ,
stats_reset IS NOT NULL
FROM pg_stat_subscription_stats
WHERE subname = '$sub1_name' )
) ,
qq( t|t|t ) ,
qq( Confirm that apply errors and sync errors are both 0 and stats_reset is not NULL for sub '$sub1_name' after reset. )
qq( t|t|t|t|t ) ,
qq( Confirm that apply errors, sync errors, and conflicts are 0 and stats_reset is not NULL for sub '$sub1_name' after reset. )
) ;
is ( $ node_subscriber - > safe_psql (
$ db ,
qq( SELECT apply_error_count = 0,
sync_error_count = 0 ,
confl_insert_exists = 0 ,
confl_delete_missing = 0 ,
stats_reset IS NOT NULL
FROM pg_stat_subscription_stats
WHERE subname = '$sub2_name' )
) ,
qq( t|t|t ) ,
qq( Confirm that apply errors and sync errors are both 0 and stats_reset is not NULL for sub '$sub2_name' after reset. )
qq( t|t|t|t|t ) ,
qq( Confirm that apply errors, sync errors, and conflicts are 0 and stats_reset is not NULL for sub '$sub2_name' after reset. )
) ;
$ reset_time1 = $ node_subscriber - > safe_psql ( $ db ,