timescaledb/test/sql/test_tss_callbacks.sql
Fabrízio de Royes Mello 0f1983ef78 Add ts_stat_statements callbacks
Currently we finish the execution of some process utility statements
and don't execute other hooks in the chain.

Because that reason neither `ts_stat_statements` and
`pg_stat_statements` are able to track some utility statements, for
example COPY ... FROM.

To be able to track it on `ts_stat_statements` we're introducing some
callbacks in order to hook `pgss_store` from TimescaleDB and store
information about the execution of those statements.

In this PR we're also adding a new GUC `enable_tss_callbacks=true` to
enable or disable the ability to hook `ts_stat_statements` from
TimescaleDB.
2024-04-19 17:32:51 -03:00

47 lines
1.3 KiB
SQL

-- This file and its contents are licensed under the Apache License 2.0.
-- Please see the included NOTICE for copyright information and
-- LICENSE-APACHE for a copy of the license.
\c :TEST_DBNAME :ROLE_SUPERUSER
CREATE OR REPLACE FUNCTION test.setup_tss_hook_v0() RETURNS VOID
AS :MODULE_PATHNAME, 'ts_setup_tss_hook_v0' LANGUAGE C VOLATILE;
CREATE OR REPLACE FUNCTION test.setup_tss_hook_v1() RETURNS VOID
AS :MODULE_PATHNAME, 'ts_setup_tss_hook_v1' LANGUAGE C VOLATILE;
CREATE OR REPLACE FUNCTION test.teardown_tss_hook_v1() RETURNS VOID
AS :MODULE_PATHNAME, 'ts_teardown_tss_hook_v1' LANGUAGE C VOLATILE;
SELECT test.setup_tss_hook_v1();
CREATE TABLE copy_test (
"time" timestamptz NOT NULL,
"value" double precision NOT NULL
);
SELECT create_hypertable('copy_test', 'time');
-- We should se a mock message
COPY copy_test FROM STDIN DELIMITER ',';
2020-01-01 01:10:00+01,1
2021-01-01 01:10:00+01,1
\.
SELECT test.teardown_tss_hook_v1();
-- Without the hook registered we cannot see the mock message
COPY copy_test FROM STDIN DELIMITER ',';
2020-01-01 01:10:00+01,1
2021-01-01 01:10:00+01,1
\.
-- Test for mismatch version
SELECT test.setup_tss_hook_v0();
-- Warning because the mismatch versions
COPY copy_test FROM STDIN DELIMITER ',';
2020-01-01 01:10:00+01,1
2021-01-01 01:10:00+01,1
\.