Merge pull request #311 from EngineeredVirus/main

Merging changes back to the main branch after the 1.1.1 release
pull/312/head
Kai Wagner 2022-11-11 10:14:18 +01:00 committed by GitHub
commit fddc0967e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
44 changed files with 1202 additions and 1832 deletions

View File

@ -5,7 +5,7 @@ jobs:
build:
name: pg-11-pgsm-pmm-integration-test
runs-on: ubuntu-latest
timeout-minutes: 20
timeout-minutes: 30
steps:
- name: Clone QA Integration repository
uses: actions/checkout@v2
@ -18,7 +18,7 @@ jobs:
run: echo 'The branch and Repo Name is' ${{ github.head_ref }} ${{ github.actor }}/pg_stat_monitor
- name: Run PMM & PGSM Setup, E2E Tests
run: bash -xe ./pmm_pgsm_setup/pmm_pgsm_setup.sh --pgsql-version=11
run: bash -xe ./pmm_pgsm_setup/pmm_pgsm_setup.sh --pgsql-version=11 --pgstat-monitor-branch=REL_1_1_1
- name: Get PMM-Agent Logs from the Container
if: success() || failure() # run this step even if previous step failed

View File

@ -5,7 +5,7 @@ jobs:
build:
name: pg-12-pgsm-pmm-integration-test
runs-on: ubuntu-latest
timeout-minutes: 20
timeout-minutes: 30
steps:
- name: Clone QA Integration repository
uses: actions/checkout@v2
@ -18,7 +18,7 @@ jobs:
run: echo 'The branch and Repo Name is' ${{ github.head_ref }} ${{ github.actor }}/pg_stat_monitor
- name: Run PMM & PGSM Setup, E2E Tests
run: bash -xe ./pmm_pgsm_setup/pmm_pgsm_setup.sh --pgsql-version=12
run: bash -xe ./pmm_pgsm_setup/pmm_pgsm_setup.sh --pgsql-version=12 --pgstat-monitor-branch=REL_1_1_1
- name: Get PMM-Agent Logs from the Container
if: success() || failure() # run this step even if previous step failed

View File

@ -5,7 +5,7 @@ jobs:
build:
name: pg-13-pgsm-pmm-integration-test
runs-on: ubuntu-latest
timeout-minutes: 20
timeout-minutes: 30
steps:
- name: Clone QA Integration repository
uses: actions/checkout@v2
@ -18,7 +18,7 @@ jobs:
run: echo 'The branch and Repo Name is' ${{ github.head_ref }} ${{ github.actor }}/pg_stat_monitor
- name: Run PMM & PGSM Setup, E2E Tests
run: bash -xe ./pmm_pgsm_setup/pmm_pgsm_setup.sh --pgsql-version=13
run: bash -xe ./pmm_pgsm_setup/pmm_pgsm_setup.sh --pgsql-version=13 --pgstat-monitor-branch=REL_1_1_1
- name: Get PMM-Agent Logs from the Container
if: success() || failure() # run this step even if previous step failed

View File

@ -5,7 +5,7 @@ jobs:
build:
name: pg-14-pgsm-pmm-integration-test
runs-on: ubuntu-latest
timeout-minutes: 20
timeout-minutes: 30
steps:
- name: Clone QA Integration repository
uses: actions/checkout@v2
@ -18,7 +18,7 @@ jobs:
run: echo 'The branch and Repo Name is' ${{ github.head_ref }} ${{ github.actor }}/pg_stat_monitor
- name: Run PMM & PGSM Setup, E2E Tests
run: bash -xe ./pmm_pgsm_setup/pmm_pgsm_setup.sh --pgsql-version=14
run: bash -xe ./pmm_pgsm_setup/pmm_pgsm_setup.sh --pgsql-version=14 --pgstat-monitor-branch=REL_1_1_1
- name: Get PMM-Agent Logs from the Container
if: success() || failure() # run this step even if previous step failed

View File

@ -0,0 +1,33 @@
name: postgresql-15-pmm-integration
on: push
jobs:
build:
name: pg-15-pgsm-pmm-integration-test
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Clone QA Integration repository
uses: actions/checkout@v2
with:
repository: 'Percona-Lab/qa-integration'
ref: 'main'
# print branch and Repo name
- name: Get branch and Repo Name
run: echo 'The branch and Repo Name is' ${{ github.head_ref }} ${{ github.actor }}/pg_stat_monitor
- name: Run PMM & PGSM Setup, E2E Tests
run: bash -xe ./pmm_pgsm_setup/pmm_pgsm_setup.sh --pgsql-version=15 --pgstat-monitor-branch=REL_1_1_1
- name: Get PMM-Agent Logs from the Container
if: success() || failure() # run this step even if previous step failed
run: docker exec pgsql_pgsm_15 cat pmm-agent.log > ./pmm-ui-tests/tests/output/pmm-agent.log
- name: Upload Tests Artifacts
uses: actions/upload-artifact@v3
if: success() || failure() # run this step even if previous step failed
with:
name: tests-artifact
path: ./pmm-ui-tests/tests/output/
if-no-files-found: ignore # 'warn' or 'ignore' are also available, defaults to `warn`

View File

