diff --git a/t/0001_settings_pgsm_track_planning.pl b/t/0001_settings_pgsm_track_planning.pl index f236588..b802c80 100644 --- a/t/0001_settings_pgsm_track_planning.pl +++ b/t/0001_settings_pgsm_track_planning.pl @@ -3,11 +3,17 @@ use String::Util qw(trim); use File::Basename; use File::Compare; +use String::Util qw(trim); use Test::More; use lib 't'; use pgsm; +# PG's major server version +open my $FH_PG_VERSION, '<', "${pgdata}/PG_VERSION"; +my $major_version = trim(<$FH_PG_VERSION>); +close $FH_PG_VERSION; + sub check_value { my ($var, $postive, $expected, $val) = @_; @@ -58,8 +64,15 @@ sub do_regression } ($cmdret, $stdout, $stderr) = pgsm_init_pg; -do_regression(1, 0, "pg_stat_monitor.pgsm_track_planning = 'no'"); -do_regression(0, 0, "pg_stat_monitor.pgsm_track_planning = 'yes'"); + +SKIP: + { + skip "Server version is 12 or less", 1 + if ($major_version <= 12); + + do_regression(1, 0, "pg_stat_monitor.pgsm_track_planning = 'no'"); + do_regression(0, 0, "pg_stat_monitor.pgsm_track_planning = 'yes'"); + } ($cmdret, $stdout, $stderr) = done_testing(); diff --git a/t/001_settings_default.pl b/t/001_settings_default.pl index 7497ed5..ccb7b2a 100644 --- a/t/001_settings_default.pl +++ b/t/001_settings_default.pl @@ -4,7 +4,9 @@ use strict; use warnings; use File::Basename; use File::Compare; +use File::Copy; use PostgresNode; +use String::Util qw(trim); use Test::More; # Expected folder where expected output will be present @@ -25,6 +27,17 @@ unless (-d $expected_folder) BAIL_OUT "Expected files folder $expected_folder doesn't exist: \n";; } +# Create new PostgreSQL node and do initdb +my $node = PostgresNode->get_new_node('test'); +my $pgdata = $node->data_dir; +$node->dump_info; +$node->init; + +# PG's major server version +open my $FH_PG_VERSION, '<', "${pgdata}/PG_VERSION"; +my $major_version = trim(<$FH_PG_VERSION>); +close $FH_PG_VERSION; + # Get filename of the this perl file my $perlfilename = basename($0); @@ -38,6 +51,12 @@ my $filename_without_extension = $perlfilename; # Create expected filename with path my $expected_filename = "${filename_without_extension}.out"; + +if ($major_version <= 12) +{ + $expected_filename = "${expected_filename}.${major_version}"; +} + my $expected_filename_with_path = "${expected_folder}/${expected_filename}" ; # Create results filename with path @@ -50,12 +69,6 @@ if ( -f $out_filename_with_path) unlink($out_filename_with_path) or die "Can't delete already existing $out_filename_with_path: $!\n"; } -# Create new PostgreSQL node and do initdb -my $node = PostgresNode->get_new_node('test'); -my $pgdata = $node->data_dir; -$node->dump_info; -$node->init; - # Update postgresql.conf to include/load pg_stat_monitor library open my $conf, '>>', "$pgdata/postgresql.conf"; print $conf "shared_preload_libraries = 'pg_stat_monitor'\n"; diff --git a/t/002_settings_pgsm_track_planning.pl b/t/002_settings_pgsm_track_planning.pl index c660709..51be0d9 100644 --- a/t/002_settings_pgsm_track_planning.pl +++ b/t/002_settings_pgsm_track_planning.pl @@ -6,6 +6,7 @@ use String::Util qw(trim); use File::Basename; use File::Compare; use PostgresNode; +use String::Util qw(trim); use Test::More; # Expected folder where expected output will be present @@ -54,6 +55,11 @@ my $pgdata = $node->data_dir; $node->dump_info; $node->init; +# PG's major server version +open my $FH_PG_VERSION, '<', "${pgdata}/PG_VERSION"; +my $major_version = trim(<$FH_PG_VERSION>); +close $FH_PG_VERSION; + # Update postgresql.conf to include/load pg_stat_monitor library open my $conf, '>>', "$pgdata/postgresql.conf"; print $conf "shared_preload_libraries = 'pg_stat_monitor'\n"; @@ -84,39 +90,45 @@ TestLib::append_to_file($out_filename_with_path, $stdout . "\n"); ok($cmdret == 0, "Print PGSM Extension Settings"); TestLib::append_to_file($out_filename_with_path, $stdout . "\n"); -($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT query, calls, total_plan_time, min_plan_time, max_plan_time, mean_plan_time, stddev_plan_time from pg_stat_monitor;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']); -ok($cmdret == 0, "Select from PGSM view"); -TestLib::append_to_file($out_filename_with_path, $stdout . "\n"); +SKIP: + { + skip "Server version is 12 or less", 1 + if ($major_version <= 12); -# Test: total_plan_time is not 0 -($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (total_plan_time = 0) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']); -trim($stdout); -is($stdout,'f',"Compare: total_plan_time is not 0)."); + ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT query, calls, total_plan_time, min_plan_time, max_plan_time, mean_plan_time, stddev_plan_time from pg_stat_monitor;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']); + ok($cmdret == 0, "Select from PGSM view"); + TestLib::append_to_file($out_filename_with_path, $stdout . "\n"); -# Test: min_plan_time is not 0 -($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (min_plan_time = 0) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']); -trim($stdout); -is($stdout,'f',"Compare: min_plan_time is not 0)."); + # Test: total_plan_time is not 0 + ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (total_plan_time = 0) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']); + trim($stdout); + is($stdout,'f',"Compare: total_plan_time is not 0)."); -# Test: max_plan_time is not 0 -($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (max_plan_time = 0) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']); -trim($stdout); -is($stdout,'f',"Compare: max_plan_time is not 0)."); + # Test: min_plan_time is not 0 + ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (min_plan_time = 0) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']); + trim($stdout); + is($stdout,'f',"Compare: min_plan_time is not 0)."); -# Test: mean_plan_time is not 0 -($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (mean_plan_time = 0) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']); -trim($stdout); -is($stdout,'f',"Compare: mean_plan_time is not 0)."); + # Test: max_plan_time is not 0 + ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (max_plan_time = 0) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']); + trim($stdout); + is($stdout,'f',"Compare: max_plan_time is not 0)."); -# Test: stddev_plan_time is not 0 -#($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (stddev_plan_time = 0) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']); -#trim($stdout); -#is($stdout,'f',"Compare: stddev_plan_time is not 0)."); + # Test: mean_plan_time is not 0 + ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (mean_plan_time = 0) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']); + trim($stdout); + is($stdout,'f',"Compare: mean_plan_time is not 0)."); -# Test: total_plan_time = min_plan_time + max_plan_time -($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (round(total_plan_time::numeric,3) = round(min_plan_time::numeric + max_plan_time::numeric,3)) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']); -trim($stdout); -is($stdout,'t',"Compare: (round(total_plan_time::numeric,3) = round(min_plan_time::numeric + max_plan_time::numeric,3))."); + # Test: stddev_plan_time is not 0 + #($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (stddev_plan_time = 0) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']); + #trim($stdout); + #is($stdout,'f',"Compare: stddev_plan_time is not 0)."); + + # Test: total_plan_time = min_plan_time + max_plan_time + ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (round(total_plan_time::numeric,3) = round(min_plan_time::numeric + max_plan_time::numeric,3)) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']); + trim($stdout); + is($stdout,'t',"Compare: (round(total_plan_time::numeric,3) = round(min_plan_time::numeric + max_plan_time::numeric,3))."); + } # Test: mean_plan_time = total_plan_time/2 #($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (round(mean_plan_time::numeric,3) = round((total_plan_time/2)::numeric,3)) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']); @@ -150,34 +162,40 @@ TestLib::append_to_file($out_filename_with_path, $stdout . "\n"); ok($cmdret == 0, "Print PGSM Extension Settings"); TestLib::append_to_file($out_filename_with_path, $stdout . "\n"); -($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT query, calls, total_plan_time, min_plan_time, max_plan_time, mean_plan_time, stddev_plan_time from pg_stat_monitor;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']); -ok($cmdret == 0, "Select from PGSM view"); -TestLib::append_to_file($out_filename_with_path, $stdout . "\n"); +SKIP: + { + skip "Server version is 12 or less", 1 + if ($major_version <= 12); -# Test: total_plan_time is 0 -($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (total_plan_time = 0) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']); -trim($stdout); -is($stdout,'t',"Compare: total_plan_time is 0)."); + ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT query, calls, total_plan_time, min_plan_time, max_plan_time, mean_plan_time, stddev_plan_time from pg_stat_monitor;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']); + ok($cmdret == 0, "Select from PGSM view"); + TestLib::append_to_file($out_filename_with_path, $stdout . "\n"); -# Test: min_plan_time is 0 -($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (min_plan_time = 0) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']); -trim($stdout); -is($stdout,'t',"Compare: min_plan_time is 0)."); + # Test: total_plan_time is 0 + ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (total_plan_time = 0) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']); + trim($stdout); + is($stdout,'t',"Compare: total_plan_time is 0)."); -# Test: max_plan_time is 0 -($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (max_plan_time = 0) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']); -trim($stdout); -is($stdout,'t',"Compare: max_plan_time is 0)."); + # Test: min_plan_time is 0 + ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (min_plan_time = 0) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']); + trim($stdout); + is($stdout,'t',"Compare: min_plan_time is 0)."); -# Test: mean_plan_time is 0 -($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (mean_plan_time = 0) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']); -trim($stdout); -is($stdout,'t',"Compare: mean_plan_time is 0)."); + # Test: max_plan_time is 0 + ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (max_plan_time = 0) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']); + trim($stdout); + is($stdout,'t',"Compare: max_plan_time is 0)."); -# Test: stddev_plan_time is 0 -($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (stddev_plan_time = 0) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']); -trim($stdout); -is($stdout,'t',"Compare: stddev_plan_time is 0)."); + # Test: mean_plan_time is 0 + ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (mean_plan_time = 0) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']); + trim($stdout); + is($stdout,'t',"Compare: mean_plan_time is 0)."); + + # Test: stddev_plan_time is 0 + ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (stddev_plan_time = 0) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']); + trim($stdout); + is($stdout,'t',"Compare: stddev_plan_time is 0)."); + } # Dump output to out file ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select substr(query, 0,100) as query, calls, total_plan_time, min_plan_time,max_plan_time,mean_plan_time,stddev_plan_time from pg_stat_monitor order by query;', extra_params => ['-a','-Pformat=aligned','-Ptuples_only=off']); diff --git a/t/007_settings_pgsm_query_shared_buffer.pl b/t/007_settings_pgsm_query_shared_buffer.pl index d4b8858..1990a0d 100755 --- a/t/007_settings_pgsm_query_shared_buffer.pl +++ b/t/007_settings_pgsm_query_shared_buffer.pl @@ -51,7 +51,7 @@ my $node = PostgresNode->get_new_node('test'); my $pgdata = $node->data_dir; $node->dump_info; $node->init; - + # Update postgresql.conf to include/load pg_stat_monitor library open my $conf, '>>', "$pgdata/postgresql.conf"; print $conf "shared_preload_libraries = 'pg_stat_monitor'\n"; diff --git a/t/013_settings_pgsm_normalized_query.pl b/t/013_settings_pgsm_normalized_query.pl index e80115d..f1b2884 100644 --- a/t/013_settings_pgsm_normalized_query.pl +++ b/t/013_settings_pgsm_normalized_query.pl @@ -5,6 +5,7 @@ use warnings; use File::Basename; use File::Compare; use PostgresNode; +use String::Util qw(trim); use Test::More; # Expected folder where expected output will be present @@ -52,6 +53,11 @@ my $pgdata = $node->data_dir; $node->dump_info; $node->init; +# PG's major server version +open my $FH_PG_VERSION, '<', "${pgdata}/PG_VERSION"; +my $major_version = trim(<$FH_PG_VERSION>); +close $FH_PG_VERSION; + # Update postgresql.conf to include/load pg_stat_monitor library open my $conf, '>>', "$pgdata/postgresql.conf"; print $conf "shared_preload_libraries = 'pg_stat_monitor'\n"; diff --git a/t/017_execution_stats.pl b/t/017_execution_stats.pl index dd454e2..d6e4459 100644 --- a/t/017_execution_stats.pl +++ b/t/017_execution_stats.pl @@ -6,6 +6,7 @@ use String::Util qw(trim); use File::Basename; use File::Compare; use PostgresNode; +use String::Util qw(trim); use Test::More; # Expected folder where expected output will be present @@ -33,6 +34,17 @@ my $perlfilename = basename($0); $perlfilename =~ s/\.[^.]+$//; my $filename_without_extension = $perlfilename; +# Create new PostgreSQL node and do initdb +my $node = PostgresNode->get_new_node('test'); +my $pgdata = $node->data_dir; +$node->dump_info; +$node->init; + +# PG's major server version +open my $FH_PG_VERSION, '<', "${pgdata}/PG_VERSION"; +my $major_version = trim(<$FH_PG_VERSION>); +close $FH_PG_VERSION; + # Create expected filename with path my $expected_filename = "${filename_without_extension}.out"; my $expected_filename_with_path = "${expected_folder}/${expected_filename}" ; @@ -48,12 +60,6 @@ if ( -f $out_filename_with_path) unlink($out_filename_with_path) or die "Can't delete already existing $out_filename_with_path: $!\n"; } -# Create new PostgreSQL node and do initdb -my $node = PostgresNode->get_new_node('test'); -my $pgdata = $node->data_dir; -$node->dump_info; -$node->init; - # Update postgresql.conf to include/load pg_stat_monitor library open my $conf, '>>', "$pgdata/postgresql.conf"; print $conf "shared_preload_libraries = 'pg_stat_monitor'\n"; @@ -63,6 +69,21 @@ close $conf; my $rt_value = $node->start; ok($rt_value == 1, "Start Server"); +my $col_total_time = "total_exec_time"; +my $col_min_time = "min_exec_time"; +my $col_max_time = "max_exec_time"; +my $col_mean_time = "mean_exec_time"; +my $col_stddev_time = "stddev_exec_time"; + +if ($major_version <= 12) +{ + $col_total_time = "total_time"; + $col_min_time = "min_time"; + $col_max_time = "max_time"; + $col_mean_time = "mean_time"; + $col_stddev_time = "stddev_time"; +} + # Create extension and change out file permissions my ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE EXTENSION pg_stat_monitor;', extra_params => ['-a']); ok($cmdret == 0, "Create PGSM Extension"); @@ -84,52 +105,52 @@ TestLib::append_to_file($out_filename_with_path, $stdout . "\n"); ok($cmdret == 0, "Print PGSM Extension Settings"); TestLib::append_to_file($out_filename_with_path, $stdout . "\n"); -($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT query, calls, total_exec_time, min_exec_time, max_exec_time, mean_exec_time, stddev_exec_time from pg_stat_monitor;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']); +($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT query, calls, ${col_total_time}, ${col_min_time}, ${col_max_time}, ${col_mean_time}, ${col_stddev_time} from pg_stat_monitor;", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']); ok($cmdret == 0, "Select from PGSM view"); TestLib::append_to_file($out_filename_with_path, $stdout . "\n"); -# Test: total_exec_time is not 0 -($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (total_exec_time = 0) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']); +# Test: ${col_total_time} is not 0 +($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT (${col_total_time} = 0) from pg_stat_monitor where calls = 2 ;", extra_params => ['-Pformat=unaligned','-Ptuples_only=on']); trim($stdout); -is($stdout,'f',"Compare: total_exec_time is not 0)."); +is($stdout,'f',"Compare: ${col_total_time} is not 0)."); -# Test: min_exec_time is not 0 -($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (min_exec_time = 0) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']); +# Test: ${col_min_time} is not 0 +($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT (${col_min_time} = 0) from pg_stat_monitor where calls = 2 ;", extra_params => ['-Pformat=unaligned','-Ptuples_only=on']); trim($stdout); -is($stdout,'f',"Compare: min_exec_time is not 0)."); +is($stdout,'f',"Compare: ${col_min_time} is not 0)."); -# Test: max_exec_time is not 0 -($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (max_exec_time = 0) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']); +# Test: ${col_max_time} is not 0 +($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT (${col_max_time} = 0) from pg_stat_monitor where calls = 2 ;", extra_params => ['-Pformat=unaligned','-Ptuples_only=on']); trim($stdout); -is($stdout,'f',"Compare: max_exec_time is not 0)."); +is($stdout,'f',"Compare: ${col_max_time} is not 0)."); -# Test: mean_exec_time is not 0 -($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (mean_exec_time = 0) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']); +# Test: ${col_mean_time} is not 0 +($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT (${col_mean_time} = 0) from pg_stat_monitor where calls = 2 ;", extra_params => ['-Pformat=unaligned','-Ptuples_only=on']); trim($stdout); -is($stdout,'f',"Compare: mean_exec_time is not 0)."); +is($stdout,'f',"Compare: ${col_mean_time} is not 0)."); -# Test: stddev_exec_time is not 0 -#($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (stddev_exec_time = 0) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']); +# Test: ${col_stddev_time} is not 0 +#($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT (${col_stddev_time} = 0) from pg_stat_monitor where calls = 2 ;", extra_params => ['-Pformat=unaligned','-Ptuples_only=on']); #trim($stdout); -#is($stdout,'f',"Test: stddev_exec_time should not be 0)."); +#is($stdout,'f',"Test: ${col_stddev_time} should not be 0)."); -# Test: total_exec_time = min_exec_time + max_exec_time -($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (round(total_exec_time::numeric,3) = round(min_exec_time::numeric + max_exec_time::numeric,3)) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']); +# Test: ${col_total_time} = ${col_min_time} + ${col_max_time} +($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT (round(${col_total_time}::numeric,3) = round(${col_min_time}::numeric + ${col_max_time}::numeric,3)) from pg_stat_monitor where calls = 2 ;", extra_params => ['-Pformat=unaligned','-Ptuples_only=on']); trim($stdout); -is($stdout,'t',"Compare: (round(total_exec_time::numeric,3) = round(min_exec_time::numeric + max_exec_time::numeric,3))."); +is($stdout,'t',"Compare: (round(${col_total_time}::numeric,3) = round(${col_min_time}::numeric + ${col_max_time}::numeric,3))."); -# Test: mean_exec_time = total_exec_time/2 -#($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (round(mean_exec_time::numeric,3) = round((total_exec_time/2)::numeric,3)) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']); +# Test: ${col_mean_time} = ${col_total_time}/2 +#($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (round(${col_mean_time}::numeric,3) = round((${col_total_time}/2)::numeric,3)) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']); #trim($stdout); -#is($stdout,'t',"Compare mean_exec_time: (round(mean_exec_time::numeric,3) = round((total_exec_time/2)::numeric,3))."); +#is($stdout,'t',"Compare ${col_mean_time}: (round(${col_mean_time}::numeric,3) = round((${col_total_time}/2)::numeric,3))."); -# Test: stddev_exec_time = mean_exec_time - min_exec_time -#($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (round(stddev_exec_time::numeric,3) = round(mean_exec_time::numeric - min_exec_time::numeric,3)) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']); +# Test: ${col_stddev_time} = ${col_mean_time} - ${col_min_time} +#($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (round(${col_stddev_time}::numeric,3) = round(${col_mean_time}::numeric - ${col_min_time}::numeric,3)) from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']); #trim($stdout); -#is($stdout,'t',"Compare mean_exec_time: (round(stddev_exec_time::numeric,3) = round(mean_exec_time::numeric - min_exec_time::numeric,3))."); +#is($stdout,'t',"Compare ${col_mean_time}: (round(${col_stddev_time}::numeric,3) = round(${col_mean_time}::numeric - ${col_min_time}::numeric,3))."); # Dump output to out file -($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select substr(query, 0,100) as query, calls, total_exec_time, min_exec_time,max_exec_time,mean_exec_time,stddev_exec_time from pg_stat_monitor order by query;', extra_params => ['-a','-Pformat=aligned','-Ptuples_only=off']); +($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT substr(query, 0,100) as query, calls, ${col_total_time}, ${col_min_time},${col_max_time},${col_mean_time},${col_stddev_time} from pg_stat_monitor order by query;", extra_params => ['-a','-Pformat=aligned','-Ptuples_only=off']); TestLib::append_to_file($dynamic_out_filename_with_path, $stdout . "\n"); # Dump output to out file diff --git a/t/024_check_timings.pl b/t/024_check_timings.pl index f6482fe..cfc8121 100644 --- a/t/024_check_timings.pl +++ b/t/024_check_timings.pl @@ -2,10 +2,10 @@ use strict; use warnings; -use String::Util qw(trim); use File::Basename; use File::Compare; use PostgresNode; +use String::Util qw(trim); use Test::More; # Expected folder where expected output will be present @@ -29,6 +29,22 @@ unless (-d $expected_folder) # Get filename of the this perl file my $perlfilename = basename($0); +# Create new PostgreSQL node and do initdb +my $node = PostgresNode->get_new_node('test'); +my $pgdata = $node->data_dir; +$node->dump_info; +$node->init; + +# PG's major server version +open my $FH_PG_VERSION, '<', "${pgdata}/PG_VERSION"; +my $major_version = trim(<$FH_PG_VERSION>); +close $FH_PG_VERSION; + +if ($major_version <= 12) +{ + plan skip_all => "pg_stat_statements test cases for versions 12 and below."; +} + #Remove .pl from filename and store in a variable $perlfilename =~ s/\.[^.]+$//; my $filename_without_extension = $perlfilename; @@ -48,12 +64,6 @@ if ( -f $out_filename_with_path) unlink($out_filename_with_path) or die "Can't delete already existing $out_filename_with_path: $!\n"; } -# Create new PostgreSQL node and do initdb -my $node = PostgresNode->get_new_node('test'); -my $pgdata = $node->data_dir; -$node->dump_info; -$node->init; - # Update postgresql.conf to include/load pg_stat_monitor library $node->append_conf('postgresql.conf', "shared_preload_libraries = 'pg_stat_statements,pg_stat_monitor'"); # Set bucket duration to 3600 seconds so bucket doesn't change. diff --git a/t/025_compare_pgss.pl b/t/025_compare_pgss.pl index 7247cd8..ca6a07e 100644 --- a/t/025_compare_pgss.pl +++ b/t/025_compare_pgss.pl @@ -2,10 +2,10 @@ use strict; use warnings; -use String::Util qw(trim); use File::Basename; use File::Compare; use PostgresNode; +use String::Util qw(trim); use Test::More; # Expected folder where expected output will be present @@ -53,6 +53,16 @@ my $node = PostgresNode->get_new_node('test'); my $pgdata = $node->data_dir; $node->dump_info; $node->init; + +# PG's major server version +open my $FH_PG_VERSION, '<', "${pgdata}/PG_VERSION"; +my $major_version = trim(<$FH_PG_VERSION>); +close $FH_PG_VERSION; + +if ($major_version <= 12) +{ + plan skip_all => "pg_stat_statements test cases for versions 12 and below."; +} # Update postgresql.conf to include/load pg_stat_monitor library $node->append_conf('postgresql.conf', "shared_preload_libraries = 'pg_stat_statements,pg_stat_monitor'"); diff --git a/t/026_shared_blocks.pl b/t/026_shared_blocks.pl index 5b7bc37..1ec6f3d 100644 --- a/t/026_shared_blocks.pl +++ b/t/026_shared_blocks.pl @@ -2,10 +2,10 @@ use strict; use warnings; -use String::Util qw(trim); use File::Basename; use File::Compare; use PostgresNode; +use String::Util qw(trim); use Test::More; # Expected folder where expected output will be present @@ -53,6 +53,16 @@ my $node = PostgresNode->get_new_node('test'); my $pgdata = $node->data_dir; $node->dump_info; $node->init; + +# PG's major server version +open my $FH_PG_VERSION, '<', "${pgdata}/PG_VERSION"; +my $major_version = trim(<$FH_PG_VERSION>); +close $FH_PG_VERSION; + +if ($major_version <= 12) +{ + plan skip_all => "pg_stat_statements test cases for versions 12 and below."; +} # Update postgresql.conf to include/load pg_stat_monitor library $node->append_conf('postgresql.conf', "shared_preload_libraries = 'pg_stat_statements,pg_stat_monitor'"); diff --git a/t/027_local_blocks.pl b/t/027_local_blocks.pl index 67066dc..d83497e 100644 --- a/t/027_local_blocks.pl +++ b/t/027_local_blocks.pl @@ -2,10 +2,10 @@ use strict; use warnings; -use String::Util qw(trim); use File::Basename; use File::Compare; use PostgresNode; +use String::Util qw(trim); use Test::More; # Expected folder where expected output will be present @@ -53,6 +53,16 @@ my $node = PostgresNode->get_new_node('test'); my $pgdata = $node->data_dir; $node->dump_info; $node->init; + +# PG's major server version +open my $FH_PG_VERSION, '<', "${pgdata}/PG_VERSION"; +my $major_version = trim(<$FH_PG_VERSION>); +close $FH_PG_VERSION; + +if ($major_version <= 12) +{ + plan skip_all => "pg_stat_statements test cases for versions 12 and below."; +} # Update postgresql.conf to include/load pg_stat_monitor library $node->append_conf('postgresql.conf', "shared_preload_libraries = 'pg_stat_monitor'"); diff --git a/t/028_temp_block.pl b/t/028_temp_block.pl index 4ea79ca..2c1b376 100644 --- a/t/028_temp_block.pl +++ b/t/028_temp_block.pl @@ -2,10 +2,10 @@ use strict; use warnings; -use String::Util qw(trim); use File::Basename; use File::Compare; use PostgresNode; +use String::Util qw(trim); use Test::More; # Expected folder where expected output will be present @@ -53,6 +53,16 @@ my $node = PostgresNode->get_new_node('test'); my $pgdata = $node->data_dir; $node->dump_info; $node->init; + +# PG's major server version +open my $FH_PG_VERSION, '<', "${pgdata}/PG_VERSION"; +my $major_version = trim(<$FH_PG_VERSION>); +close $FH_PG_VERSION; + +if ($major_version <= 12) +{ + plan skip_all => "pg_stat_statements test cases for versions 12 and below."; +} # Update postgresql.conf to include/load pg_stat_monitor library $node->append_conf('postgresql.conf', "shared_preload_libraries = 'pg_stat_monitor'"); diff --git a/t/expected/001_settings_default.out.12 b/t/expected/001_settings_default.out.12 new file mode 100644 index 0000000..60a68cd --- /dev/null +++ b/t/expected/001_settings_default.out.12 @@ -0,0 +1,60 @@ +CREATE EXTENSION pg_stat_monitor; +SELECT pg_stat_monitor_reset(); + pg_stat_monitor_reset +----------------------- + +(1 row) + +SELECT * from pg_stat_monitor_settings; + name | value | default_value | description | minimum | maximum | options | restart +------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+--------- + pg_stat_monitor.pgsm_max | 100 | 100 | Sets the maximum size of shared memory in (MB) used for statement's metadata tracked by pg_stat_monitor. | 1 | 1000 | | yes + pg_stat_monitor.pgsm_query_max_len | 2048 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes + pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no + pg_stat_monitor.pgsm_normalized_query | no | no | Selects whether save query in normalized format. | | | yes, no | no + pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes + pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes + pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes + pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes + pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 50 | | yes + pg_stat_monitor.pgsm_query_shared_buffer | 20 | 20 | Sets the maximum size of shared memory in (MB) used for query tracked by pg_stat_monitor. | 1 | 10000 | | yes + pg_stat_monitor.pgsm_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes + pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no + pg_stat_monitor.pgsm_track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no + pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no +(14 rows) + +select datname, substr(query,0,100) as query, calls from pg_stat_monitor order by datname, query, calls desc Limit 20; + datname | query | calls +----------+-----------------------------------------------------------------------------------------------------+------- + postgres | SELECT * from pg_stat_monitor_settings | 1 + postgres | SELECT pg_stat_monitor_reset() | 1 + postgres | select datname, substr(query,0,100) as query, calls from pg_stat_monitor order by datname, query, c | 1 +(3 rows) + +SELECT * from pg_stat_monitor_settings; + name | value | default_value | description | minimum | maximum | options | restart +------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+----------------+--------- + pg_stat_monitor.pgsm_max | 100 | 100 | Sets the maximum size of shared memory in (MB) used for statement's metadata tracked by pg_stat_monitor. | 1 | 1000 | | yes + pg_stat_monitor.pgsm_query_max_len | 2048 | 2048 | Sets the maximum length of query. | 1024 | 2147483647 | | yes + pg_stat_monitor.pgsm_track_utility | yes | yes | Selects whether utility commands are tracked. | | | yes, no | no + pg_stat_monitor.pgsm_normalized_query | no | no | Selects whether save query in normalized format. | | | yes, no | no + pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | | yes + pg_stat_monitor.pgsm_bucket_time | 60 | 60 | Sets the time in seconds per bucket. | 1 | 2147483647 | | yes + pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | | yes + pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | | yes + pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 50 | | yes + pg_stat_monitor.pgsm_query_shared_buffer | 20 | 20 | Sets the maximum size of shared memory in (MB) used for query tracked by pg_stat_monitor. | 1 | 10000 | | yes + pg_stat_monitor.pgsm_overflow_target | 1 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | | yes + pg_stat_monitor.pgsm_enable_query_plan | no | no | Enable/Disable query plan monitoring | | | yes, no | no + pg_stat_monitor.pgsm_track | top | top | Selects which statements are tracked by pg_stat_monitor. | | | none, top, all | no + pg_stat_monitor.pgsm_extract_comments | no | no | Enable/Disable extracting comments from queries. | | | yes, no | no +(14 rows) + +SELECT pg_stat_monitor_reset(); + pg_stat_monitor_reset +----------------------- + +(1 row) + +Drop extension pg_stat_monitor;