aboutsummaryrefslogtreecommitdiff
path: root/contrib/pg_stat_statements
diff options
context:
space:
mode:
authorPeter Eisentraut <peter@eisentraut.org>2023-12-30 19:55:32 +0100
committerPeter Eisentraut <peter@eisentraut.org>2023-12-30 20:18:23 +0100
commit4710b67d4d35832223dc49ccc2ccc043dff53793 (patch)
treea9eceff581c9adc1ba660947cd944b42f62fa18f /contrib/pg_stat_statements
parent742f6b3e6df980d7dafa4a18a165d285483d5f0e (diff)
downloadpostgresql-4710b67d4d35832223dc49ccc2ccc043dff53793.tar.gz
postgresql-4710b67d4d35832223dc49ccc2ccc043dff53793.zip
pg_stat_statements: Add TAP test for testing restarts
This tests that pg_stat_statement contents are successfully kept across restart. (This similar to src/test/recovery/t/029_stats_restart.pl for the stats collector.) Reviewed-by: Michael Paquier <michael@paquier.xyz> Reviewed-by: Julien Rouhaud <rjuju123@gmail.com> Discussion: https://www.postgresql.org/message-id/flat/40d1e4f2-835f-448f-a541-8ff5db75bf3d@eisentraut.org
Diffstat (limited to 'contrib/pg_stat_statements')
-rw-r--r--contrib/pg_stat_statements/Makefile2
-rw-r--r--contrib/pg_stat_statements/meson.build5
-rw-r--r--contrib/pg_stat_statements/t/010_restart.pl53
3 files changed, 60 insertions, 0 deletions
diff --git a/contrib/pg_stat_statements/Makefile b/contrib/pg_stat_statements/Makefile
index 7ee16e83509..20834bb0ee4 100644
--- a/contrib/pg_stat_statements/Makefile
+++ b/contrib/pg_stat_statements/Makefile
@@ -24,6 +24,8 @@ REGRESS = select dml cursors utility level_tracking planning \
# which typical installcheck users do not have (e.g. buildfarm clients).
NO_INSTALLCHECK = 1
+TAP_TESTS = 1
+
ifdef USE_PGXS
PG_CONFIG = pg_config
PGXS := $(shell $(PG_CONFIG) --pgxs)
diff --git a/contrib/pg_stat_statements/meson.build b/contrib/pg_stat_statements/meson.build
index a66acaa5b88..3e42328f6c5 100644
--- a/contrib/pg_stat_statements/meson.build
+++ b/contrib/pg_stat_statements/meson.build
@@ -60,4 +60,9 @@ tests += {
# runningcheck users do not have (e.g. buildfarm clients).
'runningcheck': false,
},
+ 'tap': {
+ 'tests': [
+ 't/010_restart.pl',
+ ],
+ },
}
diff --git a/contrib/pg_stat_statements/t/010_restart.pl b/contrib/pg_stat_statements/t/010_restart.pl
new file mode 100644
index 00000000000..83a2bf0db82
--- /dev/null
+++ b/contrib/pg_stat_statements/t/010_restart.pl
@@ -0,0 +1,53 @@
+# Copyright (c) 2023, PostgreSQL Global Development Group
+
+# Tests for checking that pg_stat_statements contents are preserved
+# across restarts.
+
+use strict;
+use warnings;
+use PostgreSQL::Test::Cluster;
+use PostgreSQL::Test::Utils;
+use Test::More;
+
+my $node = PostgreSQL::Test::Cluster->new('main');
+$node->init;
+$node->append_conf('postgresql.conf',
+ "shared_preload_libraries = 'pg_stat_statements'");
+$node->start;
+
+$node->safe_psql('postgres', 'CREATE EXTENSION pg_stat_statements');
+
+$node->safe_psql('postgres', 'CREATE TABLE t1 (a int)');
+$node->safe_psql('postgres', 'SELECT a FROM t1');
+
+is( $node->safe_psql(
+ 'postgres',
+ "SELECT query FROM pg_stat_statements WHERE query NOT LIKE '%pg_stat_statements%' ORDER BY query"
+ ),
+ "CREATE TABLE t1 (a int)\nSELECT a FROM t1",
+ 'pg_stat_statements populated');
+
+$node->restart;
+
+is( $node->safe_psql(
+ 'postgres',
+ "SELECT query FROM pg_stat_statements WHERE query NOT LIKE '%pg_stat_statements%' ORDER BY query"
+ ),
+ "CREATE TABLE t1 (a int)\nSELECT a FROM t1",
+ 'pg_stat_statements data kept across restart');
+
+$node->append_conf('postgresql.conf', "pg_stat_statements.save = false");
+$node->reload;
+
+$node->restart;
+
+is( $node->safe_psql(
+ 'postgres',
+ "SELECT count(*) FROM pg_stat_statements WHERE query NOT LIKE '%pg_stat_statements%'"
+ ),
+ '0',
+ 'pg_stat_statements data not kept across restart with .save=false');
+
+$node->stop;
+
+done_testing();