@ -2,7 +2,7 @@
"name": "pg_stat_monitor",
"abstract": "PostgreSQL Query Performance Monitoring Tool",
"description": "pg_stat_monitor is a PostgreSQL Query Performance Monitoring tool, based on PostgreSQL's contrib module pg_stat_statements. PostgreSQLs pg_stat_statements provides the basic statistics, which is sometimes not enough. The major shortcoming in pg_stat_statements is that it accumulates all the queries and their statistics and does not provide aggregated statistics nor histogram information. In this case, a user would need to calculate the aggregates, which is quite an expensive operation.",
"version": "1.1.0",
"version": "1.1.1",
"maintainer": [
"ibrar.ahmed@percona.com"
],
@ -12,7 +12,7 @@
"abstract": "PostgreSQL Query Performance Monitoring Tool",
"file": "pg_stat_monitor--1.0.sql",
"docfile": "README.md",
"version": "1.1.0"
"version": "1.1.1"
}
},
"prereqs": {

View File

@ -2,6 +2,13 @@
Below is the complete list of release notes for every version of ``pg_stat_monitor``.
## 1.1.1
### Bugs Fixed
[PG-520](https://jira.percona.com/browse/PG-520): pg_stat_monitor does not work with PostgreSQL15
## 1.1.0
### Improvements

View File

@ -25,7 +25,7 @@
PG_MODULE_MAGIC;
#define BUILD_VERSION "1.1.0"
#define BUILD_VERSION "1.1.1"
#define PG_STAT_STATEMENTS_COLS 53 /* maximum of above */
#define PGSM_TEXT_FILE PGSTAT_STAT_PERMANENT_DIRECTORY "pg_stat_monitor_query"
@ -81,10 +81,15 @@ static int get_histogram_bucket(double q_time);
static bool IsSystemInitialized(void);
static bool dump_queries_buffer(int bucket_id, unsigned char *buf, int buf_len);
static double time_diff(struct timeval end, struct timeval start);
static void request_additional_shared_resources(void);
/* Saved hook values in case of unload */
#if PG_VERSION_NUM >= 150000
static void pgss_shmem_request(void);
static shmem_request_hook_type prev_shmem_request_hook = NULL;
#endif
#if PG_VERSION_NUM >= 130000
static planner_hook_type planner_hook_next = NULL;
#endif
@ -256,17 +261,15 @@ _PG_init(void)
elog(ERROR, "pg_stat_monitor: query comments regcomp() failed, return code=(%d)\n", rc);
}
/*
* Request additional shared resources. (These are no-ops if we're not in
* the postmaster process.) We'll allocate or attach to the shared
* resources in pgss_shmem_startup().
*/
RequestAddinShmemSpace(hash_memsize() + HOOK_STATS_SIZE);
RequestNamedLWLockTranche("pg_stat_monitor", 1);
/*
* Install hooks.
*/
#if PG_VERSION_NUM >= 150000
prev_shmem_request_hook = shmem_request_hook;
shmem_request_hook = pgss_shmem_request;
#else
request_additional_shared_resources();
#endif
prev_shmem_startup_hook = shmem_startup_hook;
shmem_startup_hook = pgss_shmem_startup;
prev_post_parse_analyze_hook = post_parse_analyze_hook;
@ -333,6 +336,17 @@ pgss_shmem_startup(void)
pgss_startup();
}
static void
request_additional_shared_resources(void)
{
/*
* Request additional shared resources. (These are no-ops if we're not in
* the postmaster process.) We'll allocate or attach to the shared
* resources in pgss_shmem_startup().
*/
RequestAddinShmemSpace(hash_memsize() + HOOK_STATS_SIZE);
RequestNamedLWLockTranche("pg_stat_monitor", 1);
}
/*
* Select the version of pg_stat_monitor.
*/
@ -342,6 +356,20 @@ pg_stat_monitor_version(PG_FUNCTION_ARGS)
PG_RETURN_TEXT_P(cstring_to_text(BUILD_VERSION));
}
#if PG_VERSION_NUM >= 150000
/*
* shmem_request hook: request additional shared resources. We'll allocate or
* attach to the shared resources in pgss_shmem_startup().
*/
static void
pgss_shmem_request(void)
{
if (prev_shmem_request_hook)
prev_shmem_request_hook();
request_additional_shared_resources();
}
#endif
#if PG_VERSION_NUM >= 140000
/*
* Post-parse-analysis hook: mark query with a queryId

View File

@ -0,0 +1,73 @@
CREATE OR REPLACE FUNCTION generate_histogram()
RETURNS TABLE (
range TEXT, freq INT, bar TEXT
) AS $$
Declare
bucket_id integer;
query_id text;
BEGIN
select bucket into bucket_id from pg_stat_monitor order by calls desc limit 1;
select queryid into query_id from pg_stat_monitor order by calls desc limit 1;
--RAISE INFO 'bucket_id %', bucket_id;
--RAISE INFO 'query_id %', query_id;
return query
SELECT * FROM histogram(bucket_id, query_id) AS a(range TEXT, freq INT, bar TEXT);
END;
$$ LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION run_pg_sleep(INTEGER) RETURNS VOID AS $$
DECLARE
loops ALIAS FOR $1;
BEGIN
FOR i IN 1..loops LOOP
--RAISE INFO 'Current timestamp: %', timeofday()::TIMESTAMP;
RAISE INFO 'Sleep % seconds', i;
PERFORM pg_sleep(i);
END LOOP;
END;
$$ LANGUAGE 'plpgsql' STRICT;
CREATE EXTENSION pg_stat_monitor;
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
Set pg_stat_monitor.pgsm_track='all';
select run_pg_sleep(5);
INFO: Sleep 1 seconds
INFO: Sleep 2 seconds
INFO: Sleep 3 seconds
INFO: Sleep 4 seconds
INFO: Sleep 5 seconds
run_pg_sleep
--------------
(1 row)
SELECT substr(query, 0,50) as query, calls, resp_calls FROM pg_stat_monitor ORDER BY query COLLATE "C";
query | calls | resp_calls
---------------------------------------------------+-------+-----------------------
SELECT pg_sleep(i) | 3 | {0,0,0,0,0,0,3,0,0,0}
SELECT pg_sleep(i) | 2 | {0,0,0,0,0,0,0,2,0,0}
SELECT pg_stat_monitor_reset() | 1 | {1,0,0,0,0,0,0,0,0,0}
SELECT substr(query, 0,50) as query, calls, resp_ | 1 | {1,0,0,0,0,0,0,0,0,0}
Set pg_stat_monitor.pgsm_track='all' | 1 | {1,0,0,0,0,0,0,0,0,0}
select run_pg_sleep(5) | 1 | {0,0,0,0,0,0,0,0,1,0}
(6 rows)
select * from generate_histogram();
range | freq | bar
--------------------+------+--------------------------------------------------------------------------------------------
(0 - 3)} | 0 |
(3 - 10)} | 0 |
(10 - 31)} | 0 |
(31 - 100)} | 0 |
(100 - 316)} | 0 |
(316 - 1000)} | 0 |
(1000 - 3162)} | 3 | ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
(3162 - 10000)} | 0 |
(10000 - 31622)} | 0 |
(31622 - 100000)} | 0 |
(10 rows)
DROP EXTENSION pg_stat_monitor;

View File

@ -0,0 +1,73 @@
CREATE OR REPLACE FUNCTION generate_histogram()
RETURNS TABLE (
range TEXT, freq INT, bar TEXT
) AS $$
Declare
bucket_id integer;
query_id text;
BEGIN
select bucket into bucket_id from pg_stat_monitor order by calls desc limit 1;
select queryid into query_id from pg_stat_monitor order by calls desc limit 1;
--RAISE INFO 'bucket_id %', bucket_id;
--RAISE INFO 'query_id %', query_id;
return query
SELECT * FROM histogram(bucket_id, query_id) AS a(range TEXT, freq INT, bar TEXT);
END;
$$ LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION run_pg_sleep(INTEGER) RETURNS VOID AS $$
DECLARE
loops ALIAS FOR $1;
BEGIN
FOR i IN 1..loops LOOP
--RAISE INFO 'Current timestamp: %', timeofday()::TIMESTAMP;
RAISE INFO 'Sleep % seconds', i;
PERFORM pg_sleep(i);
END LOOP;
END;
$$ LANGUAGE 'plpgsql' STRICT;
CREATE EXTENSION pg_stat_monitor;
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
Set pg_stat_monitor.pgsm_track='all';
select run_pg_sleep(5);
INFO: Sleep 1 seconds
INFO: Sleep 2 seconds
INFO: Sleep 3 seconds
INFO: Sleep 4 seconds
INFO: Sleep 5 seconds
run_pg_sleep
--------------
(1 row)
SELECT substr(query, 0,50) as query, calls, resp_calls FROM pg_stat_monitor ORDER BY query COLLATE "C";
query | calls | resp_calls
---------------------------------------------------+-------+-----------------------
SELECT pg_sleep(i) | 3 | {0,0,0,0,0,0,3,0,0,0}
SELECT pg_sleep(i) | 2 | {0,0,0,0,0,0,0,2,0,0}
SELECT pg_stat_monitor_reset() | 1 | {1,0,0,0,0,0,0,0,0,0}
SELECT substr(query, 0,50) as query, calls, resp_ | 1 | {1,0,0,0,0,0,0,0,0,0}
Set pg_stat_monitor.pgsm_track='all' | 1 | {1,0,0,0,0,0,0,0,0,0}
select run_pg_sleep(5) | 1 | {0,0,0,0,0,0,0,0,1,0}
(6 rows)
select * from generate_histogram();
range | freq | bar
--------------------+------+--------------------------------
(0 - 3)} | 0 |
(3 - 10)} | 0 |
(10 - 31)} | 0 |
(31 - 100)} | 0 |
(100 - 316)} | 0 |
(316 - 1000)} | 0 |
(1000 - 3162)} | 3 | ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
(3162 - 10000)} | 0 |
(10000 - 31622)} | 0 |
(31622 - 100000)} | 0 |
(10 rows)
DROP EXTENSION pg_stat_monitor;

View File

@ -0,0 +1,72 @@
CREATE OR REPLACE FUNCTION generate_histogram()
RETURNS TABLE (
range TEXT, freq INT, bar TEXT
) AS $$
Declare
bucket_id integer;
query_id text;
BEGIN
select bucket into bucket_id from pg_stat_monitor order by calls desc limit 1;
select queryid into query_id from pg_stat_monitor order by calls desc limit 1;
--RAISE INFO 'bucket_id %', bucket_id;
--RAISE INFO 'query_id %', query_id;
return query
SELECT * FROM histogram(bucket_id, query_id) AS a(range TEXT, freq INT, bar TEXT);
END;
$$ LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION run_pg_sleep(INTEGER) RETURNS VOID AS $$
DECLARE
loops ALIAS FOR $1;
BEGIN
FOR i IN 1..loops LOOP
--RAISE INFO 'Current timestamp: %', timeofday()::TIMESTAMP;
RAISE INFO 'Sleep % seconds', i;
PERFORM pg_sleep(i);
END LOOP;
END;
$$ LANGUAGE 'plpgsql' STRICT;
CREATE EXTENSION pg_stat_monitor;
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
Set pg_stat_monitor.pgsm_track='all';
select run_pg_sleep(5);
INFO: Sleep 1 seconds
INFO: Sleep 2 seconds
INFO: Sleep 3 seconds
INFO: Sleep 4 seconds
INFO: Sleep 5 seconds
run_pg_sleep
--------------
(1 row)
SELECT substr(query, 0,50) as query, calls, resp_calls FROM pg_stat_monitor ORDER BY query COLLATE "C";
query | calls | resp_calls
---------------------------------------------------+-------+-----------------------
SELECT pg_sleep(i) | 4 | {0,0,0,0,0,0,2,2,0,0}
SELECT pg_stat_monitor_reset() | 1 | {1,0,0,0,0,0,0,0,0,0}
SELECT substr(query, 0,50) as query, calls, resp_ | 1 | {1,0,0,0,0,0,0,0,0,0}
Set pg_stat_monitor.pgsm_track='all' | 1 | {1,0,0,0,0,0,0,0,0,0}
select run_pg_sleep(5) | 1 | {0,0,0,0,0,0,0,0,1,0}
(5 rows)
select * from generate_histogram();
range | freq | bar
--------------------+------+--------------------------------
(0 - 3)} | 0 |
(3 - 10)} | 0 |
(10 - 31)} | 0 |
(31 - 100)} | 0 |
(100 - 316)} | 0 |
(316 - 1000)} | 0 |
(1000 - 3162)} | 2 | ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
(3162 - 10000)} | 2 | ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
(10000 - 31622)} | 0 |
(31622 - 100000)} | 0 |
(10 rows)
DROP EXTENSION pg_stat_monitor;

View File

@ -0,0 +1,73 @@
CREATE OR REPLACE FUNCTION generate_histogram()
RETURNS TABLE (
range TEXT, freq INT, bar TEXT
) AS $$
Declare
bucket_id integer;
query_id text;
BEGIN
select bucket into bucket_id from pg_stat_monitor order by calls desc limit 1;
select queryid into query_id from pg_stat_monitor order by calls desc limit 1;
--RAISE INFO 'bucket_id %', bucket_id;
--RAISE INFO 'query_id %', query_id;
return query
SELECT * FROM histogram(bucket_id, query_id) AS a(range TEXT, freq INT, bar TEXT);
END;
$$ LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION run_pg_sleep(INTEGER) RETURNS VOID AS $$
DECLARE
loops ALIAS FOR $1;
BEGIN
FOR i IN 1..loops LOOP
--RAISE INFO 'Current timestamp: %', timeofday()::TIMESTAMP;
RAISE INFO 'Sleep % seconds', i;
PERFORM pg_sleep(i);
END LOOP;
END;
$$ LANGUAGE 'plpgsql' STRICT;
CREATE EXTENSION pg_stat_monitor;
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
Set pg_stat_monitor.pgsm_track='all';
select run_pg_sleep(5);
INFO: Sleep 1 seconds
INFO: Sleep 2 seconds
INFO: Sleep 3 seconds
INFO: Sleep 4 seconds
INFO: Sleep 5 seconds
run_pg_sleep
--------------
(1 row)
SELECT substr(query, 0,50) as query, calls, resp_calls FROM pg_stat_monitor ORDER BY query COLLATE "C";
query | calls | resp_calls
---------------------------------------------------+-------+-----------------------
SELECT pg_sleep(i) | 2 | {0,0,0,0,0,0,2,0,0,0}
SELECT pg_sleep(i) | 3 | {0,0,0,0,0,0,1,2,0,0}
SELECT pg_stat_monitor_reset() | 1 | {1,0,0,0,0,0,0,0,0,0}
SELECT substr(query, 0,50) as query, calls, resp_ | 1 | {1,0,0,0,0,0,0,0,0,0}
Set pg_stat_monitor.pgsm_track='all' | 1 | {1,0,0,0,0,0,0,0,0,0}
select run_pg_sleep(5) | 1 | {0,0,0,0,0,0,0,0,1,0}
(6 rows)
select * from generate_histogram();
range | freq | bar
--------------------+------+--------------------------------
(0 - 3)} | 0 |
(3 - 10)} | 0 |
(10 - 31)} | 0 |
(31 - 100)} | 0 |
(100 - 316)} | 0 |
(316 - 1000)} | 0 |
(1000 - 3162)} | 1 | ■■■■■■■■■■■■■■■
(3162 - 10000)} | 2 | ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
(10000 - 31622)} | 0 |
(31622 - 100000)} | 0 |
(10 rows)
DROP EXTENSION pg_stat_monitor;

View File

@ -2,7 +2,7 @@ CREATE EXTENSION pg_stat_monitor;
SELECT pg_stat_monitor_version();
pg_stat_monitor_version
-------------------------
1.1.0
1.1.1
(1 row)
DROP EXTENSION pg_stat_monitor;

View File

@ -1,78 +0,0 @@
#!/usr/bin/perl
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) = @_;
if ($postive)
{
is($expected, $val, "Checking $var...");
}
else
{
isnt($expected, $val, "Checking $var...");
}
}
sub do_testing
{
my ($expected, $postive) = @_;
my ($cmdret, $stdout, $stderr) = pgsm_psql_cmd('postgres', 'SELECT max(total_plan_time) FROM pg_stat_monitor;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
my $total_plan_time = trim($stdout);
($cmdret, $stdout, $stderr) = pgsm_psql_cmd('postgres', 'SELECT max(min_plan_time) FROM pg_stat_monitor;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
my $min_plan_time = trim($stdout);
($cmdret, $stdout, $stderr) = pgsm_psql_cmd('postgres', 'SELECT max(max_plan_time) FROM pg_stat_monitor;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
my $max_plan_time = trim($stdout);
($cmdret, $stdout, $stderr) = pgsm_psql_cmd('postgres', 'SELECT max(mean_plan_time) FROM pg_stat_monitor;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
my $mean_plan_time = trim($stdout);
($cmdret, $stdout, $stderr) = pgsm_psql_cmd('postgres', 'SELECT max(stddev_plan_time) FROM pg_stat_monitor;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
my $stddev_plan_time = trim($stdout);
check_value("pgsm_track_planning", $postive, $expected, $total_plan_time + $min_plan_time + $max_plan_time + $stddev_plan_time);
return ($cmdret, $stdout, $stderr);
}
sub do_regression
{
my ($postive, $expected, $set) = @_;
($cmdret, $stdout, $stderr) = pgsm_setup_pg_stat_monitor($set);
($cmdret, $stdout, $stderr) = pgsm_start_pg;
($cmdret, $stdout, $stderr) = pgsm_create_extension;
($cmdret, $stdout, $stderr) = do_testing($postive, $expected);
ok($cmdret == 0, "Checking final result ...");
($cmdret, $stdout, $stderr) = pgsm_drop_extension;
($cmdret, $stdout, $stderr) = pgsm_stop_pg;
}
($cmdret, $stdout, $stderr) = pgsm_init_pg;
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();

View File

@ -1,54 +0,0 @@
#!/usr/bin/perl
use warnings;
use String::Util qw(trim);
use File::Basename;
use File::Compare;
use Test::More;
use lib 't';
use pgsm;
sub check_value
{
my ($var, $postive, $expected, $val) = @_;
trim($val);
if ($postive)
{
is($expected, $val, "Checking $var...");
}
else
{
isnt($expected, $val, "Checking $var...");
}
}
sub do_testing
{
my ($expected, $postive) = @_;
($cmdret, $stdout, $stderr) = pgsm_psql_cmd('postgres', "select * from pg_class;", extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
my ($cmdret, $stdout, $stderr) = pgsm_psql_cmd('postgres', "SELECT case WHEN query_plan LIKE 'Seq Scan on pg_class' THEN 1 ELSE 0 END FROM pg_stat_monitor WHERE query LIKE 'select * from pg_class';", extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
check_value("query_plan", $postive, $expected, $stdout);
return ($cmdret, $stdout, $stderr);
}
sub do_regression
{
my ($postive, $expected, $set) = @_;
($cmdret, $stdout, $stderr) = pgsm_setup_pg_stat_monitor($set);
($cmdret, $stdout, $stderr) = pgsm_start_pg;
($cmdret, $stdout, $stderr) = pgsm_create_extension;
($cmdret, $stdout, $stderr) = do_testing($postive, $expected);
ok($cmdret == 0, "Checking final result ...");
($cmdret, $stdout, $stderr) = pgsm_drop_extension;
($cmdret, $stdout, $stderr) = pgsm_stop_pg;
}
($cmdret, $stdout, $stderr) = pgsm_init_pg;
do_regression(1, 0, "pg_stat_monitor.pgsm_enable_query_plan = 'no'");
do_regression(1, 1, "pg_stat_monitor.pgsm_enable_query_plan = 'yes'");
($cmdret, $stdout, $stderr) = done_testing();

View File

@ -5,69 +5,17 @@ use warnings;
use File::Basename;
use File::Compare;
use File::Copy;
use PostgresNode;
use String::Util qw(trim);
use Test::More;
use lib 't';
use pgsm;
# Expected folder where expected output will be present
my $expected_folder = "t/expected";
# Results/out folder where generated results files will be placed
my $results_folder = "t/results";
# Check if results folder exists or not, create if it doesn't
unless (-d $results_folder)
{
mkdir $results_folder or die "Can't create folder $results_folder: $!\n";;
}
# Check if expected folder exists or not, bail out if it doesn't
unless (-d $expected_folder)
{
BAIL_OUT "Expected files folder $expected_folder doesn't exist: \n";;
}
# Get filename and create out file name and dirs where requried
PGSM::setup_files_dir(basename($0));
# Create new PostgreSQL node and do initdb
my $node = PostgresNode->get_new_node('test');
my $node = PGSM->pgsm_init_pg();
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);
#Remove .pl from filename and store in a variable
my($filename,$extension) = split('.', $perlfilename);
print '$filename';
print '$extension';
$perlfilename =~ s/.pl//;
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
my $out_filename = "${filename_without_extension}.out";
my $out_filename_with_path = "${results_folder}/${out_filename}" ;
# Delete already existing result out file, if it exists.
if ( -f $out_filename_with_path)
{
unlink($out_filename_with_path) or die "Can't delete already existing $out_filename_with_path: $!\n";
}
# Update postgresql.conf to include/load pg_stat_monitor library
open my $conf, '>>', "$pgdata/postgresql.conf";
@ -81,44 +29,42 @@ ok($rt_value == 1, "Start Server");
# 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");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
PGSM::append_to_file($stdout);
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select datname, substr(query,0,100) as query, calls from pg_stat_monitor order by datname, query, calls desc Limit 20;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Select XXX from pg_stat_monitor");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Drop extension
$stdout = $node->safe_psql('postgres', 'Drop extension pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Drop PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Stop the server
$node->stop;
# compare the expected and out file
my $compare = compare($expected_filename_with_path, $out_filename_with_path);
my $compare = PGSM->compare_results();
# Test/check if expected and result/out file match. If Yes, test passes.
is($compare,0,"Compare Files: $expected_filename_with_path and $out_filename_with_path match.");
is($compare,0,"Compare Files: $PGSM::expected_filename_with_path and $PGSM::out_filename_with_path files.");
# Done testing for this testcase file.
done_testing();

View File

@ -2,63 +2,20 @@
use strict;
use warnings;
use String::Util qw(trim);
use File::Basename;
use File::Compare;
use PostgresNode;
use File::Copy;
use String::Util qw(trim);
use Test::More;
use lib 't';
use pgsm;
# Expected folder where expected output will be present
my $expected_folder = "t/expected";
# Results/out folder where generated results files will be placed
my $results_folder = "t/results";
# Check if results folder exists or not, create if it doesn't
unless (-d $results_folder)
{
mkdir $results_folder or die "Can't create folder $results_folder: $!\n";;
}
# Check if expected folder exists or not, bail out if it doesn't
unless (-d $expected_folder)
{
BAIL_OUT "Expected files folder $expected_folder doesn't exist: \n";;
}
# Get filename of the this perl file
my $perlfilename = basename($0);
#Remove .pl from filename and store in a variable
$perlfilename =~ s/\.[^.]+$//;
my $filename_without_extension = $perlfilename;
# Create expected filename with path
my $expected_filename = "${filename_without_extension}.out";
my $expected_filename_with_path = "${expected_folder}/${expected_filename}" ;
# Create results filename with path
my $out_filename = "${filename_without_extension}.out";
my $out_filename_with_path = "${results_folder}/${out_filename}" ;
my $dynamic_out_filename_with_path = "${results_folder}/${out_filename}.dynamic" ;
# Delete already existing result out file, if it exists.
if ( -f $out_filename_with_path)
{
unlink($out_filename_with_path) or die "Can't delete already existing $out_filename_with_path: $!\n";
}
# Get filename and create out file name and dirs where requried
PGSM::setup_files_dir(basename($0));
# Create new PostgreSQL node and do initdb
my $node = PostgresNode->get_new_node('test');
my $node = PGSM->pgsm_init_pg();
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";
@ -73,76 +30,74 @@ ok($rt_value == 1, "Start Server");
# 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");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
PGSM::append_to_file($stdout);
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Run 'SELECT * from pg_stat_monitor_settings;' two times and dump output to out file
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT * from pg_stat_monitor_settings where name = 'pg_stat_monitor.pgsm_track_planning';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT * from pg_stat_monitor_settings where name = 'pg_stat_monitor.pgsm_track_planning';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
SKIP:
{
skip "Server version is 12 or less", 1
if ($major_version <= 12);
if ($PGSM::PG_MAJOR_VERSION <= 12);
($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");
PGSM::append_to_file($stdout);
# 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']);
($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: 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']);
($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: 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']);
($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: 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']);
($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: 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']);
#($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']);
($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']);
#($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']);
#trim($stdout);
#is($stdout,'t',"Test mean_plan_time: (round(mean_plan_time::numeric,3) = round((total_plan_time/2)::numeric,3)).");
# Test: stddev_plan_time = mean_plan_time - min_plan_time
#($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select (round(stddev_plan_time::numeric,3) = round(mean_plan_time::numeric - min_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 (round(stddev_plan_time::numeric,3) = round(mean_plan_time::numeric - min_plan_time::numeric,3)) from pg_stat_monitor where calls = 2;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
#trim($stdout);
#is($stdout,'t',"Compare mean_plan_time: (round(stddev_plan_time::numeric,3) = round(mean_plan_time::numeric - min_plan_time::numeric,3)).");
# 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']);
TestLib::append_to_file($dynamic_out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Disable pgsm_track_planning
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_track_planning = 'no'\n");
@ -151,65 +106,65 @@ $node->restart();
# Dump output to out file
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Run 'SELECT * from pg_stat_monitor_settings;' two times and dump output to out file
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT * from pg_stat_monitor_settings where name = 'pg_stat_monitor.pgsm_track_planning';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT * from pg_stat_monitor_settings where name = 'pg_stat_monitor.pgsm_track_planning';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
SKIP:
{
skip "Server version is 12 or less", 1
if ($major_version <= 12);
if ($PGSM::PG_MAJOR_VERSION <= 12);
($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");
PGSM::append_to_file($stdout);
# 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']);
($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: 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']);
($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: 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']);
($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: 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']);
($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']);
($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']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Dump output to out file
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Drop extension
$stdout = $node->safe_psql('postgres', 'Drop extension pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Drop PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Stop the server
$node->stop;

View File

@ -4,53 +4,18 @@ use strict;
use warnings;
use File::Basename;
use File::Compare;
use PostgresNode;
use File::Copy;
use String::Util qw(trim);
use Test::More;
use lib 't';
use pgsm;
# Expected folder where expected output will be present
my $expected_folder = "t/expected";
# Results/out folder where generated results files will be placed
my $results_folder = "t/results";
# Check if results folder exists or not, create if it doesn't
unless (-d $results_folder)
{
mkdir $results_folder or die "Can't create folder $results_folder: $!\n";;
}
# Check if expected folder exists or not, bail out if it doesn't
unless (-d $expected_folder)
{
BAIL_OUT "Expected files folder $expected_folder doesn't exist: \n";;
}
# Get filename of the this perl file
my $perlfilename = basename($0);
#Remove .pl from filename and store in a variable
$perlfilename =~ s/\.[^.]+$//;
my $filename_without_extension = $perlfilename;
# Create expected filename with path
my $expected_filename = "${filename_without_extension}.out";
my $expected_filename_with_path = "${expected_folder}/${expected_filename}" ;
# Create results filename with path
my $out_filename = "${filename_without_extension}.out";
my $out_filename_with_path = "${results_folder}/${out_filename}" ;
# Delete already existing result out file, if it exists.
if ( -f $out_filename_with_path)
{
unlink($out_filename_with_path) or die "Can't delete already existing $out_filename_with_path: $!\n";
}
# Get filename and create out file name and dirs where requried
PGSM::setup_files_dir(basename($0));
# Create new PostgreSQL node and do initdb
my $node = PostgresNode->get_new_node('test');
my $node = PGSM->pgsm_init_pg();
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";
@ -65,55 +30,53 @@ ok($rt_value == 1, "Start Server");
# 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");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
PGSM::append_to_file($stdout);
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT * from pg_stat_monitor_settings where name = 'pg_stat_monitor.pgsm_extract_comments';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT 1 AS num /* First comment */, 'John' as Name /* Second comment*/;", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT query, comments FROM pg_stat_monitor ORDER BY query COLLATE "C";', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_extract_comments = 'no'\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT * from pg_stat_monitor_settings where name = 'pg_stat_monitor.pgsm_extract_comments';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT 1 AS num /* First comment */, 'John' as Name /* Second comment*/;", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT query, comments FROM pg_stat_monitor ORDER BY query COLLATE "C";', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Drop extension
$stdout = $node->safe_psql('postgres', 'Drop extension pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Drop PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Stop the server
$node->stop;
# compare the expected and out file
my $compare = compare($expected_filename_with_path, $out_filename_with_path);
my $compare = PGSM->compare_results();
# Test/check if expected and result/out file match. If Yes, test passes.
is($compare,0,"Compare Files: $expected_filename_with_path and $out_filename_with_path match.");
is($compare,0,"Compare Files: $PGSM::expected_filename_with_path and $PGSM::out_filename_with_path files.");
# Done testing for this testcase file.
done_testing();

View File

@ -4,53 +4,18 @@ use strict;
use warnings;
use File::Basename;
use File::Compare;
use PostgresNode;
use File::Copy;
use String::Util qw(trim);
use Test::More;
use lib 't';
use pgsm;
# Expected folder where expected output will be present
my $expected_folder = "t/expected";
# Results/out folder where generated results files will be placed
my $results_folder = "t/results";
# Check if results folder exists or not, create if it doesn't
unless (-d $results_folder)
{
mkdir $results_folder or die "Can't create folder $results_folder: $!\n";;
}
# Check if expected folder exists or not, bail out if it doesn't
unless (-d $expected_folder)
{
BAIL_OUT "Expected files folder $expected_folder doesn't exist: \n";;
}
# Get filename of the this perl file
my $perlfilename = basename($0);
#Remove .pl from filename and store in a variable
$perlfilename =~ s/\.[^.]+$//;
my $filename_without_extension = $perlfilename;
# Create expected filename with path
my $expected_filename = "${filename_without_extension}.out";
my $expected_filename_with_path = "${expected_folder}/${expected_filename}" ;
# Create results filename with path
my $out_filename = "${filename_without_extension}.out";
my $out_filename_with_path = "${results_folder}/${out_filename}" ;
# Delete already existing result out file, if it exists.
if ( -f $out_filename_with_path)
{
unlink($out_filename_with_path) or die "Can't delete already existing $out_filename_with_path: $!\n";
}
# Get filename and create out file name and dirs where requried
PGSM::setup_files_dir(basename($0));
# Create new PostgreSQL node and do initdb
my $node = PostgresNode->get_new_node('test');
my $node = PGSM->pgsm_init_pg();
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";
@ -65,54 +30,51 @@ ok($rt_value == 1, "Start Server");
# 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");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
PGSM::append_to_file($stdout);
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT * from pg_stat_monitor_settings where name='pg_stat_monitor.pgsm_track';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_track = 'all'\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT * from pg_stat_monitor_settings where name='pg_stat_monitor.pgsm_track';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_track = 'top'\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT * from pg_stat_monitor_settings where name='pg_stat_monitor.pgsm_track';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Drop extension
$stdout = $node->safe_psql('postgres', 'Drop extension pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Drop PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Stop the server
$node->stop;
# compare the expected and out file
my $compare = compare($expected_filename_with_path, $out_filename_with_path);
my $compare = PGSM->compare_results();
# Test/check if expected and result/out file match. If Yes, test passes.
is($compare,0,"Compare Files: $expected_filename_with_path and $out_filename_with_path match.");
is($compare,0,"Compare Files: $PGSM::expected_filename_with_path and $PGSM::out_filename_with_path files.");
# Done testing for this testcase file.
done_testing();

View File

@ -2,56 +2,20 @@
use strict;
use warnings;
use String::Util qw(trim);
use File::Basename;
use File::Compare;
use PostgresNode;
use File::Copy;
use String::Util qw(trim);
use Test::More;
use lib 't';
use pgsm;
# Expected folder where expected output will be present
my $expected_folder = "t/expected";
# Results/out folder where generated results files will be placed
my $results_folder = "t/results";
# Check if results folder exists or not, create if it doesn't
unless (-d $results_folder)
{
mkdir $results_folder or die "Can't create folder $results_folder: $!\n";;
}
# Check if expected folder exists or not, bail out if it doesn't
unless (-d $expected_folder)
{
BAIL_OUT "Expected files folder $expected_folder doesn't exist: \n";;
}
# Get filename of the this perl file
my $perlfilename = basename($0);
#Remove .pl from filename and store in a variable
$perlfilename =~ s/\.[^.]+$//;
my $filename_without_extension = $perlfilename;
# Create expected filename with path
my $expected_filename = "${filename_without_extension}.out";
my $expected_filename_with_path = "${expected_folder}/${expected_filename}" ;
# Create results filename with path
my $out_filename = "${filename_without_extension}.out";
my $out_filename_with_path = "${results_folder}/${out_filename}" ;
# Delete already existing result out file, if it exists.
if ( -f $out_filename_with_path)
{
unlink($out_filename_with_path) or die "Can't delete already existing $out_filename_with_path: $!\n";
}
# Get filename and create out file name and dirs where requried
PGSM::setup_files_dir(basename($0));
# Create new PostgreSQL node and do initdb
my $node = PostgresNode->get_new_node('test');
my $node = PGSM->pgsm_init_pg();
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";
@ -66,39 +30,37 @@ ok($rt_value == 1, "Start Server");
# 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");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
PGSM::append_to_file($stdout);
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT * from pg_stat_monitor_settings where name='pg_stat_monitor.pgsm_enable_query_plan';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE TABLE TBL_0(key text primary key, txt_0 text, value_0 int);', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "INSERT INTO TBL_0(key, txt_0, value_0) VALUES('000000', '846930886', 1804289383);", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT key, txt_0, value_0 FROM TBL_0;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT key, txt_0, value_0 FROM TBL_0;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'UPDATE TBL_0 SET value_0 = 1681692777;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select substr(query, 0,50) as query, calls, query_plan from pg_stat_monitor order by query,calls;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Test: planid is not 0 or empty
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select planid from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select planid from pg_stat_monitor where calls = 2;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
isnt($stdout,'',"Test: planid should not be empty");
ok(length($stdout) == 16, 'Length of planid is 16');
@ -108,36 +70,36 @@ $node->restart();
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Drop TABLE TBL_0;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT * from pg_stat_monitor_settings where name='pg_stat_monitor.pgsm_enable_query_plan';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE TABLE TBL_0(key text primary key, txt_0 text, value_0 int);', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "INSERT INTO TBL_0(key, txt_0, value_0) VALUES('000000', '846930886', 1804289383);", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT key, txt_0, value_0 FROM TBL_0;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT key, txt_0, value_0 FROM TBL_0;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'UPDATE TBL_0 SET value_0 = 1681692777;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select substr(query, 0,50) as query, calls, query_plan from pg_stat_monitor order by query,calls;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Test: planid is empty
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select planid from pg_stat_monitor where calls = 2 ;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select planid from pg_stat_monitor where calls = 2;', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
trim($stdout);
is($stdout,'',"Test: planid should be empty");
ok(length($stdout) == 0, 'Length of planid is 0');
@ -145,16 +107,16 @@ ok(length($stdout) == 0, 'Length of planid is 0');
# Drop extension
$stdout = $node->safe_psql('postgres', 'Drop extension pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Drop PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Stop the server
$node->stop;
# compare the expected and out file
my $compare = compare($expected_filename_with_path, $out_filename_with_path);
my $compare = PGSM->compare_results();
# Test/check if expected and result/out file match. If Yes, test passes.
is($compare,0,"Compare Files: $expected_filename_with_path and $out_filename_with_path match.");
is($compare,0,"Compare Files: $PGSM::expected_filename_with_path and $PGSM::out_filename_with_path files.");
# Done testing for this testcase file.
done_testing();

View File

@ -4,53 +4,18 @@ use strict;
use warnings;
use File::Basename;
use File::Compare;
use PostgresNode;
use File::Copy;
use String::Util qw(trim);
use Test::More;
use lib 't';
use pgsm;
# Expected folder where expected output will be present
my $expected_folder = "t/expected";
# Results/out folder where generated results files will be placed
my $results_folder = "t/results";
# Check if results folder exists or not, create if it doesn't
unless (-d $results_folder)
{
mkdir $results_folder or die "Can't create folder $results_folder: $!\n";;
}
# Check if expected folder exists or not, bail out if it doesn't
unless (-d $expected_folder)
{
BAIL_OUT "Expected files folder $expected_folder doesn't exist: \n";;
}
# Get filename of the this perl file
my $perlfilename = basename($0);
#Remove .pl from filename and store in a variable
$perlfilename =~ s/\.[^.]+$//;
my $filename_without_extension = $perlfilename;
# Create expected filename with path
my $expected_filename = "${filename_without_extension}.out";
my $expected_filename_with_path = "${expected_folder}/${expected_filename}" ;
# Create results filename with path
my $out_filename = "${filename_without_extension}.out";
my $out_filename_with_path = "${results_folder}/${out_filename}" ;
# Delete already existing result out file, if it exists.
if ( -f $out_filename_with_path)
{
unlink($out_filename_with_path) or die "Can't delete already existing $out_filename_with_path: $!\n";
}
# Get filename and create out file name and dirs where requried
PGSM::setup_files_dir(basename($0));
# Create new PostgreSQL node and do initdb
my $node = PostgresNode->get_new_node('test');
my $node = PGSM->pgsm_init_pg();
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";
@ -65,43 +30,41 @@ ok($rt_value == 1, "Start Server");
# 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");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
PGSM::append_to_file($stdout);
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT * from pg_stat_monitor_settings where name='pg_stat_monitor.pgsm_overflow_target';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_overflow_target = 1\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT * from pg_stat_monitor_settings where name='pg_stat_monitor.pgsm_overflow_target';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Drop extension
$stdout = $node->safe_psql('postgres', 'Drop extension pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Drop PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Stop the server
$node->stop;
# compare the expected and out file
my $compare = compare($expected_filename_with_path, $out_filename_with_path);
my $compare = PGSM->compare_results();
# Test/check if expected and result/out file match. If Yes, test passes.
is($compare,0,"Compare Files: $expected_filename_with_path and $out_filename_with_path match.");
is($compare,0,"Compare Files: $PGSM::expected_filename_with_path and $PGSM::out_filename_with_path files.");
# Done testing for this testcase file.
done_testing();

View File

@ -4,54 +4,19 @@ use strict;
use warnings;
use File::Basename;
use File::Compare;
use PostgresNode;
use File::Copy;
use String::Util qw(trim);
use Test::More;
use lib 't';
use pgsm;
# Expected folder where expected output will be present
my $expected_folder = "t/expected";
# Results/out folder where generated results files will be placed
my $results_folder = "t/results";
# Check if results folder exists or not, create if it doesn't
unless (-d $results_folder)
{
mkdir $results_folder or die "Can't create folder $results_folder: $!\n";;
}
# Check if expected folder exists or not, bail out if it doesn't
unless (-d $expected_folder)
{
BAIL_OUT "Expected files folder $expected_folder doesn't exist: \n";;
}
# Get filename of the this perl file
my $perlfilename = basename($0);
#Remove .pl from filename and store in a variable
$perlfilename =~ s/\.[^.]+$//;
my $filename_without_extension = $perlfilename;
# Create expected filename with path
my $expected_filename = "${filename_without_extension}.out";
my $expected_filename_with_path = "${expected_folder}/${expected_filename}" ;
# Create results filename with path
my $out_filename = "${filename_without_extension}.out";
my $out_filename_with_path = "${results_folder}/${out_filename}" ;
# Delete already existing result out file, if it exists.
if ( -f $out_filename_with_path)
{
unlink($out_filename_with_path) or die "Can't delete already existing $out_filename_with_path: $!\n";
}
# Get filename and create out file name and dirs where requried
PGSM::setup_files_dir(basename($0));
# Create new PostgreSQL node and do initdb
my $node = PostgresNode->get_new_node('test');
my $node = PGSM->pgsm_init_pg();
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";
@ -67,103 +32,100 @@ ok($rt_value == 1, "Start Server");
# 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");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
PGSM::append_to_file($stdout);
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT * from pg_stat_monitor_settings where name='pg_stat_monitor.pgsm_query_shared_buffer';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Create example database and run pgbench init
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE database example;', extra_params => ['-a']);
print "cmdret $cmdret\n";
ok($cmdret == 0, "Create Database example");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
my $port = $node->port;
print "port $port \n";
my $out = system ("pgbench -i -s 100 -p $port example");
print " out: $out \n" ;
print " out: $out \n";
ok($cmdret == 0, "Perform pgbench init");
$out = system ("pgbench -c 10 -j 2 -t 1000 -p $port example");
print " out: $out \n" ;
print " out: $out \n";
ok($cmdret == 0, "Run pgbench");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select datname, substr(query,0,150) as query, calls from pg_stat_monitor order by datname, query, calls desc Limit 20;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
print "cmdret $cmdret\n";
ok($cmdret == 0, "Select XXX from pg_stat_monitor");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_query_shared_buffer = 100\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT * from pg_stat_monitor_settings where name='pg_stat_monitor.pgsm_query_shared_buffer';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
$out = system ("pgbench -i -s 100 -p $port example");
print " out: $out \n" ;
print " out: $out \n";
ok($cmdret == 0, "Perform pgbench init");
$out = system ("pgbench -c 10 -j 2 -t 1000 -p $port example");
print " out: $out \n" ;
print " out: $out \n";
ok($cmdret == 0, "Run pgbench");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select datname, substr(query,0,150) as query, calls from pg_stat_monitor order by datname, query, calls desc Limit 20;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
print "cmdret $cmdret\n";
ok($cmdret == 0, "Select XXX from pg_stat_monitor");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_query_shared_buffer = 20\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT * from pg_stat_monitor_settings where name='pg_stat_monitor.pgsm_query_shared_buffer';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
$out = system ("pgbench -i -s 100 -p $port example");
print " out: $out \n" ;
print " out: $out \n";
ok($cmdret == 0, "Perform pgbench init");
$out = system ("pgbench -c 10 -j 2 -t 1000 -p $port example");
print " out: $out \n" ;
print " out: $out \n";
ok($cmdret == 0, "Run pgbench");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select datname, substr(query,0,150) as query, calls from pg_stat_monitor order by datname, query, calls desc Limit 20;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
print "cmdret $cmdret\n";
ok($cmdret == 0, "Select XXX from pg_stat_monitor");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Drop extension
$stdout = $node->safe_psql('postgres', 'Drop extension pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Drop PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Stop the server
$node->stop;
# compare the expected and out file
my $compare = compare($expected_filename_with_path, $out_filename_with_path);
my $compare = PGSM->compare_results();
# Test/check if expected and result/out file match. If Yes, test passes.
is($compare,0,"Compare Files: $expected_filename_with_path and $out_filename_with_path match.");
is($compare,0,"Compare Files: $PGSM::expected_filename_with_path and $PGSM::out_filename_with_path files.");
# Done testing for this testcase file.
done_testing();

View File

@ -4,53 +4,18 @@ use strict;
use warnings;
use File::Basename;
use File::Compare;
use PostgresNode;
use File::Copy;
use String::Util qw(trim);
use Test::More;
use lib 't';
use pgsm;
# Expected folder where expected output will be present
my $expected_folder = "t/expected";
# Results/out folder where generated results files will be placed
my $results_folder = "t/results";
# Check if results folder exists or not, create if it doesn't
unless (-d $results_folder)
{
mkdir $results_folder or die "Can't create folder $results_folder: $!\n";;
}
# Check if expected folder exists or not, bail out if it doesn't
unless (-d $expected_folder)
{
BAIL_OUT "Expected files folder $expected_folder doesn't exist: \n";;
}
# Get filename of the this perl file
my $perlfilename = basename($0);
#Remove .pl from filename and store in a variable
$perlfilename =~ s/\.[^.]+$//;
my $filename_without_extension = $perlfilename;
# Create expected filename with path
my $expected_filename = "${filename_without_extension}.out";
my $expected_filename_with_path = "${expected_folder}/${expected_filename}" ;
# Create results filename with path
my $out_filename = "${filename_without_extension}.out";
my $out_filename_with_path = "${results_folder}/${out_filename}" ;
# Delete already existing result out file, if it exists.
if ( -f $out_filename_with_path)
{
unlink($out_filename_with_path) or die "Can't delete already existing $out_filename_with_path: $!\n";
}
# Get filename and create out file name and dirs where requried
PGSM::setup_files_dir(basename($0));
# Create new PostgreSQL node and do initdb
my $node = PostgresNode->get_new_node('test');
my $node = PGSM->pgsm_init_pg();
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";
@ -65,88 +30,85 @@ ok($rt_value == 1, "Start Server");
# 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");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
PGSM::append_to_file($stdout);
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT * from pg_stat_monitor_settings where name='pg_stat_monitor.pgsm_histogram_buckets';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_histogram_buckets = 1000\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT * from pg_stat_monitor_settings where name='pg_stat_monitor.pgsm_histogram_buckets';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_histogram_buckets = 100\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT * from pg_stat_monitor_settings where name='pg_stat_monitor.pgsm_histogram_buckets';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_histogram_buckets = 10\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT * from pg_stat_monitor_settings where name='pg_stat_monitor.pgsm_histogram_buckets';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_histogram_buckets = 5\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT * from pg_stat_monitor_settings where name='pg_stat_monitor.pgsm_histogram_buckets';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_histogram_buckets = 1\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT * from pg_stat_monitor_settings where name='pg_stat_monitor.pgsm_histogram_buckets';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Drop extension
$stdout = $node->safe_psql('postgres', 'Drop extension pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Drop PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Stop the server
$node->stop;
# compare the expected and out file
my $compare = compare($expected_filename_with_path, $out_filename_with_path);
my $compare = PGSM->compare_results();
# Test/check if expected and result/out file match. If Yes, test passes.
is($compare,0,"Compare Files: $expected_filename_with_path and $out_filename_with_path match.");
is($compare,0,"Compare Files: $PGSM::expected_filename_with_path and $PGSM::out_filename_with_path files.");
# Done testing for this testcase file.
done_testing();

View File

@ -4,53 +4,18 @@ use strict;
use warnings;
use File::Basename;
use File::Compare;
use PostgresNode;
use File::Copy;
use String::Util qw(trim);
use Test::More;
use lib 't';
use pgsm;
# Expected folder where expected output will be present
my $expected_folder = "t/expected";
# Results/out folder where generated results files will be placed
my $results_folder = "t/results";
# Check if results folder exists or not, create if it doesn't
unless (-d $results_folder)
{
mkdir $results_folder or die "Can't create folder $results_folder: $!\n";;
}
# Check if expected folder exists or not, bail out if it doesn't
unless (-d $expected_folder)
{
BAIL_OUT "Expected files folder $expected_folder doesn't exist: \n";;
}
# Get filename of the this perl file
my $perlfilename = basename($0);
#Remove .pl from filename and store in a variable
$perlfilename =~ s/\.[^.]+$//;
my $filename_without_extension = $perlfilename;
# Create expected filename with path
my $expected_filename = "${filename_without_extension}.out";
my $expected_filename_with_path = "${expected_folder}/${expected_filename}" ;
# Create results filename with path
my $out_filename = "${filename_without_extension}.out";
my $out_filename_with_path = "${results_folder}/${out_filename}" ;
# Delete already existing result out file, if it exists.
if ( -f $out_filename_with_path)
{
unlink($out_filename_with_path) or die "Can't delete already existing $out_filename_with_path: $!\n";
}
# Get filename and create out file name and dirs where requried
PGSM::setup_files_dir(basename($0));
# Create new PostgreSQL node and do initdb
my $node = PostgresNode->get_new_node('test');
my $node = PGSM->pgsm_init_pg();
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";
@ -65,66 +30,63 @@ ok($rt_value == 1, "Start Server");
# 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");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
PGSM::append_to_file($stdout);
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT * from pg_stat_monitor_settings where name='pg_stat_monitor.pgsm_histogram_max';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_histogram_max = 10\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT * from pg_stat_monitor_settings where name='pg_stat_monitor.pgsm_histogram_max';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_histogram_max = 100\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT * from pg_stat_monitor_settings where name='pg_stat_monitor.pgsm_histogram_max';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_histogram_max = 1000\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT * from pg_stat_monitor_settings where name='pg_stat_monitor.pgsm_histogram_max';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Drop extension
$stdout = $node->safe_psql('postgres', 'Drop extension pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Drop PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Stop the server
$node->stop;
# compare the expected and out file
my $compare = compare($expected_filename_with_path, $out_filename_with_path);
my $compare = PGSM->compare_results();
# Test/check if expected and result/out file match. If Yes, test passes.
is($compare,0,"Compare Files: $expected_filename_with_path and $out_filename_with_path match.");
is($compare,0,"Compare Files: $PGSM::expected_filename_with_path and $PGSM::out_filename_with_path files.");
# Done testing for this testcase file.
done_testing();

View File

@ -4,53 +4,18 @@ use strict;
use warnings;
use File::Basename;
use File::Compare;
use PostgresNode;
use File::Copy;
use String::Util qw(trim);
use Test::More;
use lib 't';
use pgsm;
# Expected folder where expected output will be present
my $expected_folder = "t/expected";
# Results/out folder where generated results files will be placed
my $results_folder = "t/results";
# Check if results folder exists or not, create if it doesn't
unless (-d $results_folder)
{
mkdir $results_folder or die "Can't create folder $results_folder: $!\n";;
}
# Check if expected folder exists or not, bail out if it doesn't
unless (-d $expected_folder)
{
BAIL_OUT "Expected files folder $expected_folder doesn't exist: \n";;
}
# Get filename of the this perl file
my $perlfilename = basename($0);
#Remove .pl from filename and store in a variable
$perlfilename =~ s/\.[^.]+$//;
my $filename_without_extension = $perlfilename;
# Create expected filename with path
my $expected_filename = "${filename_without_extension}.out";
my $expected_filename_with_path = "${expected_folder}/${expected_filename}" ;
# Create results filename with path
my $out_filename = "${filename_without_extension}.out";
my $out_filename_with_path = "${results_folder}/${out_filename}" ;
# Delete already existing result out file, if it exists.
if ( -f $out_filename_with_path)
{
unlink($out_filename_with_path) or die "Can't delete already existing $out_filename_with_path: $!\n";
}
# Get filename and create out file name and dirs where requried
PGSM::setup_files_dir(basename($0));
# Create new PostgreSQL node and do initdb
my $node = PostgresNode->get_new_node('test');
my $node = PGSM->pgsm_init_pg();
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";
@ -65,65 +30,63 @@ ok($rt_value == 1, "Start Server");
# 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");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
PGSM::append_to_file($stdout);
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT * from pg_stat_monitor_settings where name='pg_stat_monitor.pgsm_histogram_min';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_histogram_min = 1000\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT * from pg_stat_monitor_settings where name='pg_stat_monitor.pgsm_histogram_min';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_histogram_min = 10000\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT * from pg_stat_monitor_settings where name='pg_stat_monitor.pgsm_histogram_min';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_histogram_min = 99999\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT * from pg_stat_monitor_settings where name='pg_stat_monitor.pgsm_histogram_min';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Drop extension
$stdout = $node->safe_psql('postgres', 'Drop extension pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Drop PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Stop the server
$node->stop;
# compare the expected and out file
my $compare = compare($expected_filename_with_path, $out_filename_with_path);
my $compare = PGSM->compare_results();
# Test/check if expected and result/out file match. If Yes, test passes.
is($compare,0,"Compare Files: $expected_filename_with_path and $out_filename_with_path match.");
is($compare,0,"Compare Files: $PGSM::expected_filename_with_path and $PGSM::out_filename_with_path files.");
# Done testing for this testcase file.
done_testing();

View File

@ -4,53 +4,18 @@ use strict;
use warnings;
use File::Basename;
use File::Compare;
use PostgresNode;
use File::Copy;
use String::Util qw(trim);
use Test::More;
use lib 't';
use pgsm;
# Expected folder where expected output will be present
my $expected_folder = "t/expected";
# Results/out folder where generated results files will be placed
my $results_folder = "t/results";
# Check if results folder exists or not, create if it doesn't
unless (-d $results_folder)
{
mkdir $results_folder or die "Can't create folder $results_folder: $!\n";;
}
# Check if expected folder exists or not, bail out if it doesn't
unless (-d $expected_folder)
{
BAIL_OUT "Expected files folder $expected_folder doesn't exist: \n";;
}
# Get filename of the this perl file
my $perlfilename = basename($0);
#Remove .pl from filename and store in a variable
$perlfilename =~ s/\.[^.]+$//;
my $filename_without_extension = $perlfilename;
# Create expected filename with path
my $expected_filename = "${filename_without_extension}.out";
my $expected_filename_with_path = "${expected_folder}/${expected_filename}" ;
# Create results filename with path
my $out_filename = "${filename_without_extension}.out";
my $out_filename_with_path = "${results_folder}/${out_filename}" ;
# Delete already existing result out file, if it exists.
if ( -f $out_filename_with_path)
{
unlink($out_filename_with_path) or die "Can't delete already existing $out_filename_with_path: $!\n";
}
# Get filename and create out file name and dirs where requried
PGSM::setup_files_dir(basename($0));
# Create new PostgreSQL node and do initdb
my $node = PostgresNode->get_new_node('test');
my $node = PGSM->pgsm_init_pg();
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";
@ -65,88 +30,85 @@ ok($rt_value == 1, "Start Server");
# 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");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
PGSM::append_to_file($stdout);
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT * from pg_stat_monitor_settings where name='pg_stat_monitor.pgsm_bucket_time';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_bucket_time = 1000\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT * from pg_stat_monitor_settings where name='pg_stat_monitor.pgsm_bucket_time';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_bucket_time = 100\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT * from pg_stat_monitor_settings where name='pg_stat_monitor.pgsm_bucket_time';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_bucket_time = 60\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT * from pg_stat_monitor_settings where name='pg_stat_monitor.pgsm_bucket_time';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_bucket_time = 1\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT * from pg_stat_monitor_settings where name='pg_stat_monitor.pgsm_bucket_time';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_bucket_time = 0\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT * from pg_stat_monitor_settings where name='pg_stat_monitor.pgsm_bucket_time';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Drop extension
$stdout = $node->safe_psql('postgres', 'Drop extension pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Drop PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Stop the server
$node->stop;
# compare the expected and out file
my $compare = compare($expected_filename_with_path, $out_filename_with_path);
my $compare = PGSM->compare_results();
# Test/check if expected and result/out file match. If Yes, test passes.
is($compare,0,"Compare Files: $expected_filename_with_path and $out_filename_with_path match.");
is($compare,0,"Compare Files: $PGSM::expected_filename_with_path and $PGSM::out_filename_with_path files.");
# Done testing for this testcase file.
done_testing();

View File

@ -4,53 +4,18 @@ use strict;
use warnings;
use File::Basename;
use File::Compare;
use PostgresNode;
use File::Copy;
use String::Util qw(trim);
use Test::More;
use lib 't';
use pgsm;
# Expected folder where expected output will be present
my $expected_folder = "t/expected";
# Results/out folder where generated results files will be placed
my $results_folder = "t/results";
# Check if results folder exists or not, create if it doesn't
unless (-d $results_folder)
{
mkdir $results_folder or die "Can't create folder $results_folder: $!\n";;
}
# Check if expected folder exists or not, bail out if it doesn't
unless (-d $expected_folder)
{
BAIL_OUT "Expected files folder $expected_folder doesn't exist: \n";;
}
# Get filename of the this perl file
my $perlfilename = basename($0);
#Remove .pl from filename and store in a variable
$perlfilename =~ s/\.[^.]+$//;
my $filename_without_extension = $perlfilename;
# Create expected filename with path
my $expected_filename = "${filename_without_extension}.out";
my $expected_filename_with_path = "${expected_folder}/${expected_filename}" ;
# Create results filename with path
my $out_filename = "${filename_without_extension}.out";
my $out_filename_with_path = "${results_folder}/${out_filename}" ;
# Delete already existing result out file, if it exists.
if ( -f $out_filename_with_path)
{
unlink($out_filename_with_path) or die "Can't delete already existing $out_filename_with_path: $!\n";
}
# Get filename and create out file name and dirs where requried
PGSM::setup_files_dir(basename($0));
# Create new PostgreSQL node and do initdb
my $node = PostgresNode->get_new_node('test');
my $node = PGSM->pgsm_init_pg();
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";
@ -65,88 +30,85 @@ ok($rt_value == 1, "Start Server");
# 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");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
PGSM::append_to_file($stdout);
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT * from pg_stat_monitor_settings where name='pg_stat_monitor.pgsm_max_buckets';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_max_buckets = 2\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT * from pg_stat_monitor_settings where name='pg_stat_monitor.pgsm_max_buckets';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_max_buckets = 5\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT * from pg_stat_monitor_settings where name='pg_stat_monitor.pgsm_max_buckets';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_max_buckets = 10\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT * from pg_stat_monitor_settings where name='pg_stat_monitor.pgsm_max_buckets';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_max_buckets = 11\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT * from pg_stat_monitor_settings where name='pg_stat_monitor.pgsm_max_buckets';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_max_buckets = 0\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT * from pg_stat_monitor_settings where name='pg_stat_monitor.pgsm_max_buckets';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Drop extension
$stdout = $node->safe_psql('postgres', 'Drop extension pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Drop PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Stop the server
$node->stop;
# compare the expected and out file
my $compare = compare($expected_filename_with_path, $out_filename_with_path);
my $compare = PGSM->compare_results();
# Test/check if expected and result/out file match. If Yes, test passes.
is($compare,0,"Compare Files: $expected_filename_with_path and $out_filename_with_path match.");
is($compare,0,"Compare Files: $PGSM::expected_filename_with_path and $PGSM::out_filename_with_path files.");
# Done testing for this testcase file.
done_testing();

View File

@ -4,59 +4,18 @@ use strict;
use warnings;
use File::Basename;
use File::Compare;
use PostgresNode;
use File::Copy;
use String::Util qw(trim);
use Test::More;
use lib 't';
use pgsm;
# Expected folder where expected output will be present
my $expected_folder = "t/expected";
# Results/out folder where generated results files will be placed
my $results_folder = "t/results";
# Check if results folder exists or not, create if it doesn't
unless (-d $results_folder)
{
mkdir $results_folder or die "Can't create folder $results_folder: $!\n";;
}
# Check if expected folder exists or not, bail out if it doesn't
unless (-d $expected_folder)
{
BAIL_OUT "Expected files folder $expected_folder doesn't exist: \n";;
}
# Get filename of the this perl file
my $perlfilename = basename($0);
#Remove .pl from filename and store in a variable
$perlfilename =~ s/\.[^.]+$//;
my $filename_without_extension = $perlfilename;
# Create expected filename with path
my $expected_filename = "${filename_without_extension}.out";
my $expected_filename_with_path = "${expected_folder}/${expected_filename}" ;
# Create results filename with path
my $out_filename = "${filename_without_extension}.out";
my $out_filename_with_path = "${results_folder}/${out_filename}" ;
# Delete already existing result out file, if it exists.
if ( -f $out_filename_with_path)
{
unlink($out_filename_with_path) or die "Can't delete already existing $out_filename_with_path: $!\n";
}
# Get filename and create out file name and dirs where requried
PGSM::setup_files_dir(basename($0));
# Create new PostgreSQL node and do initdb
my $node = PostgresNode->get_new_node('test');
my $node = PGSM->pgsm_init_pg();
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";
@ -71,85 +30,83 @@ ok($rt_value == 1, "Start Server");
# 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");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
PGSM::append_to_file($stdout);
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT * from pg_stat_monitor_settings where name='pg_stat_monitor.pgsm_normalized_query';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE TABLE TBL_0(key text primary key, txt_0 text, value_0 int);', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "INSERT INTO TBL_0(key, txt_0, value_0) VALUES('000000', '846930886', 1804289383);", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT key, txt_0, value_0 FROM TBL_0;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT key, txt_0, value_0 FROM TBL_0;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'UPDATE TBL_0 SET value_0 = 1681692777;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select datname, substr(query,0,100) as query, calls from pg_stat_monitor order by datname, query, calls desc Limit 20;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Select XXX from pg_stat_monitor");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_normalized_query = 'yes'\n");
$node->restart();
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Drop TABLE TBL_0;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT * from pg_stat_monitor_settings where name='pg_stat_monitor.pgsm_normalized_query';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE TABLE TBL_0(key text primary key, txt_0 text, value_0 int);', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "INSERT INTO TBL_0(key, txt_0, value_0) VALUES('000000', '846930886', 1804289383);", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT key, txt_0, value_0 FROM TBL_0;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT key, txt_0, value_0 FROM TBL_0;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'UPDATE TBL_0 SET value_0 = 1681692777;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select datname, substr(query,0,100) as query, calls from pg_stat_monitor order by datname, query, calls desc Limit 20;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Select XXX from pg_stat_monitor");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Drop extension
$stdout = $node->safe_psql('postgres', 'Drop extension pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Drop PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Stop the server
$node->stop;
# compare the expected and out file
my $compare = compare($expected_filename_with_path, $out_filename_with_path);
my $compare = PGSM->compare_results();
# Test/check if expected and result/out file match. If Yes, test passes.
is($compare,0,"Compare Files: $expected_filename_with_path and $out_filename_with_path match.");
is($compare,0,"Compare Files: $PGSM::expected_filename_with_path and $PGSM::out_filename_with_path files.");
# Done testing for this testcase file.
done_testing();

View File

@ -4,53 +4,18 @@ use strict;
use warnings;
use File::Basename;
use File::Compare;
use PostgresNode;
use File::Copy;
use String::Util qw(trim);
use Test::More;
use lib 't';
use pgsm;
# Expected folder where expected output will be present
my $expected_folder = "t/expected";
# Results/out folder where generated results files will be placed
my $results_folder = "t/results";
# Check if results folder exists or not, create if it doesn't
unless (-d $results_folder)
{
mkdir $results_folder or die "Can't create folder $results_folder: $!\n";;
}
# Check if expected folder exists or not, bail out if it doesn't
unless (-d $expected_folder)
{
BAIL_OUT "Expected files folder $expected_folder doesn't exist: \n";;
}
# Get filename of the this perl file
my $perlfilename = basename($0);
#Remove .pl from filename and store in a variable
$perlfilename =~ s/\.[^.]+$//;
my $filename_without_extension = $perlfilename;
# Create expected filename with path
my $expected_filename = "${filename_without_extension}.out";
my $expected_filename_with_path = "${expected_folder}/${expected_filename}" ;
# Create results filename with path
my $out_filename = "${filename_without_extension}.out";
my $out_filename_with_path = "${results_folder}/${out_filename}" ;
# Delete already existing result out file, if it exists.
if ( -f $out_filename_with_path)
{
unlink($out_filename_with_path) or die "Can't delete already existing $out_filename_with_path: $!\n";
}
# Get filename and create out file name and dirs where requried
PGSM::setup_files_dir(basename($0));
# Create new PostgreSQL node and do initdb
my $node = PostgresNode->get_new_node('test');
my $node = PGSM->pgsm_init_pg();
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";
@ -65,94 +30,91 @@ ok($rt_value == 1, "Start Server");
# 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");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
PGSM::append_to_file($stdout);
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT * from pg_stat_monitor_settings where name='pg_stat_monitor.pgsm_track_utility';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE TABLE TBL_0(key text primary key, txt_0 text, value_0 int);', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "INSERT INTO TBL_0(key, txt_0, value_0) VALUES('000000', '846930886', 1804289383);", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT key, txt_0, value_0 FROM TBL_0;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT key, txt_0, value_0 FROM TBL_0;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'UPDATE TBL_0 SET value_0 = 1681692777;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Analyze TBL_0;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'DROP TABLE TBL_0;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select datname, substr(query,0,100) as query, calls from pg_stat_monitor order by datname, query, calls desc Limit 20;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Select XXX from pg_stat_monitor");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_track_utility = 'yes'\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT * from pg_stat_monitor_settings where name='pg_stat_monitor.pgsm_track_utility';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE TABLE TBL_0(key text primary key, txt_0 text, value_0 int);', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "INSERT INTO TBL_0(key, txt_0, value_0) VALUES('000000', '846930886', 1804289383);", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT key, txt_0, value_0 FROM TBL_0;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT key, txt_0, value_0 FROM TBL_0;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'UPDATE TBL_0 SET value_0 = 1681692777;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Analyze TBL_0;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'DROP TABLE TBL_0;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select datname, substr(query,0,100) as query, calls from pg_stat_monitor order by datname, query, calls desc Limit 20;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Select XXX from pg_stat_monitor");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Drop extension
$stdout = $node->safe_psql('postgres', 'Drop extension pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Drop PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Stop the server
$node->stop;
# compare the expected and out file
my $compare = compare($expected_filename_with_path, $out_filename_with_path);
my $compare = PGSM->compare_results();
# Test/check if expected and result/out file match. If Yes, test passes.
is($compare,0,"Compare Files: $expected_filename_with_path and $out_filename_with_path match.");
is($compare,0,"Compare Files: $PGSM::expected_filename_with_path and $PGSM::out_filename_with_path files.");
# Done testing for this testcase file.
done_testing();

View File

@ -4,53 +4,18 @@ use strict;
use warnings;
use File::Basename;
use File::Compare;
use PostgresNode;
use File::Copy;
use String::Util qw(trim);
use Test::More;
use lib 't';
use pgsm;
# Expected folder where expected output will be present
my $expected_folder = "t/expected";
# Results/out folder where generated results files will be placed
my $results_folder = "t/results";
# Check if results folder exists or not, create if it doesn't
unless (-d $results_folder)
{
mkdir $results_folder or die "Can't create folder $results_folder: $!\n";;
}
# Check if expected folder exists or not, bail out if it doesn't
unless (-d $expected_folder)
{
BAIL_OUT "Expected files folder $expected_folder doesn't exist: \n";;
}
# Get filename of the this perl file
my $perlfilename = basename($0);
#Remove .pl from filename and store in a variable
$perlfilename =~ s/\.[^.]+$//;
my $filename_without_extension = $perlfilename;
# Create expected filename with path
my $expected_filename = "${filename_without_extension}.out";
my $expected_filename_with_path = "${expected_folder}/${expected_filename}" ;
# Create results filename with path
my $out_filename = "${filename_without_extension}.out";
my $out_filename_with_path = "${results_folder}/${out_filename}" ;
# Delete already existing result out file, if it exists.
if ( -f $out_filename_with_path)
{
unlink($out_filename_with_path) or die "Can't delete already existing $out_filename_with_path: $!\n";
}
# Get filename and create out file name and dirs where requried
PGSM::setup_files_dir(basename($0));
# Create new PostgreSQL node and do initdb
my $node = PostgresNode->get_new_node('test');
my $node = PGSM->pgsm_init_pg();
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";
@ -65,77 +30,74 @@ ok($rt_value == 1, "Start Server");
# 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");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
PGSM::append_to_file($stdout);
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT * from pg_stat_monitor_settings where name='pg_stat_monitor.pgsm_query_max_len';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_query_max_len = 1024\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT * from pg_stat_monitor_settings where name='pg_stat_monitor.pgsm_query_max_len';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_query_max_len = 100\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT * from pg_stat_monitor_settings where name='pg_stat_monitor.pgsm_query_max_len';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_query_max_len = 10\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT * from pg_stat_monitor_settings where name='pg_stat_monitor.pgsm_query_max_len';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_query_max_len = 0\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT * from pg_stat_monitor_settings where name='pg_stat_monitor.pgsm_query_max_len';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Drop extension
$stdout = $node->safe_psql('postgres', 'Drop extension pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Drop PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Stop the server
$node->stop;
# compare the expected and out file
my $compare = compare($expected_filename_with_path, $out_filename_with_path);
my $compare = PGSM->compare_results();
# Test/check if expected and result/out file match. If Yes, test passes.
is($compare,0,"Compare Files: $expected_filename_with_path and $out_filename_with_path match.");
is($compare,0,"Compare Files: $PGSM::expected_filename_with_path and $PGSM::out_filename_with_path files.");
# Done testing for this testcase file.
done_testing();

View File

@ -4,53 +4,18 @@ use strict;
use warnings;
use File::Basename;
use File::Compare;
use PostgresNode;
use File::Copy;
use String::Util qw(trim);
use Test::More;
use lib 't';
use pgsm;
# Expected folder where expected output will be present
my $expected_folder = "t/expected";
# Results/out folder where generated results files will be placed
my $results_folder = "t/results";
# Check if results folder exists or not, create if it doesn't
unless (-d $results_folder)
{
mkdir $results_folder or die "Can't create folder $results_folder: $!\n";;
}
# Check if expected folder exists or not, bail out if it doesn't
unless (-d $expected_folder)
{
BAIL_OUT "Expected files folder $expected_folder doesn't exist: \n";;
}
# Get filename of the this perl file
my $perlfilename = basename($0);
#Remove .pl from filename and store in a variable
$perlfilename =~ s/\.[^.]+$//;
my $filename_without_extension = $perlfilename;
# Create expected filename with path
my $expected_filename = "${filename_without_extension}.out";
my $expected_filename_with_path = "${expected_folder}/${expected_filename}" ;
# Create results filename with path
my $out_filename = "${filename_without_extension}.out";
my $out_filename_with_path = "${results_folder}/${out_filename}" ;
# Delete already existing result out file, if it exists.
if ( -f $out_filename_with_path)
{
unlink($out_filename_with_path) or die "Can't delete already existing $out_filename_with_path: $!\n";
}
# Get filename and create out file name and dirs where requried
PGSM::setup_files_dir(basename($0));
# Create new PostgreSQL node and do initdb
my $node = PostgresNode->get_new_node('test');
my $node = PGSM->pgsm_init_pg();
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";
@ -65,77 +30,74 @@ ok($rt_value == 1, "Start Server");
# 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");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
PGSM::append_to_file($stdout);
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT * from pg_stat_monitor_settings where name='pg_stat_monitor.pgsm_max';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_max = 500\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT * from pg_stat_monitor_settings where name='pg_stat_monitor.pgsm_max';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_max = 100\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT * from pg_stat_monitor_settings where name='pg_stat_monitor.pgsm_max';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_max = 10\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT * from pg_stat_monitor_settings where name='pg_stat_monitor.pgsm_max';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_max = 0\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT * from pg_stat_monitor_settings where name='pg_stat_monitor.pgsm_max';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Drop extension
$stdout = $node->safe_psql('postgres', 'Drop extension pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Drop PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Stop the server
$node->stop;
# compare the expected and out file
my $compare = compare($expected_filename_with_path, $out_filename_with_path);
my $compare = PGSM->compare_results();
# Test/check if expected and result/out file match. If Yes, test passes.
is($compare,0,"Compare Files: $expected_filename_with_path and $out_filename_with_path match.");
is($compare,0,"Compare Files: $PGSM::expected_filename_with_path and $PGSM::out_filename_with_path files.");
# Done testing for this testcase file.
done_testing();

View File

@ -2,63 +2,20 @@
use strict;
use warnings;
use String::Util qw(trim);
use File::Basename;
use File::Compare;
use PostgresNode;
use File::Copy;
use String::Util qw(trim);
use Test::More;
use lib 't';
use pgsm;
# Expected folder where expected output will be present
my $expected_folder = "t/expected";
# Results/out folder where generated results files will be placed
my $results_folder = "t/results";
# Check if results folder exists or not, create if it doesn't
unless (-d $results_folder)
{
mkdir $results_folder or die "Can't create folder $results_folder: $!\n";;
}
# Check if expected folder exists or not, bail out if it doesn't
unless (-d $expected_folder)
{
BAIL_OUT "Expected files folder $expected_folder doesn't exist: \n";;
}
# Get filename of the this perl file
my $perlfilename = basename($0);
#Remove .pl from filename and store in a variable
$perlfilename =~ s/\.[^.]+$//;
my $filename_without_extension = $perlfilename;
# Get filename and create out file name and dirs where requried
PGSM::setup_files_dir(basename($0));
# Create new PostgreSQL node and do initdb
my $node = PostgresNode->get_new_node('test');
my $node = PGSM->pgsm_init_pg();
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}" ;
# Create results filename with path
my $out_filename = "${filename_without_extension}.out";
my $out_filename_with_path = "${results_folder}/${out_filename}" ;
my $dynamic_out_filename_with_path = "${results_folder}/${out_filename}.dynamic" ;
# Delete already existing result out file, if it exists.
if ( -f $out_filename_with_path)
{
unlink($out_filename_with_path) or die "Can't delete already existing $out_filename_with_path: $!\n";
}
# Update postgresql.conf to include/load pg_stat_monitor library
open my $conf, '>>', "$pgdata/postgresql.conf";
@ -75,7 +32,7 @@ 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)
if ($PGSM::PG_MAJOR_VERSION <= 12)
{
$col_total_time = "total_time";
$col_min_time = "min_time";
@ -87,81 +44,79 @@ if ($major_version <= 12)
# 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");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
PGSM::append_to_file($stdout);
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Run 'SELECT * from pg_stat_monitor_settings;' two times and dump output to out file
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($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");
PGSM::append_to_file($stdout);
# 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']);
($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: ${col_total_time} is not 0).");
# 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']);
($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: ${col_min_time} is not 0).");
# 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']);
($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: ${col_max_time} is not 0).");
# 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']);
($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: ${col_mean_time} is not 0).");
# 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']);
#($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: ${col_stddev_time} should not be 0).");
# 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']);
($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(${col_total_time}::numeric,3) = round(${col_min_time}::numeric + ${col_max_time}::numeric,3)).");
# 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']);
#($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 ${col_mean_time}: (round(${col_mean_time}::numeric,3) = round((${col_total_time}/2)::numeric,3)).");
# 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']);
#($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 ${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, ${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");
PGSM::append_to_debug_file($stdout);
# Dump output to out file
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Drop extension
$stdout = $node->safe_psql('postgres', 'Drop extension pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Drop PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Stop the server
$node->stop;

View File

@ -2,56 +2,20 @@
use strict;
use warnings;
use String::Util qw(trim);
use File::Basename;
use File::Compare;
use PostgresNode;
use File::Copy;
use String::Util qw(trim);
use Test::More;
use lib 't';
use pgsm;
# Expected folder where expected output will be present
my $expected_folder = "t/expected";
# Results/out folder where generated results files will be placed
my $results_folder = "t/results";
# Check if results folder exists or not, create if it doesn't
unless (-d $results_folder)
{
mkdir $results_folder or die "Can't create folder $results_folder: $!\n";;
}
# Check if expected folder exists or not, bail out if it doesn't
unless (-d $expected_folder)
{
BAIL_OUT "Expected files folder $expected_folder doesn't exist: \n";;
}
# Get filename of the this perl file
my $perlfilename = basename($0);
#Remove .pl from filename and store in a variable
$perlfilename =~ s/\.[^.]+$//;
my $filename_without_extension = $perlfilename;
# Create expected filename with path
my $expected_filename = "${filename_without_extension}.out";
my $expected_filename_with_path = "${expected_folder}/${expected_filename}" ;
# Create results filename with path
my $out_filename = "${filename_without_extension}.out";
my $out_filename_with_path = "${results_folder}/${out_filename}" ;
# Delete already existing result out file, if it exists.
if ( -f $out_filename_with_path)
{
unlink($out_filename_with_path) or die "Can't delete already existing $out_filename_with_path: $!\n";
}
# Get filename and create out file name and dirs where requried
PGSM::setup_files_dir(basename($0));
# Create new PostgreSQL node and do initdb
my $node = PostgresNode->get_new_node('test');
my $node = PGSM->pgsm_init_pg();
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";
@ -68,63 +32,60 @@ ok($rt_value == 1, "Start Server");
# 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");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
PGSM::append_to_file($stdout);
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'create table foo (id int generated by default as identity,col1 varchar(100) not null,primary key(id));', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Create Table foo");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT * from pg_stat_monitor_settings where name='pg_stat_monitor.pgsm_overflow_target';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', '\i scripts/data_1.sql' , extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Run sql file: scripts/data.sql");
#TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
#PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT substr(query, 0, 50), length(query), bucket, queryid, calls, elevel, sqlcode, message from pg_stat_monitor;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "SELECT substr(query, 0, 50), calls, message from pg_stat_monitor");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT count(queryid) from pg_stat_monitor;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "SELECT count(queryid) from pg_stat_monitor");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_overflow_target = 1\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', "SELECT * from pg_stat_monitor_settings where name='pg_stat_monitor.pgsm_overflow_target';", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', '\i scripts/data_2.sql' , extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Run sql file: scripts/data2.sql");
#TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
#PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT substr(query, 0, 50), length(query), bucket, queryid, calls, elevel, sqlcode, message from pg_stat_monitor;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "SELECT substr(query, 0, 50), calls, message from pg_stat_monitor");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT count(queryid) from pg_stat_monitor;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "SELECT count(queryid) from pg_stat_monitor");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Drop extension
$stdout = $node->safe_psql('postgres', 'Drop extension pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Drop PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Stop the server
$node->stop;

View File

@ -2,56 +2,20 @@
use strict;
use warnings;
use String::Util qw(trim);
use File::Basename;
use File::Compare;
use PostgresNode;
use File::Copy;
use String::Util qw(trim);
use Test::More;
use lib 't';
use pgsm;
# Expected folder where expected output will be present
my $expected_folder = "t/expected";
# Results/out folder where generated results files will be placed
my $results_folder = "t/results";
# Check if results folder exists or not, create if it doesn't
unless (-d $results_folder)
{
mkdir $results_folder or die "Can't create folder $results_folder: $!\n";;
}
# Check if expected folder exists or not, bail out if it doesn't
unless (-d $expected_folder)
{
BAIL_OUT "Expected files folder $expected_folder doesn't exist: \n";;
}
# Get filename of the this perl file
my $perlfilename = basename($0);
#Remove .pl from filename and store in a variable
$perlfilename =~ s/\.[^.]+$//;
my $filename_without_extension = $perlfilename;
# Create expected filename with path
my $expected_filename = "${filename_without_extension}.out";
my $expected_filename_with_path = "${expected_folder}/${expected_filename}" ;
# Create results filename with path
my $out_filename = "${filename_without_extension}.out";
my $out_filename_with_path = "${results_folder}/${out_filename}" ;
# Delete already existing result out file, if it exists.
if ( -f $out_filename_with_path)
{
unlink($out_filename_with_path) or die "Can't delete already existing $out_filename_with_path: $!\n";
}
# Get filename and create out file name and dirs where requried
PGSM::setup_files_dir(basename($0));
# Create new PostgreSQL node and do initdb
my $node = PostgresNode->get_new_node('test');
my $node = PGSM->pgsm_init_pg();
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";
@ -70,63 +34,61 @@ ok($rt_value == 1, "Start Server");
# 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");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
PGSM::append_to_file($stdout);
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'create table foo (id int generated by default as identity,col1 varchar(100) not null,primary key(id));', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Create Table foo");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', '\i scripts/data_1.sql' , extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Run sql file: scripts/data.sql");
#TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
#PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT substr(query, 0, 50), length(query), bucket, queryid, calls, elevel, sqlcode, message from pg_stat_monitor;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "SELECT substr(query, 0, 50), calls, message from pg_stat_monitor");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT count(queryid) from pg_stat_monitor;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "SELECT count(queryid) from pg_stat_monitor");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_overflow_target = 1\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', '\i scripts/data_2.sql' , extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Run sql file: scripts/data2.sql");
#TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
#PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT substr(query, 0, 50), length(query), bucket, queryid, calls, elevel, sqlcode, message from pg_stat_monitor;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "SELECT substr(query, 0, 50), calls, message from pg_stat_monitor");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT count(queryid) from pg_stat_monitor;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "SELECT count(queryid) from pg_stat_monitor");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Drop extension
$stdout = $node->safe_psql('postgres', 'Drop extension pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Drop PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Stop the server
$node->stop;

View File

@ -2,56 +2,20 @@
use strict;
use warnings;
use String::Util qw(trim);
use File::Basename;
use File::Compare;
use PostgresNode;
use File::Copy;
use String::Util qw(trim);
use Test::More;
use lib 't';
use pgsm;
# Expected folder where expected output will be present
my $expected_folder = "t/expected";
# Results/out folder where generated results files will be placed
my $results_folder = "t/results";
# Check if results folder exists or not, create if it doesn't
unless (-d $results_folder)
{
mkdir $results_folder or die "Can't create folder $results_folder: $!\n";;
}
# Check if expected folder exists or not, bail out if it doesn't
unless (-d $expected_folder)
{
BAIL_OUT "Expected files folder $expected_folder doesn't exist: \n";;
}
# Get filename of the this perl file
my $perlfilename = basename($0);
#Remove .pl from filename and store in a variable
$perlfilename =~ s/\.[^.]+$//;
my $filename_without_extension = $perlfilename;
# Create expected filename with path
my $expected_filename = "${filename_without_extension}.out";
my $expected_filename_with_path = "${expected_folder}/${expected_filename}" ;
# Create results filename with path
my $out_filename = "${filename_without_extension}.out";
my $out_filename_with_path = "${results_folder}/${out_filename}" ;
# Delete already existing result out file, if it exists.
if ( -f $out_filename_with_path)
{
unlink($out_filename_with_path) or die "Can't delete already existing $out_filename_with_path: $!\n";
}
# Get filename and create out file name and dirs where requried
PGSM::setup_files_dir(basename($0));
# Create new PostgreSQL node and do initdb
my $node = PostgresNode->get_new_node('test');
my $node = PGSM->pgsm_init_pg();
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";
@ -73,63 +37,61 @@ ok($rt_value == 1, "Start Server");
# 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");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
PGSM::append_to_file($stdout);
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'create table foo (id int generated by default as identity,col1 varchar(100) not null,primary key(id));', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Create Table foo");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', '\i scripts/data_1.sql' , extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Run sql file: scripts/data.sql");
#TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
#PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT substr(query, 0, 50), length(query), bucket, queryid, calls, elevel, sqlcode, message from pg_stat_monitor;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "SELECT substr(query, 0, 50), calls, message from pg_stat_monitor");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT count(queryid) from pg_stat_monitor;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "SELECT count(queryid) from pg_stat_monitor");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_overflow_target = 1\n");
$node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', '\i scripts/data_2.sql' , extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Run sql file: scripts/data2.sql");
#TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
#PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT substr(query, 0, 50), length(query), bucket, queryid, calls, elevel, sqlcode, message from pg_stat_monitor;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "SELECT substr(query, 0, 50), calls, message from pg_stat_monitor");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT count(queryid) from pg_stat_monitor;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "SELECT count(queryid) from pg_stat_monitor");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Drop extension
$stdout = $node->safe_psql('postgres', 'Drop extension pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Drop PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Stop the server
$node->stop;

View File

@ -2,56 +2,20 @@
use strict;
use warnings;
use String::Util qw(trim);
use File::Basename;
use File::Compare;
use PostgresNode;
use File::Copy;
use String::Util qw(trim);
use Test::More;
use lib 't';
use pgsm;
# Expected folder where expected output will be present
my $expected_folder = "t/expected";
# Results/out folder where generated results files will be placed
my $results_folder = "t/results";
# Check if results folder exists or not, create if it doesn't
unless (-d $results_folder)
{
mkdir $results_folder or die "Can't create folder $results_folder: $!\n";;
}
# Check if expected folder exists or not, bail out if it doesn't
unless (-d $expected_folder)
{
BAIL_OUT "Expected files folder $expected_folder doesn't exist: \n";;
}
# Get filename of the this perl file
my $perlfilename = basename($0);
#Remove .pl from filename and store in a variable
$perlfilename =~ s/\.[^.]+$//;
my $filename_without_extension = $perlfilename;
# Create expected filename with path
my $expected_filename = "${filename_without_extension}.out";
my $expected_filename_with_path = "${expected_folder}/${expected_filename}" ;
# Create results filename with path
my $out_filename = "${filename_without_extension}.out";
my $out_filename_with_path = "${results_folder}/${out_filename}" ;
# Delete already existing result out file, if it exists.
if ( -f $out_filename_with_path)
{
unlink($out_filename_with_path) or die "Can't delete already existing $out_filename_with_path: $!\n";
}
# Get filename and create out file name and dirs where requried
PGSM::setup_files_dir(basename($0));
# Create new PostgreSQL node and do initdb
my $node = PostgresNode->get_new_node('test');
my $node = PGSM->pgsm_init_pg();
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";
@ -73,35 +37,33 @@ ok($rt_value == 1, "Start Server");
# 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");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
PGSM::append_to_file($stdout);
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'create table foo (id int generated by default as identity,col1 varchar(100) not null,primary key(id));', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Create Table foo");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', '\i scripts/data_1.sql' , extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Run sql file: scripts/data.sql");
#TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
#PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT substr(query, 0, 50), length(query), bucket, queryid, calls, elevel, sqlcode, message from pg_stat_monitor;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "SELECT substr(query, 0, 50), calls, message from pg_stat_monitor");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT count(queryid) from pg_stat_monitor;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "SELECT count(queryid) from pg_stat_monitor");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_max = 100\n");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_query_max_len = 1024\n");
@ -122,32 +84,32 @@ $node->restart();
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', '\i scripts/data_2.sql' , extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Run sql file: scripts/data2.sql");
#TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
#PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT substr(query, 0, 50), length(query), bucket, queryid, calls, elevel, sqlcode, message from pg_stat_monitor;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "SELECT substr(query, 0, 50), calls, message from pg_stat_monitor");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT count(queryid) from pg_stat_monitor;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "SELECT count(queryid) from pg_stat_monitor");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Drop extension
$stdout = $node->safe_psql('postgres', 'Drop extension pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Drop PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Stop the server
$node->stop;

View File

@ -34,14 +34,18 @@ use strict;
use warnings;
use File::Basename;
use File::Compare;
use PostgresNode;
use File::Copy;
use Test::More;
use lib 't';
use pgsm;
# Get filename and create out file name and dirs where requried
PGSM::setup_files_dir(basename($0));
# Create new PostgreSQL node and do initdb
my $node = PostgresNode->get_new_node('test');
my $node = PGSM->pgsm_init_pg();
my $pgdata = $node->data_dir;
$node->dump_info;
$node->init;
$node->append_conf('postgresql.conf', "shared_preload_libraries = 'pg_stat_monitor'");
# Set bucket duration to 14 seconds so tests don't take too long.
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_bucket_time = 14");

View File

@ -1,68 +1,27 @@
#!/usr/bin/perl
use strict;
use warnings;
use File::Basename;
use File::Compare;
use PostgresNode;
use File::Copy;
use String::Util qw(trim);
use Test::More;
use lib 't';
use pgsm;
# Expected folder where expected output will be present
my $expected_folder = "t/expected";
# Get filename and create out file name and dirs where requried
PGSM::setup_files_dir(basename($0));
# Results/out folder where generated results files will be placed
my $results_folder = "t/results";
# Check if results folder exists or not, create if it doesn't
unless (-d $results_folder)
{
mkdir $results_folder or die "Can't create folder $results_folder: $!\n";;
}
# Check if expected folder exists or not, bail out if it doesn't
unless (-d $expected_folder)
{
BAIL_OUT "Expected files folder $expected_folder doesn't exist: \n";;
}
# 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)
if ($PGSM::PG_MAJOR_VERSION <= 12)
{
plan skip_all => "pg_stat_statements test cases for versions 12 and below.";
plan skip_all => "pg_stat_monitor test cases for versions 12 and below.";
}
#Remove .pl from filename and store in a variable
$perlfilename =~ s/\.[^.]+$//;
my $filename_without_extension = $perlfilename;
# Create expected filename with path
my $expected_filename = "${filename_without_extension}.out";
my $expected_filename_with_path = "${expected_folder}/${expected_filename}" ;
# Create results filename with path
my $out_filename = "${filename_without_extension}.out";
my $out_filename_with_path = "${results_folder}/${out_filename}" ;
my $dynamic_out_filename_with_path = "${results_folder}/${out_filename}.dynamic" ;
# Delete already existing result out file, if it exists.
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 = PGSM->pgsm_init_pg();
my $pgdata = $node->data_dir;
# Update postgresql.conf to include/load pg_stat_monitor library
$node->append_conf('postgresql.conf', "shared_preload_libraries = 'pg_stat_statements,pg_stat_monitor'");
@ -79,36 +38,32 @@ ok($rt_value == 1, "Start Server");
# Create extension and change out file permissions
my ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE EXTENSION pg_stat_statements;', extra_params => ['-a']);
ok($cmdret == 0, "Create PGSS Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
PGSM::append_to_file($stdout);
# Create extension and change out file permissions
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE EXTENSION pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Create PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
PGSM::append_to_file($stdout);
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_statements_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSS Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Run 'SELECT * from pg_stat_monitor_settings;' two times and dump output to out file
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Create example database and run pgbench init
# ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE database example;', extra_params => ['-a']);
# ok($cmdret == 0, "Create Database example");
# TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# PGSM::append_to_file($stdout);
my $port = $node->port;
@ -125,11 +80,11 @@ ok($cmdret == 0, "Run pgbench");
($cmdret, $stdout, $stderr) = $node->psql('postgres', "Delete from pgbench_accounts where aid % 2 = 1;", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select substr(query,0,130) as query, calls, rows, total_exec_time,min_exec_time,max_exec_time,mean_exec_time,stddev_exec_time from pg_stat_statements where query Like \'%bench%\' order by query,calls desc;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($dynamic_out_filename_with_path, $stdout . "\n");
PGSM::append_to_debug_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select substr(query,0,130) as query, calls, rows_retrieved, total_exec_time, min_exec_time, max_exec_time, mean_exec_time,stddev_exec_time, cpu_user_time, cpu_sys_time from pg_stat_monitor where query Like \'%bench%\' order by query,calls desc;', 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, "\n\n");
PGSM::append_to_debug_file($stdout);
PGSM::append_to_debug_file("--------------");
# Compare values for query 'Delete from pgbench_accounts where $1 = $2'
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.total_exec_time != 0 from pg_stat_monitor as PGSM where PGSM.query Like \'%Delete from pgbench_accounts%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
@ -251,7 +206,7 @@ is($stdout,'t',"Check: cpu_sys_time should not be 0.");
# Drop extension
$stdout = $node->safe_psql('postgres', 'Drop extension pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Drop PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Stop the server
$node->stop;

View File

@ -4,71 +4,29 @@ use strict;
use warnings;
use File::Basename;
use File::Compare;
use PostgresNode;
use File::Copy;
use String::Util qw(trim);
use Test::More;
use lib 't';
use pgsm;
# Expected folder where expected output will be present
my $expected_folder = "t/expected";
# Results/out folder where generated results files will be placed
my $results_folder = "t/results";
# Check if results folder exists or not, create if it doesn't
unless (-d $results_folder)
{
mkdir $results_folder or die "Can't create folder $results_folder: $!\n";;
}
# Check if expected folder exists or not, bail out if it doesn't
unless (-d $expected_folder)
{
BAIL_OUT "Expected files folder $expected_folder doesn't exist: \n";;
}
# Get filename of the this perl file
my $perlfilename = basename($0);
#Remove .pl from filename and store in a variable
$perlfilename =~ s/\.[^.]+$//;
my $filename_without_extension = $perlfilename;
# Create expected filename with path
my $expected_filename = "${filename_without_extension}.out";
my $expected_filename_with_path = "${expected_folder}/${expected_filename}" ;
# Create results filename with path
my $out_filename = "${filename_without_extension}.out";
my $out_filename_with_path = "${results_folder}/${out_filename}" ;
my $dynamic_out_filename_with_path = "${results_folder}/${out_filename}.dynamic" ;
# Delete already existing result out file, if it exists.
if ( -f $out_filename_with_path)
{
unlink($out_filename_with_path) or die "Can't delete already existing $out_filename_with_path: $!\n";
}
# Get filename and create out file name and dirs where requried
PGSM::setup_files_dir(basename($0));
if ($PGSM::PG_MAJOR_VERSION <= 12)
{
plan skip_all => "pg_stat_monitor test cases for versions 12 and below.";
}
# Create new PostgreSQL node and do initdb
my $node = PostgresNode->get_new_node('test');
my $node = PGSM->pgsm_init_pg();
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'");
# Set bucket duration to 3600 seconds so bucket doesn't change.
$node->append_conf('postgresql.conf', "pg_stat_statements.track_utility = off");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_bucket_time = 1800");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_bucket_time = 3600");
$node->append_conf('postgresql.conf', "track_io_timing = on");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_track_utility = no");
$node->append_conf('postgresql.conf', "pg_stat_monitor.pgsm_normalized_query = yes");
@ -80,36 +38,32 @@ ok($rt_value == 1, "Start Server");
# Create extension and change out file permissions
my ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE EXTENSION pg_stat_statements;', extra_params => ['-a']);
ok($cmdret == 0, "Create PGSS Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
PGSM::append_to_file($stdout);
# Create extension and change out file permissions
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE EXTENSION pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Create PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
PGSM::append_to_file($stdout);
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_statements_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSS Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Run 'SELECT * from pg_stat_monitor_settings;' two times and dump output to out file
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Create example database and run pgbench init
# ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE database example;', extra_params => ['-a']);
# ok($cmdret == 0, "Create Database example");
# TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# PGSM::append_to_file($stdout);
my $port = $node->port;
@ -126,23 +80,23 @@ ok($cmdret == 0, "Run pgbench");
($cmdret, $stdout, $stderr) = $node->psql('postgres', "Delete from pgbench_accounts where aid % 2 = 1;", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select queryid, substr(query,0,130) as query, calls, rows, total_exec_time,min_exec_time,max_exec_time,mean_exec_time from pg_stat_statements where query Like \'%bench%\' order by query,calls desc;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($dynamic_out_filename_with_path, $stdout . "\n");
PGSM::append_to_debug_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select client_ip, bucket, queryid, substr(query,0,130) as query, cmd_type_text, calls, rows_retrieved, total_exec_time, min_exec_time, max_exec_time, mean_exec_time, cpu_user_time, cpu_sys_time from pg_stat_monitor where query Like \'%bench%\' order by query,calls desc;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($dynamic_out_filename_with_path, $stdout . "\n");
PGSM::append_to_debug_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select substr(query,0,30) as query,calls,rows,shared_blks_hit,shared_blks_read,shared_blks_dirtied,shared_blks_written,local_blks_hit,local_blks_read,local_blks_dirtied,local_blks_written,temp_blks_read,temp_blks_written,blk_read_time,blk_write_time,wal_records,wal_fpi,wal_bytes from pg_stat_statements where query Like \'%bench%\' order by query,calls ;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($dynamic_out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select substr(query,0,30) as query,calls,rows,shared_blks_hit,shared_blks_read,shared_blks_dirtied,shared_blks_written,local_blks_hit,local_blks_read,local_blks_dirtied,local_blks_written,temp_blks_read,temp_blks_written,blk_read_time,blk_write_time,wal_records,wal_fpi,wal_bytes from pg_stat_statements where query Like \'%bench%\' order by query,calls;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
PGSM::append_to_debug_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select substr(query,0,30) as query,calls,rows_retrieved as rows, shared_blks_hit,shared_blks_read,shared_blks_dirtied,shared_blks_written,local_blks_hit,local_blks_read,local_blks_dirtied,local_blks_written,temp_blks_read,temp_blks_written,blk_read_time,blk_write_time,wal_records,wal_fpi,wal_bytes, cmd_type_text from pg_stat_monitor where query Like \'%bench%\' order by query,calls ;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($dynamic_out_filename_with_path, $stdout . "\n");
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select substr(query,0,30) as query,calls,rows_retrieved as rows, shared_blks_hit,shared_blks_read,shared_blks_dirtied,shared_blks_written,local_blks_hit,local_blks_read,local_blks_dirtied,local_blks_written,temp_blks_read,temp_blks_written,blk_read_time,blk_write_time,wal_records,wal_fpi,wal_bytes, cmd_type_text from pg_stat_monitor where query Like \'%bench%\' order by query,calls;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
PGSM::append_to_debug_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select substr(query,0,30),calls, rows, ROUND(total_exec_time::numeric,4) as total_exec_time, ROUND(min_exec_time::numeric,4) as min_exec_time, ROUND(max_exec_time::numeric,4) as max_exec_time, ROUND(mean_exec_time::numeric,4) as mean_exec_time, ROUND(stddev_exec_time::numeric,4) as stddev_exec_time, ROUND(blk_read_time::numeric,4) as blk_read_time, ROUND(blk_write_time::numeric,4) as blk_write_time, wal_records, wal_fpi, wal_bytes from pg_stat_statements where query Like \'%bench%\' order by query,calls desc;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($dynamic_out_filename_with_path, $stdout . "\n");
PGSM::append_to_debug_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'select substr(query,0,30), calls, rows_retrieved as rows, total_exec_time, min_exec_time, max_exec_time, mean_exec_time, stddev_exec_time, ROUND(blk_read_time::numeric,4) as blk_read_time, ROUND(blk_write_time::numeric,4) as blk_write_time, wal_records, wal_fpi, wal_bytes from pg_stat_monitor where query Like \'%bench%\' order by query,calls desc;', 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, "\n\n");
PGSM::append_to_debug_file($stdout);
PGSM::append_to_debug_file("-------------");
# Compare values for query 'Delete from pgbench_accounts where $1 = $2'
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.calls = PGSS.calls from pg_stat_monitor as PGSM INNER JOIN pg_stat_statements as PGSS ON PGSS.query = PGSM.query where PGSM.query Like \'%Delete from pgbench_accounts%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
@ -343,7 +297,7 @@ is($stdout,'t',"Compare: wal_bytes are equal.");
# Drop extension
$stdout = $node->safe_psql('postgres', 'Drop extension pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Drop PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Stop the server
$node->stop;

View File

@ -4,65 +4,23 @@ use strict;
use warnings;
use File::Basename;
use File::Compare;
use PostgresNode;
use File::Copy;
use String::Util qw(trim);
use Test::More;
use lib 't';
use pgsm;
# Expected folder where expected output will be present
my $expected_folder = "t/expected";
# Results/out folder where generated results files will be placed
my $results_folder = "t/results";
# Check if results folder exists or not, create if it doesn't
unless (-d $results_folder)
{
mkdir $results_folder or die "Can't create folder $results_folder: $!\n";;
}
# Check if expected folder exists or not, bail out if it doesn't
unless (-d $expected_folder)
{
BAIL_OUT "Expected files folder $expected_folder doesn't exist: \n";;
}
# Get filename of the this perl file
my $perlfilename = basename($0);
#Remove .pl from filename and store in a variable
$perlfilename =~ s/\.[^.]+$//;
my $filename_without_extension = $perlfilename;
# Create expected filename with path
my $expected_filename = "${filename_without_extension}.out";
my $expected_filename_with_path = "${expected_folder}/${expected_filename}" ;
# Create results filename with path
my $out_filename = "${filename_without_extension}.out";
my $out_filename_with_path = "${results_folder}/${out_filename}" ;
my $dynamic_out_filename_with_path = "${results_folder}/${out_filename}.dynamic" ;
# Delete already existing result out file, if it exists.
if ( -f $out_filename_with_path)
{
unlink($out_filename_with_path) or die "Can't delete already existing $out_filename_with_path: $!\n";
}
# Get filename and create out file name and dirs where requried
PGSM::setup_files_dir(basename($0));
if ($PGSM::PG_MAJOR_VERSION <= 12)
{
plan skip_all => "pg_stat_monitor test cases for versions 12 and below.";
}
# Create new PostgreSQL node and do initdb
my $node = PostgresNode->get_new_node('test');
my $node = PGSM->pgsm_init_pg();
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'");
@ -80,36 +38,32 @@ ok($rt_value == 1, "Start Server");
# Create extension and change out file permissions
my ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE EXTENSION pg_stat_statements;', extra_params => ['-a']);
ok($cmdret == 0, "Create PGSS Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
PGSM::append_to_file($stdout);
# Create extension and change out file permissions
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE EXTENSION pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Create PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
PGSM::append_to_file($stdout);
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_statements_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSS Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Run 'SELECT * from pg_stat_monitor_settings;' two times and dump output to out file
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Create example database and run pgbench init
# ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE database example;', extra_params => ['-a']);
# ok($cmdret == 0, "Create Database example");
# TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
# PGSM::append_to_file($stdout);
my $port = $node->port;
@ -126,11 +80,11 @@ ok($cmdret == 0, "Run pgbench");
($cmdret, $stdout, $stderr) = $node->psql('postgres', "Delete from pgbench_accounts where aid % 2 = 1;", extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select substr(query,0,130) as query, calls, rows, total_exec_time,min_exec_time,max_exec_time,mean_exec_time,stddev_exec_time from pg_stat_statements where query Like \'%bench%\' order by query,calls desc;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($dynamic_out_filename_with_path, $stdout . "\n");
PGSM::append_to_debug_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select substr(query,0,130) as query, calls, rows_retrieved, total_exec_time, min_exec_time, max_exec_time, mean_exec_time,stddev_exec_time, cpu_user_time, cpu_sys_time from pg_stat_monitor where query Like \'%bench%\' order by query,calls desc;', 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, "\n\n");
PGSM::append_to_debug_file($stdout);
PGSM::append_to_debug_file("--------");
# Compare values for query 'Delete from pgbench_accounts where $1 = $2'
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.shared_blks_hit != 0 from pg_stat_monitor as PGSM where PGSM.query Like \'%Delete from pgbench_accounts%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
@ -210,7 +164,7 @@ is($stdout,'t',"Check: blk_write_time should not be 0.");
# Drop extension
$stdout = $node->safe_psql('postgres', 'Drop extension pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Drop PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Stop the server
$node->stop;

View File

@ -4,65 +4,23 @@ use strict;
use warnings;
use File::Basename;
use File::Compare;
use PostgresNode;
use File::Copy;
use String::Util qw(trim);
use Test::More;
use lib 't';
use pgsm;
# Expected folder where expected output will be present
my $expected_folder = "t/expected";
# Get filename and create out file name and dirs where requried
PGSM::setup_files_dir(basename($0));
# Results/out folder where generated results files will be placed
my $results_folder = "t/results";
# Check if results folder exists or not, create if it doesn't
unless (-d $results_folder)
if ($PGSM::PG_MAJOR_VERSION <= 12)
{
mkdir $results_folder or die "Can't create folder $results_folder: $!\n";;
}
# Check if expected folder exists or not, bail out if it doesn't
unless (-d $expected_folder)
{
BAIL_OUT "Expected files folder $expected_folder doesn't exist: \n";;
}
# Get filename of the this perl file
my $perlfilename = basename($0);
#Remove .pl from filename and store in a variable
$perlfilename =~ s/\.[^.]+$//;
my $filename_without_extension = $perlfilename;
# Create expected filename with path
my $expected_filename = "${filename_without_extension}.out";
my $expected_filename_with_path = "${expected_folder}/${expected_filename}" ;
# Create results filename with path
my $out_filename = "${filename_without_extension}.out";
my $out_filename_with_path = "${results_folder}/${out_filename}" ;
my $dynamic_out_filename_with_path = "${results_folder}/${out_filename}.dynamic" ;
# Delete already existing result out file, if it exists.
if ( -f $out_filename_with_path)
{
unlink($out_filename_with_path) or die "Can't delete already existing $out_filename_with_path: $!\n";
plan skip_all => "pg_stat_monitor test cases for versions 12 and below.";
}
# Create new PostgreSQL node and do initdb
my $node = PostgresNode->get_new_node('test');
my $node = PGSM->pgsm_init_pg();
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'");
@ -79,33 +37,29 @@ ok($rt_value == 1, "Start Server");
# Create extension and change out file permissions
my ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE EXTENSION pg_stat_statements;', extra_params => ['-a']);
ok($cmdret == 0, "Create PGSS Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
PGSM::append_to_file($stdout);
# Create extension and change out file permissions
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE EXTENSION pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Create PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
PGSM::append_to_file($stdout);
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Run 'SELECT * from pg_stat_monitor_settings;' two times and dump output to out file
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', ' CREATE Temporary TABLE t1(a int); INSERT INTO t1 VALUES(generate_series(1,10000)); ANALYZE t1; SELECT * FROM t1;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Create Temporary Table and insert values in a single session.");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select substr(query,0,130) as query, calls, rows_retrieved, cpu_user_time, cpu_sys_time, local_blks_hit, local_blks_read, local_blks_dirtied, local_blks_written, temp_blks_read, temp_blks_written from pg_stat_monitor where query Like \'%t1%\' order by query,calls desc;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($dynamic_out_filename_with_path, $stdout . "\n");
PGSM::append_to_debug_file($stdout);
# Compare values for query 'INSERT INTO t1 VALUES(generate_series($1,$2))'
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.local_blks_hit != 0 from pg_stat_monitor as PGSM where PGSM.query Like \'%INSERT INTO t1%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
@ -132,7 +86,7 @@ is($stdout,'t',"Check: shared_blks_hit should not be 0.");
# Drop extension
$stdout = $node->safe_psql('postgres', 'Drop extension pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Drop PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Stop the server
$node->stop;

View File

@ -4,65 +4,23 @@ use strict;
use warnings;
use File::Basename;
use File::Compare;
use PostgresNode;
use File::Copy;
use String::Util qw(trim);
use Test::More;
use lib 't';
use pgsm;
# Expected folder where expected output will be present
my $expected_folder = "t/expected";
# Get filename and create out file name and dirs where requried
PGSM::setup_files_dir(basename($0));
# Results/out folder where generated results files will be placed
my $results_folder = "t/results";
# Check if results folder exists or not, create if it doesn't
unless (-d $results_folder)
if ($PGSM::PG_MAJOR_VERSION <= 12)
{
mkdir $results_folder or die "Can't create folder $results_folder: $!\n";;
}
# Check if expected folder exists or not, bail out if it doesn't
unless (-d $expected_folder)
{
BAIL_OUT "Expected files folder $expected_folder doesn't exist: \n";;
}
# Get filename of the this perl file
my $perlfilename = basename($0);
#Remove .pl from filename and store in a variable
$perlfilename =~ s/\.[^.]+$//;
my $filename_without_extension = $perlfilename;
# Create expected filename with path
my $expected_filename = "${filename_without_extension}.out";
my $expected_filename_with_path = "${expected_folder}/${expected_filename}" ;
# Create results filename with path
my $out_filename = "${filename_without_extension}.out";
my $out_filename_with_path = "${results_folder}/${out_filename}" ;
my $dynamic_out_filename_with_path = "${results_folder}/${out_filename}.dynamic" ;
# Delete already existing result out file, if it exists.
if ( -f $out_filename_with_path)
{
unlink($out_filename_with_path) or die "Can't delete already existing $out_filename_with_path: $!\n";
plan skip_all => "pg_stat_monitor test cases for versions 12 and below.";
}
# Create new PostgreSQL node and do initdb
my $node = PostgresNode->get_new_node('test');
my $node = PGSM->pgsm_init_pg();
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'");
@ -81,52 +39,48 @@ ok($rt_value == 1, "Start Server");
# Create extension and change out file permissions
my ($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE EXTENSION pg_stat_statements;', extra_params => ['-a']);
ok($cmdret == 0, "Create PGSS Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
PGSM::append_to_file($stdout);
# Create extension and change out file permissions
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE EXTENSION pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Create PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
PGSM::append_to_file($stdout);
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Run 'SELECT * from pg_stat_monitor_settings;' two times and dump output to out file
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * from pg_stat_monitor_settings;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Print PGSM Extension Settings");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', ' CREATE TABLE t1(a int);', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Create Table t1");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'CREATE INDEX idx_t1_a on t1(a);', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Create index.");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'INSERT INTO t1 VALUES(generate_series(1,1000000));', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Insert 10000 records.");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'ANALYZE t1;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Analyze t1.");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT * FROM t1 AS XX INNER JOIN t1 as TT ON XX.a = TT.a;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Select * from t1.");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select substr(query,0,130) as query, calls, rows_retrieved, cpu_user_time, cpu_sys_time, local_blks_hit, local_blks_read, local_blks_dirtied, local_blks_written, temp_blks_read, temp_blks_written from pg_stat_monitor where query Like \'%t1%\' order by query,calls desc;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($dynamic_out_filename_with_path, $stdout . "\n");
PGSM::append_to_debug_file($stdout);
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'SELECT temp_files, temp_bytes FROM pg_stat_database db;', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
TestLib::append_to_file($dynamic_out_filename_with_path, $stdout . "\n");
PGSM::append_to_debug_file($stdout);
# Compare values for query 'SELECT * FROM t1'
($cmdret, $stdout, $stderr) = $node->psql('postgres', 'Select PGSM.temp_blks_read != 0 from pg_stat_monitor as PGSM where PGSM.query Like \'%FROM t1%\';', extra_params => ['-Pformat=unaligned','-Ptuples_only=on']);
@ -140,7 +94,7 @@ is($stdout,'t',"Check: temp_blks_read should not be 0.");
# Drop extension
$stdout = $node->safe_psql('postgres', 'Drop extension pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "Drop PGSM Extension");
TestLib::append_to_file($out_filename_with_path, $stdout . "\n");
PGSM::append_to_file($stdout);
# Stop the server
$node->stop;

View File

@ -0,0 +1,114 @@
CREATE EXTENSION pg_stat_monitor;
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT * from pg_stat_monitor_settings where name='pg_stat_monitor.pgsm_query_shared_buffer';
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+-------+---------------+-------------------------------------------------------------------------------------------+---------+---------+---------+---------
pg_stat_monitor.pgsm_query_shared_buffer | 1 | 20 | Sets the maximum size of shared memory in (MB) used for query tracked by pg_stat_monitor. | 1 | 10000 | | yes
(1 row)
CREATE database example;
select datname, substr(query,0,150) as query, calls from pg_stat_monitor order by datname, query, calls desc Limit 20;
datname | query | calls
---------+---------------------------------------------------------------------------------------------------------------+-------
example | BEGIN | 10000
example | END | 10000
example | INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES ($1, $2, $3, $4, CURRENT_TIMESTAMP) | 10000
example | SELECT abalance FROM pgbench_accounts WHERE aid = $1 | 10000
example | UPDATE pgbench_accounts SET abalance = abalance + $1 WHERE aid = $2 | 10000
example | UPDATE pgbench_branches SET bbalance = bbalance + $1 WHERE bid = $2 | 10000
example | UPDATE pgbench_tellers SET tbalance = tbalance + $1 WHERE tid = $2 | 10000
example | alter table pgbench_accounts add primary key (aid) | 1
example | alter table pgbench_branches add primary key (bid) | 1
example | alter table pgbench_tellers add primary key (tid) | 1
example | begin | 1
example | commit | 1
example | copy pgbench_accounts from stdin with (freeze on) | 1
example | create table pgbench_accounts(aid int not null,bid int,abalance int,filler char(84)) with (fillfactor=100) | 1
example | create table pgbench_branches(bid int not null,bbalance int,filler char(88)) with (fillfactor=100) | 1
example | create table pgbench_history(tid int,bid int,aid int,delta int,mtime timestamp,filler char(22)) | 1
example | create table pgbench_tellers(tid int not null,bid int,tbalance int,filler char(84)) with (fillfactor=100) | 1
example | drop table if exists pgbench_accounts, pgbench_branches, pgbench_history, pgbench_tellers | 1
example | insert into pgbench_branches(bid,bbalance) values($1,$2) | 100
example | insert into pgbench_tellers(tid,bid,tbalance) values ($1,$2,$3) | 1000
(20 rows)
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT * from pg_stat_monitor_settings where name='pg_stat_monitor.pgsm_query_shared_buffer';
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+-------+---------------+-------------------------------------------------------------------------------------------+---------+---------+---------+---------
pg_stat_monitor.pgsm_query_shared_buffer | 100 | 20 | Sets the maximum size of shared memory in (MB) used for query tracked by pg_stat_monitor. | 1 | 10000 | | yes
(1 row)
select datname, substr(query,0,150) as query, calls from pg_stat_monitor order by datname, query, calls desc Limit 20;
datname | query | calls
---------+---------------------------------------------------------------------------------------------------------------+-------
example | BEGIN | 10000
example | END | 10000
example | INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES ($1, $2, $3, $4, CURRENT_TIMESTAMP) | 10000
example | SELECT abalance FROM pgbench_accounts WHERE aid = $1 | 10000
example | UPDATE pgbench_accounts SET abalance = abalance + $1 WHERE aid = $2 | 10000
example | UPDATE pgbench_branches SET bbalance = bbalance + $1 WHERE bid = $2 | 10000
example | UPDATE pgbench_tellers SET tbalance = tbalance + $1 WHERE tid = $2 | 10000
example | alter table pgbench_accounts add primary key (aid) | 1
example | alter table pgbench_branches add primary key (bid) | 1
example | alter table pgbench_tellers add primary key (tid) | 1
example | begin | 1
example | commit | 1
example | copy pgbench_accounts from stdin with (freeze on) | 1
example | create table pgbench_accounts(aid int not null,bid int,abalance int,filler char(84)) with (fillfactor=100) | 1
example | create table pgbench_branches(bid int not null,bbalance int,filler char(88)) with (fillfactor=100) | 1
example | create table pgbench_history(tid int,bid int,aid int,delta int,mtime timestamp,filler char(22)) | 1
example | create table pgbench_tellers(tid int not null,bid int,tbalance int,filler char(84)) with (fillfactor=100) | 1
example | drop table if exists pgbench_accounts, pgbench_branches, pgbench_history, pgbench_tellers | 1
example | insert into pgbench_branches(bid,bbalance) values($1,$2) | 100
example | insert into pgbench_tellers(tid,bid,tbalance) values ($1,$2,$3) | 1000
(20 rows)
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT * from pg_stat_monitor_settings where name='pg_stat_monitor.pgsm_query_shared_buffer';
name | value | default_value | description | minimum | maximum | options | restart
------------------------------------------+-------+---------------+-------------------------------------------------------------------------------------------+---------+---------+---------+---------
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
(1 row)
select datname, substr(query,0,150) as query, calls from pg_stat_monitor order by datname, query, calls desc Limit 20;
datname | query | calls
---------+---------------------------------------------------------------------------------------------------------------+-------
example | BEGIN | 10000
example | END | 10000
example | INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES ($1, $2, $3, $4, CURRENT_TIMESTAMP) | 10000
example | SELECT abalance FROM pgbench_accounts WHERE aid = $1 | 10000
example | UPDATE pgbench_accounts SET abalance = abalance + $1 WHERE aid = $2 | 10000
example | UPDATE pgbench_branches SET bbalance = bbalance + $1 WHERE bid = $2 | 10000
example | UPDATE pgbench_tellers SET tbalance = tbalance + $1 WHERE tid = $2 | 10000
example | alter table pgbench_accounts add primary key (aid) | 1
example | alter table pgbench_branches add primary key (bid) | 1
example | alter table pgbench_tellers add primary key (tid) | 1
example | begin | 1
example | commit | 1
example | copy pgbench_accounts from stdin with (freeze on) | 1
example | create table pgbench_accounts(aid int not null,bid int,abalance int,filler char(84)) with (fillfactor=100) | 1
example | create table pgbench_branches(bid int not null,bbalance int,filler char(88)) with (fillfactor=100) | 1
example | create table pgbench_history(tid int,bid int,aid int,delta int,mtime timestamp,filler char(22)) | 1
example | create table pgbench_tellers(tid int not null,bid int,tbalance int,filler char(84)) with (fillfactor=100) | 1
example | drop table if exists pgbench_accounts, pgbench_branches, pgbench_history, pgbench_tellers | 1
example | insert into pgbench_branches(bid,bbalance) values($1,$2) | 100
example | insert into pgbench_tellers(tid,bid,tbalance) values ($1,$2,$3) | 1000
(20 rows)
Drop extension pg_stat_monitor;

171
t/pgsm.pm
View File

@ -1,72 +1,157 @@
package pgsm;
package PGSM;
use String::Util qw(trim);
use File::Basename;
use File::Compare;
use PostgresNode;
use Test::More;
our @ISA= qw( Exporter );
# these CAN be exported.
# These CAN be exported.
our @EXPORT = qw( pgsm_init_pg pgsm_start_pg pgsm_stop_pg pgsm_psql_cmd pgsm_setup_pg_stat_monitor pgsm_create_extension pgsm_reset_pg_stat_monitor pgsm_drop_extension );
# Instance of pg server that would be spanwed by TAP testing. A new server will be created for each TAP test.
our $pg_node;
# Create new PostgreSQL node and do initdb
# Expected .out filename of TAP testcase being executed. These are already part of repo under t/expected/*.
our $expected_filename_with_path;
# Major version of PG Server that we are using.
our $PG_MAJOR_VERSION;
# Result .out filename of TAP testcase being executed. Where needed, a new *.out will be created for each TAP test.
our $out_filename_with_path;
# Runtime output file that is used only for debugging purposes for comparison to PGSS, blocks and timings.
our $debug_out_filename_with_path;
BEGIN {
# Get PG Server Major version from pg_config
$PG_MAJOR_VERSION = `pg_config --version | awk {'print \$2'} | cut -f1 -d"." | sed -e 's/[^0-9].*\$//g'`;
$PG_MAJOR_VERSION =~ s/^\s+|\s+$//g;
# Depending upon PG server version load the required module at runtime when pgsm.pm is loaded.
my $node_module = $PG_MAJOR_VERSION > 14 ? "PostgreSQL::Test::Cluster" : "PostgresNode";
my $node_module_file = $node_module;
$node_module_file =~ s[::][/]g;
$node_module_file .= '.pm';
require $node_module_file;
$node_module->import;
}
sub pgsm_init_pg
{
$pg_node = PostgresNode->get_new_node('pgsm_regression');
print "Postgres major version: $PG_MAJOR_VERSION \n";
# For Server version 15 & above, spawn the server using PostgreSQL::Test::Cluster
if ($PG_MAJOR_VERSION > 14) {
$pg_node = PostgreSQL::Test::Cluster->new('pgsm_regression');
}
# For Server version 14 & below, spawn the server using PostgresNode
elsif ($PG_MAJOR_VERSION < 15) {
$pg_node = PostgresNode->get_new_node('pgsm_regression');
}
$pg_node->dump_info;
$pg_node->init;
return $pg_node;
}
sub pgsm_start_pg
sub append_to_file
{
my $rt_value = $pg_node->start;
ok($rt_value == 1, "Starting PostgreSQL");
return $rt_value;
my ($str) = @_;
# For Server version 15 & above, use PostgreSQL::Test::Utils to write to files
if ($PG_MAJOR_VERSION > 14) {
PostgreSQL::Test::Utils::append_to_file($out_filename_with_path, $str . "\n");
}
# For Server version 14 & below, use PostgresNode to write to files
elsif ($PG_MAJOR_VERSION < 15) {
TestLib::append_to_file($out_filename_with_path, $str . "\n");
}
chmod(0640 , $out_filename_with_path)
or die("unable to set permissions for $out_filename_with_path");
return;
}
sub pgsm_stop_pg
sub append_to_debug_file
{
return $pg_node->stop;
my ($str) = @_;
# For Server version 15 & above, use PostgreSQL::Test::Utils to write to files
if ($PG_MAJOR_VERSION > 14) {
PostgreSQL::Test::Utils::append_to_file($debug_out_filename_with_path, $str . "\n");
}
# For Server version 14 & below, use PostgresNode to write to files
elsif ($PG_MAJOR_VERSION < 15) {
TestLib::append_to_file($debug_out_filename_with_path, $str . "\n");
}
chmod(0640 , $debug_out_filename_with_path)
or die("unable to set permissions for $debug_out_filename_with_path");
return;
}
sub pgsm_psql_cmd
sub setup_files_dir
{
my ($cmdret, $stdout, $stderr) = $pg_node->psql(@_);
my ($perlfilename) = @_;
# Expected folder where expected output will be present
my $expected_folder = "t/expected";
# Results/out folder where generated results files will be placed
my $results_folder = "t/results";
# Check if results folder exists or not, create if it doesn't
unless (-d $results_folder)
{
mkdir $results_folder or die "Can't create folder $results_folder: $!\n";
}
# Check if expected folder exists or not, bail out if it doesn't
unless (-d $expected_folder)
{
BAIL_OUT "Expected files folder $expected_folder doesn't exist: \n";
}
#Remove .pl from filename and store in a variable
my @split_arr = split /\./, $perlfilename;
my $filename_without_extension = $split_arr[0];
# Create expected filename with path
my $expected_filename = "${filename_without_extension}.out";
if ($PG_MAJOR_VERSION <= 12 and "$filename_without_extension" == "001_settings_default")
{
$expected_filename = "${expected_filename}.${PG_MAJOR_VERSION}";
}
if ($PG_MAJOR_VERSION >= 15 and "$filename_without_extension" == "007_settings_pgsm_query_shared_buffer")
{
$expected_filename = "${expected_filename}.${PG_MAJOR_VERSION}";
}
$expected_filename_with_path = "${expected_folder}/${expected_filename}";
# Create results filename with path
my $out_filename = "${filename_without_extension}.out";
$out_filename_with_path = "${results_folder}/${out_filename}";
# Delete already existing result out file, if it exists.
if ( -f $out_filename_with_path)
{
unlink($out_filename_with_path) or die "Can't delete already existing $out_filename_with_path: $!\n";
}
$debug_out_filename_with_path = "${results_folder}/${out_filename}.debug";
}
sub pgsm_setup_pg_stat_monitor
sub compare_results
{
my ($set) = @_;
my $pgdata = $pg_node->data_dir;
open my $conf, '>>', "$pgdata/postgresql.conf";
print $conf "shared_preload_libraries = 'pg_stat_monitor'\n";
print $conf "$set\n";
close $conf;
# Compare expected and results files and return the result
return compare($expected_filename_with_path, $out_filename_with_path);
}
sub pgsm_create_extension
{
my ($cmdret, $stdout, $stderr) = $pg_node->psql('postgres', 'CREATE EXTENSION pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "CREATE EXTENSION pg_stat_monitor...");
return ($cmdret, $stdout, $stderr);
}
sub pgsm_reset_pg_stat_monitor
{
# Run required commands/queries and dump output to out file.
($cmdret, $stdout, $stderr) = $pg_node->psql('postgres', 'SELECT pg_stat_monitor_reset();', extra_params => ['-a', '-Pformat=aligned','-Ptuples_only=off']);
ok($cmdret == 0, "Reset pg_stat_monitor...");
return ($cmdret, $stdout, $stderr);
}
sub pgsm_drop_extension
{
my ($cmdret, $stdout) = $pg_node->safe_psql('postgres', 'Drop extension pg_stat_monitor;', extra_params => ['-a']);
ok($cmdret == 0, "DROP EXTENSION pg_stat_monitor...");
return ($cmdret, $stdout, $stderr);
}
1;
1;