PG-376: Enable TAP testing on PG 12 (#285)

This commit does not make any changes to the makefile. It simply ensures that
the test cases work with PG12. Necessary skip statements are added. Makefile
changes are to be done as part refactoring the Makefile.
pull/289/head
Hamid Akhtar 2022-08-03 00:08:52 +05:00 committed by GitHub
parent cf1f7a842f
commit 31e3c801a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 283 additions and 102 deletions

View File

@ -3,11 +3,17 @@
use String::Util qw(trim); use String::Util qw(trim);
use File::Basename; use File::Basename;
use File::Compare; use File::Compare;
use String::Util qw(trim);
use Test::More; use Test::More;
use lib 't'; use lib 't';
use pgsm; 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 sub check_value
{ {
my ($var, $postive, $expected, $val) = @_; my ($var, $postive, $expected, $val) = @_;
@ -58,8 +64,15 @@ sub do_regression
} }
($cmdret, $stdout, $stderr) = pgsm_init_pg; ($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(); ($cmdret, $stdout, $stderr) = done_testing();

View File

@ -4,7 +4,9 @@ use strict;
use warnings; use warnings;
use File::Basename; use File::Basename;
use File::Compare; use File::Compare;
use File::Copy;
use PostgresNode; use PostgresNode;
use String::Util qw(trim);
use Test::More; use Test::More;
# Expected folder where expected output will be present # 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";; 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 # Get filename of the this perl file
my $perlfilename = basename($0); my $perlfilename = basename($0);
@ -38,6 +51,12 @@ my $filename_without_extension = $perlfilename;
# Create expected filename with path # Create expected filename with path
my $expected_filename = "${filename_without_extension}.out"; 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}" ; my $expected_filename_with_path = "${expected_folder}/${expected_filename}" ;
# Create results filename with path # 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"; 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 # Update postgresql.conf to include/load pg_stat_monitor library
open my $conf, '>>', "$pgdata/postgresql.conf"; open my $conf, '>>', "$pgdata/postgresql.conf";
print $conf "shared_preload_libraries = 'pg_stat_monitor'\n"; print $conf "shared_preload_libraries = 'pg_stat_monitor'\n";

View File

@ -6,6 +6,7 @@ use String::Util qw(trim);
use File::Basename; use File::Basename;
use File::Compare; use File::Compare;
use PostgresNode; use PostgresNode;
use String::Util qw(trim);
use Test::More; use Test::More;
# Expected folder where expected output will be present # Expected folder where expected output will be present
@ -54,6 +55,11 @@ my $pgdata = $node->data_dir;
$node->dump_info; $node->dump_info;
$node->init; $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 # Update postgresql.conf to include/load pg_stat_monitor library
open my $conf, '>>', "$pgdata/postgresql.conf"; open my $conf, '>>', "$pgdata/postgresql.conf";
print $conf "shared_preload_libraries = 'pg_stat_monitor'\n"; 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"); ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n"); 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']); SKIP:
ok($cmdret == 0, "Select from PGSM view"); {
TestLib::append_to_file($out_filename_with_path, $stdout . "\n"); 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 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']);
($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']); ok($cmdret == 0, "Select from PGSM view");
trim($stdout); TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
is($stdout,'f',"Compare: total_plan_time is not 0).");
# Test: min_plan_time is not 0 # Test: total_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']); ($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); trim($stdout);
is($stdout,'f',"Compare: min_plan_time is not 0)."); is($stdout,'f',"Compare: total_plan_time is not 0).");
# Test: max_plan_time is not 0 # Test: min_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']); ($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); trim($stdout);
is($stdout,'f',"Compare: max_plan_time is not 0)."); is($stdout,'f',"Compare: min_plan_time is not 0).");
# Test: mean_plan_time is not 0 # Test: max_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']); ($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); trim($stdout);
is($stdout,'f',"Compare: mean_plan_time is not 0)."); is($stdout,'f',"Compare: max_plan_time is not 0).");
# Test: stddev_plan_time is not 0 # Test: mean_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']); ($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); trim($stdout);
#is($stdout,'f',"Compare: stddev_plan_time is not 0)."); is($stdout,'f',"Compare: mean_plan_time is not 0).");
# Test: total_plan_time = min_plan_time + max_plan_time # Test: stddev_plan_time is not 0
($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']); #($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); #trim($stdout);
is($stdout,'t',"Compare: (round(total_plan_time::numeric,3) = round(min_plan_time::numeric + max_plan_time::numeric,3))."); #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 # 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']); #($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"); ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n"); 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']); SKIP:
ok($cmdret == 0, "Select from PGSM view"); {
TestLib::append_to_file($out_filename_with_path, $stdout . "\n"); 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 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']);
($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']); ok($cmdret == 0, "Select from PGSM view");
trim($stdout); TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
is($stdout,'t',"Compare: total_plan_time is 0).");
# Test: min_plan_time is 0 # Test: total_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']); ($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); trim($stdout);
is($stdout,'t',"Compare: min_plan_time is 0)."); is($stdout,'t',"Compare: total_plan_time is 0).");
# Test: max_plan_time is 0 # Test: min_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']); ($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); trim($stdout);
is($stdout,'t',"Compare: max_plan_time is 0)."); is($stdout,'t',"Compare: min_plan_time is 0).");
# Test: mean_plan_time is 0 # Test: max_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']); ($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); trim($stdout);
is($stdout,'t',"Compare: mean_plan_time is 0)."); is($stdout,'t',"Compare: max_plan_time is 0).");
# Test: stddev_plan_time is 0 # Test: mean_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']); ($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); trim($stdout);
is($stdout,'t',"Compare: stddev_plan_time is 0)."); 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 # 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']); ($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']);

View File

@ -51,7 +51,7 @@ my $node = PostgresNode->get_new_node('test');
my $pgdata = $node->data_dir; my $pgdata = $node->data_dir;
$node->dump_info; $node->dump_info;
$node->init; $node->init;
# Update postgresql.conf to include/load pg_stat_monitor library # Update postgresql.conf to include/load pg_stat_monitor library
open my $conf, '>>', "$pgdata/postgresql.conf"; open my $conf, '>>', "$pgdata/postgresql.conf";
print $conf "shared_preload_libraries = 'pg_stat_monitor'\n"; print $conf "shared_preload_libraries = 'pg_stat_monitor'\n";

View File

@ -5,6 +5,7 @@ use warnings;
use File::Basename; use File::Basename;
use File::Compare; use File::Compare;
use PostgresNode; use PostgresNode;
use String::Util qw(trim);
use Test::More; use Test::More;
# Expected folder where expected output will be present # Expected folder where expected output will be present
@ -52,6 +53,11 @@ my $pgdata = $node->data_dir;
$node->dump_info; $node->dump_info;
$node->init; $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 # Update postgresql.conf to include/load pg_stat_monitor library
open my $conf, '>>', "$pgdata/postgresql.conf"; open my $conf, '>>', "$pgdata/postgresql.conf";
print $conf "shared_preload_libraries = 'pg_stat_monitor'\n"; print $conf "shared_preload_libraries = 'pg_stat_monitor'\n";

View File

@ -6,6 +6,7 @@ use String::Util qw(trim);
use File::Basename; use File::Basename;
use File::Compare; use File::Compare;
use PostgresNode; use PostgresNode;
use String::Util qw(trim);
use Test::More; use Test::More;
# Expected folder where expected output will be present # Expected folder where expected output will be present
@ -33,6 +34,17 @@ my $perlfilename = basename($0);
$perlfilename =~ s/\.[^.]+$//; $perlfilename =~ s/\.[^.]+$//;
my $filename_without_extension = $perlfilename; 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 # Create expected filename with path
my $expected_filename = "${filename_without_extension}.out"; my $expected_filename = "${filename_without_extension}.out";
my $expected_filename_with_path = "${expected_folder}/${expected_filename}" ; 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"; 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 # Update postgresql.conf to include/load pg_stat_monitor library
open my $conf, '>>', "$pgdata/postgresql.conf"; open my $conf, '>>', "$pgdata/postgresql.conf";
print $conf "shared_preload_libraries = 'pg_stat_monitor'\n"; print $conf "shared_preload_libraries = 'pg_stat_monitor'\n";
@ -63,6 +69,21 @@ close $conf;
my $rt_value = $node->start; my $rt_value = $node->start;
ok($rt_value == 1, "Start Server"); 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 # Create extension and change out file permissions
my ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE EXTENSION pg_stat_monitor;', extra_params => ['-a']); my ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE EXTENSION pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Create PGSM Extension"); 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"); ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n"); 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"); ok($cmdret == 0, "Select from PGSM view");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n"); TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# Test: total_exec_time is not 0 # Test: ${col_total_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']); ($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); 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 # Test: ${col_min_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']); ($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); 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 # Test: ${col_max_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']); ($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); 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 # Test: ${col_mean_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']); ($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); 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 # Test: ${col_stddev_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']); #($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); #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 # Test: ${col_total_time} = ${col_min_time} + ${col_max_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']); ($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); 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 # Test: ${col_mean_time} = ${col_total_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']); #($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); #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 # Test: ${col_stddev_time} = ${col_mean_time} - ${col_min_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']); #($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); #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 # 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"); TestLib::append_to_file($dynamic_out_filename_with_path, $stdout . "\n");
# Dump output to out file # Dump output to out file

View File

@ -2,10 +2,10 @@
use strict; use strict;
use warnings; use warnings;
use String::Util qw(trim);
use File::Basename; use File::Basename;
use File::Compare; use File::Compare;
use PostgresNode; use PostgresNode;
use String::Util qw(trim);
use Test::More; use Test::More;
# Expected folder where expected output will be present # Expected folder where expected output will be present
@ -29,6 +29,22 @@ unless (-d $expected_folder)
# Get filename of the this perl file # Get filename of the this perl file
my $perlfilename = basename($0); 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 #Remove .pl from filename and store in a variable
$perlfilename =~ s/\.[^.]+$//; $perlfilename =~ s/\.[^.]+$//;
my $filename_without_extension = $perlfilename; 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"; 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 # Update postgresql.conf to include/load pg_stat_monitor library
$node->append_conf('postgresql.conf', "shared_preload_libraries = 'pg_stat_statements,pg_stat_monitor'"); $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. # Set bucket duration to 3600 seconds so bucket doesn't change.

View File

@ -2,10 +2,10 @@
use strict; use strict;
use warnings; use warnings;
use String::Util qw(trim);
use File::Basename; use File::Basename;
use File::Compare; use File::Compare;
use PostgresNode; use PostgresNode;
use String::Util qw(trim);
use Test::More; use Test::More;
# Expected folder where expected output will be present # Expected folder where expected output will be present
@ -53,6 +53,16 @@ my $node = PostgresNode->get_new_node('test');
my $pgdata = $node->data_dir; my $pgdata = $node->data_dir;
$node->dump_info; $node->dump_info;
$node->init; $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 # Update postgresql.conf to include/load pg_stat_monitor library
$node->append_conf('postgresql.conf', "shared_preload_libraries = 'pg_stat_statements,pg_stat_monitor'"); $node->append_conf('postgresql.conf', "shared_preload_libraries = 'pg_stat_statements,pg_stat_monitor'");

View File

@ -2,10 +2,10 @@
use strict; use strict;
use warnings; use warnings;
use String::Util qw(trim);
use File::Basename; use File::Basename;
use File::Compare; use File::Compare;
use PostgresNode; use PostgresNode;
use String::Util qw(trim);
use Test::More; use Test::More;
# Expected folder where expected output will be present # Expected folder where expected output will be present
@ -53,6 +53,16 @@ my $node = PostgresNode->get_new_node('test');
my $pgdata = $node->data_dir; my $pgdata = $node->data_dir;
$node->dump_info; $node->dump_info;
$node->init; $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 # Update postgresql.conf to include/load pg_stat_monitor library
$node->append_conf('postgresql.conf', "shared_preload_libraries = 'pg_stat_statements,pg_stat_monitor'"); $node->append_conf('postgresql.conf', "shared_preload_libraries = 'pg_stat_statements,pg_stat_monitor'");

View File

@ -2,10 +2,10 @@
use strict; use strict;
use warnings; use warnings;
use String::Util qw(trim);
use File::Basename; use File::Basename;
use File::Compare; use File::Compare;
use PostgresNode; use PostgresNode;
use String::Util qw(trim);
use Test::More; use Test::More;
# Expected folder where expected output will be present # Expected folder where expected output will be present
@ -53,6 +53,16 @@ my $node = PostgresNode->get_new_node('test');
my $pgdata = $node->data_dir; my $pgdata = $node->data_dir;
$node->dump_info; $node->dump_info;
$node->init; $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 # Update postgresql.conf to include/load pg_stat_monitor library
$node->append_conf('postgresql.conf', "shared_preload_libraries = 'pg_stat_monitor'"); $node->append_conf('postgresql.conf', "shared_preload_libraries = 'pg_stat_monitor'");

View File

@ -2,10 +2,10 @@
use strict; use strict;
use warnings; use warnings;
use String::Util qw(trim);
use File::Basename; use File::Basename;
use File::Compare; use File::Compare;
use PostgresNode; use PostgresNode;
use String::Util qw(trim);
use Test::More; use Test::More;
# Expected folder where expected output will be present # Expected folder where expected output will be present
@ -53,6 +53,16 @@ my $node = PostgresNode->get_new_node('test');
my $pgdata = $node->data_dir; my $pgdata = $node->data_dir;
$node->dump_info; $node->dump_info;
$node->init; $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 # Update postgresql.conf to include/load pg_stat_monitor library
$node->append_conf('postgresql.conf', "shared_preload_libraries = 'pg_stat_monitor'"); $node->append_conf('postgresql.conf', "shared_preload_libraries = 'pg_stat_monitor'");

View File

@ -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;