| 1 |
# Copyright (c) 2023-2025, PostgreSQL Global Development Group |
| 2 |
|
| 3 |
# Tests for checking that pg_stat_statements contents are preserved |
| 4 |
# across restarts. |
| 5 |
|
| 6 |
use strict; |
| 7 |
use warnings FATAL => 'all'; |
| 8 |
use PostgreSQL::Test::Cluster; |
| 9 |
use PostgreSQL::Test::Utils; |
| 10 |
use Test::More; |
| 11 |
|
| 12 |
my $node = PostgreSQL::Test::Cluster->new('main'); |
| 13 |
$node->init; |
| 14 |
$node->append_conf('postgresql.conf', |
| 15 |
"shared_preload_libraries = 'pg_stat_statements'"); |
| 16 |
$node->start; |
| 17 |
|
| 18 |
$node->safe_psql('postgres', 'CREATE EXTENSION pg_stat_statements'); |
| 19 |
|
| 20 |
$node->safe_psql('postgres', 'CREATE TABLE t1 (a int)'); |
| 21 |
$node->safe_psql('postgres', 'SELECT a FROM t1'); |
| 22 |
|
| 23 |
is( $node->safe_psql( |
| 24 |
'postgres', |
| 25 |
"SELECT query FROM pg_stat_statements WHERE query NOT LIKE '%pg_stat_statements%' ORDER BY query" |
| 26 |
), |
| 27 |
"CREATE TABLE t1 (a int)\nSELECT a FROM t1", |
| 28 |
'pg_stat_statements populated'); |
| 29 |
|
| 30 |
$node->restart; |
| 31 |
|
| 32 |
is( $node->safe_psql( |
| 33 |
'postgres', |
| 34 |
"SELECT query FROM pg_stat_statements WHERE query NOT LIKE '%pg_stat_statements%' ORDER BY query" |
| 35 |
), |
| 36 |
"CREATE TABLE t1 (a int)\nSELECT a FROM t1", |
| 37 |
'pg_stat_statements data kept across restart'); |
| 38 |
|
| 39 |
$node->append_conf('postgresql.conf', "pg_stat_statements.save = false"); |
| 40 |
$node->reload; |
| 41 |
|
| 42 |
$node->restart; |
| 43 |
|
| 44 |
is( $node->safe_psql( |
| 45 |
'postgres', |
| 46 |
"SELECT count(*) FROM pg_stat_statements WHERE query NOT LIKE '%pg_stat_statements%'" |
| 47 |
), |
| 48 |
'0', |
| 49 |
'pg_stat_statements data not kept across restart with .save=false'); |
| 50 |
|
| 51 |
$node->stop; |
| 52 |
|
| 53 |
done_testing(); |