summaryrefslogtreecommitdiffstats
path: root/contrib/pg_prewarm/t
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 13:44:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 13:44:03 +0000
commit293913568e6a7a86fd1479e1cff8e2ecb58d6568 (patch)
treefc3b469a3ec5ab71b36ea97cc7aaddb838423a0c /contrib/pg_prewarm/t
parentInitial commit. (diff)
downloadpostgresql-16-293913568e6a7a86fd1479e1cff8e2ecb58d6568.tar.xz
postgresql-16-293913568e6a7a86fd1479e1cff8e2ecb58d6568.zip
Adding upstream version 16.2.upstream/16.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'contrib/pg_prewarm/t')
-rw-r--r--contrib/pg_prewarm/t/001_basic.pl58
1 files changed, 58 insertions, 0 deletions
diff --git a/contrib/pg_prewarm/t/001_basic.pl b/contrib/pg_prewarm/t/001_basic.pl
new file mode 100644
index 0000000..6b7c869
--- /dev/null
+++ b/contrib/pg_prewarm/t/001_basic.pl
@@ -0,0 +1,58 @@
+
+# Copyright (c) 2021-2023, PostgreSQL Global Development Group
+
+use strict;
+use warnings;
+
+use PostgreSQL::Test::Cluster;
+use PostgreSQL::Test::Utils;
+use Test::More;
+
+
+my $node = PostgreSQL::Test::Cluster->new('main');
+
+$node->init;
+$node->append_conf(
+ 'postgresql.conf',
+ qq{shared_preload_libraries = 'pg_prewarm'
+ pg_prewarm.autoprewarm = true
+ pg_prewarm.autoprewarm_interval = 0});
+$node->start;
+
+# setup
+$node->safe_psql("postgres",
+ "CREATE EXTENSION pg_prewarm;\n"
+ . "CREATE TABLE test(c1 int);\n"
+ . "INSERT INTO test SELECT generate_series(1, 100);");
+
+# test read mode
+my $result =
+ $node->safe_psql("postgres", "SELECT pg_prewarm('test', 'read');");
+like($result, qr/^[1-9][0-9]*$/, 'read mode succeeded');
+
+# test buffer_mode
+$result =
+ $node->safe_psql("postgres", "SELECT pg_prewarm('test', 'buffer');");
+like($result, qr/^[1-9][0-9]*$/, 'buffer mode succeeded');
+
+# prefetch mode might or might not be available
+my ($cmdret, $stdout, $stderr) =
+ $node->psql("postgres", "SELECT pg_prewarm('test', 'prefetch');");
+ok( ( $stdout =~ qr/^[1-9][0-9]*$/
+ or $stderr =~ qr/prefetch is not supported by this build/),
+ 'prefetch mode succeeded');
+
+# test autoprewarm_dump_now()
+$result = $node->safe_psql("postgres", "SELECT autoprewarm_dump_now();");
+like($result, qr/^[1-9][0-9]*$/, 'autoprewarm_dump_now succeeded');
+
+# restart, to verify that auto prewarm actually works
+$node->restart;
+
+$node->wait_for_log(
+ "autoprewarm successfully prewarmed [1-9][0-9]* of [0-9]+ previously-loaded blocks"
+);
+
+$node->stop;
+
+done_testing();