From 5e45211a64149b3c659b90ff2de6fa982a5a93ed Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 4 May 2024 14:17:33 +0200 Subject: Adding upstream version 15.5. Signed-off-by: Daniel Baumann --- src/bin/scripts/t/010_clusterdb.pl | 38 ++++++ src/bin/scripts/t/011_clusterdb_all.pl | 38 ++++++ src/bin/scripts/t/020_createdb.pl | 161 ++++++++++++++++++++++++ src/bin/scripts/t/040_createuser.pl | 39 ++++++ src/bin/scripts/t/050_dropdb.pl | 43 +++++++ src/bin/scripts/t/070_dropuser.pl | 28 +++++ src/bin/scripts/t/080_pg_isready.pl | 25 ++++ src/bin/scripts/t/090_reindexdb.pl | 202 +++++++++++++++++++++++++++++++ src/bin/scripts/t/091_reindexdb_all.pl | 35 ++++++ src/bin/scripts/t/100_vacuumdb.pl | 150 +++++++++++++++++++++++ src/bin/scripts/t/101_vacuumdb_all.pl | 33 +++++ src/bin/scripts/t/102_vacuumdb_stages.pl | 40 ++++++ src/bin/scripts/t/200_connstr.pl | 44 +++++++ 13 files changed, 876 insertions(+) create mode 100644 src/bin/scripts/t/010_clusterdb.pl create mode 100644 src/bin/scripts/t/011_clusterdb_all.pl create mode 100644 src/bin/scripts/t/020_createdb.pl create mode 100644 src/bin/scripts/t/040_createuser.pl create mode 100644 src/bin/scripts/t/050_dropdb.pl create mode 100644 src/bin/scripts/t/070_dropuser.pl create mode 100644 src/bin/scripts/t/080_pg_isready.pl create mode 100644 src/bin/scripts/t/090_reindexdb.pl create mode 100644 src/bin/scripts/t/091_reindexdb_all.pl create mode 100644 src/bin/scripts/t/100_vacuumdb.pl create mode 100644 src/bin/scripts/t/101_vacuumdb_all.pl create mode 100644 src/bin/scripts/t/102_vacuumdb_stages.pl create mode 100644 src/bin/scripts/t/200_connstr.pl (limited to 'src/bin/scripts/t') diff --git a/src/bin/scripts/t/010_clusterdb.pl b/src/bin/scripts/t/010_clusterdb.pl new file mode 100644 index 0000000..3d9abbb --- /dev/null +++ b/src/bin/scripts/t/010_clusterdb.pl @@ -0,0 +1,38 @@ + +# Copyright (c) 2021-2022, PostgreSQL Global Development Group + +use strict; +use warnings; + +use PostgreSQL::Test::Cluster; +use PostgreSQL::Test::Utils; +use Test::More; + +program_help_ok('clusterdb'); +program_version_ok('clusterdb'); +program_options_handling_ok('clusterdb'); + +my $node = PostgreSQL::Test::Cluster->new('main'); +$node->init; +$node->start; + +$node->issues_sql_like( + ['clusterdb'], + qr/statement: CLUSTER;/, + 'SQL CLUSTER run'); + +$node->command_fails([ 'clusterdb', '-t', 'nonexistent' ], + 'fails with nonexistent table'); + +$node->safe_psql('postgres', + 'CREATE TABLE test1 (a int); CREATE INDEX test1x ON test1 (a); CLUSTER test1 USING test1x' +); +$node->issues_sql_like( + [ 'clusterdb', '-t', 'test1' ], + qr/statement: CLUSTER public\.test1;/, + 'cluster specific table'); + +$node->command_ok([qw(clusterdb --echo --verbose dbname=template1)], + 'clusterdb with connection string'); + +done_testing(); diff --git a/src/bin/scripts/t/011_clusterdb_all.pl b/src/bin/scripts/t/011_clusterdb_all.pl new file mode 100644 index 0000000..7a209cf --- /dev/null +++ b/src/bin/scripts/t/011_clusterdb_all.pl @@ -0,0 +1,38 @@ + +# Copyright (c) 2021-2022, 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->start; + +# clusterdb -a is not compatible with -d, hence enforce environment variable +# correctly. +$ENV{PGDATABASE} = 'postgres'; + +$node->issues_sql_like( + [ 'clusterdb', '-a' ], + qr/statement: CLUSTER.*statement: CLUSTER/s, + 'cluster all databases'); + +$node->safe_psql( + 'postgres', q( + CREATE DATABASE regression_invalid; + UPDATE pg_database SET datconnlimit = -2 WHERE datname = 'regression_invalid'; +)); +$node->command_ok([ 'clusterdb', '-a' ], + 'invalid database not targeted by clusterdb -a'); + +# Doesn't quite belong here, but don't want to waste time by creating an +# invalid database in 010_clusterdb.pl as well. +$node->command_fails_like([ 'clusterdb', '-d', 'regression_invalid'], + qr/FATAL: cannot connect to invalid database "regression_invalid"/, + 'clusterdb cannot target invalid database'); + +done_testing(); diff --git a/src/bin/scripts/t/020_createdb.pl b/src/bin/scripts/t/020_createdb.pl new file mode 100644 index 0000000..2e712f4 --- /dev/null +++ b/src/bin/scripts/t/020_createdb.pl @@ -0,0 +1,161 @@ + +# Copyright (c) 2021-2022, PostgreSQL Global Development Group + +use strict; +use warnings; + +use PostgreSQL::Test::Cluster; +use PostgreSQL::Test::Utils; +use Test::More; + +program_help_ok('createdb'); +program_version_ok('createdb'); +program_options_handling_ok('createdb'); + +my $node = PostgreSQL::Test::Cluster->new('main'); +$node->init; +$node->start; + +$node->issues_sql_like( + [ 'createdb', 'foobar1' ], + qr/statement: CREATE DATABASE foobar1/, + 'SQL CREATE DATABASE run'); +$node->issues_sql_like( + [ 'createdb', '-l', 'C', '-E', 'LATIN1', '-T', 'template0', 'foobar2' ], + qr/statement: CREATE DATABASE foobar2 ENCODING 'LATIN1'/, + 'create database with encoding'); + +if ($ENV{with_icu} eq 'yes') +{ + # This fails because template0 uses libc provider and has no ICU + # locale set. It would succeed if template0 used the icu + # provider. XXX Maybe split into multiple tests? + $node->command_fails( + [ + 'createdb', '-T', 'template0', '-E', 'UTF8', + '--locale-provider=icu', 'foobar4' + ], + 'create database with ICU fails without ICU locale specified'); + + $node->issues_sql_like( + [ + 'createdb', '-T', + 'template0', '-E', 'UTF8', '--locale-provider=icu', + '--icu-locale=en', 'foobar5' + ], + qr/statement: CREATE DATABASE foobar5 .* LOCALE_PROVIDER icu ICU_LOCALE 'en'/, + 'create database with ICU locale specified'); + + $node->command_fails( + [ + 'createdb', '-T', 'template0', '-E', 'UTF8', + '--locale-provider=icu', + '--icu-locale=@colNumeric=lower', 'foobarX' + ], + 'fails for invalid ICU locale'); + + $node->command_fails_like( + [ + 'createdb', '-T', + 'template0', '--locale-provider=icu', + '--encoding=SQL_ASCII', 'foobarX' + ], + qr/ERROR: encoding "SQL_ASCII" is not supported with ICU provider/, + 'fails for encoding not supported by ICU'); + + # additional node, which uses the icu provider + my $node2 = PostgreSQL::Test::Cluster->new('icu'); + $node2->init(extra => ['--locale-provider=icu', '--icu-locale=en']); + $node2->start; + + $node2->command_ok( + [ 'createdb', '-T', 'template0', '--locale-provider=libc', 'foobar55' ], + 'create database with libc provider from template database with icu provider'); + + $node2->command_ok( + [ 'createdb', '-T', 'template0', '--icu-locale', 'en-US', 'foobar56' ], + 'create database with icu locale from template database with icu provider'); +} +else +{ + $node->command_fails( + [ 'createdb', '-T', 'template0', '--locale-provider=icu', 'foobar4' ], + 'create database with ICU fails since no ICU support'); +} + +$node->command_fails([ 'createdb', 'foobar1' ], + 'fails if database already exists'); + +$node->command_fails( + [ 'createdb', '-T', 'template0', '--locale-provider=xyz', 'foobarX' ], + 'fails for invalid locale provider'); + +# Check use of templates with shared dependencies copied from the template. +my ($ret, $stdout, $stderr) = $node->psql( + 'foobar2', + 'CREATE ROLE role_foobar; +CREATE TABLE tab_foobar (id int); +ALTER TABLE tab_foobar owner to role_foobar; +CREATE POLICY pol_foobar ON tab_foobar FOR ALL TO role_foobar;'); +$node->issues_sql_like( + [ 'createdb', '-l', 'C', '-T', 'foobar2', 'foobar3' ], + qr/statement: CREATE DATABASE foobar3 TEMPLATE foobar2/, + 'create database with template'); +($ret, $stdout, $stderr) = $node->psql( + 'foobar3', + "SELECT pg_describe_object(classid, objid, objsubid) AS obj, + pg_describe_object(refclassid, refobjid, 0) AS refobj + FROM pg_shdepend s JOIN pg_database d ON (d.oid = s.dbid) + WHERE d.datname = 'foobar3' ORDER BY obj;", on_error_die => 1); +chomp($stdout); +like( + $stdout, + qr/^policy pol_foobar on table tab_foobar\|role role_foobar +table tab_foobar\|role role_foobar$/, + 'shared dependencies copied over to target database'); + +# Check quote handling with incorrect option values. +$node->command_checks_all( + [ 'createdb', '--encoding', "foo'; SELECT '1", 'foobar2' ], + 1, + [qr/^$/], + [qr/^createdb: error: "foo'; SELECT '1" is not a valid encoding name/s], + 'createdb with incorrect --encoding'); +$node->command_checks_all( + [ 'createdb', '--lc-collate', "foo'; SELECT '1", 'foobar2' ], + 1, + [qr/^$/], + [ + qr/^createdb: error: database creation failed: ERROR: invalid locale name|^createdb: error: database creation failed: ERROR: new collation \(foo'; SELECT '1\) is incompatible with the collation of the template database/s + ], + 'createdb with incorrect --lc-collate'); +$node->command_checks_all( + [ 'createdb', '--lc-ctype', "foo'; SELECT '1", 'foobar2' ], + 1, + [qr/^$/], + [ + qr/^createdb: error: database creation failed: ERROR: invalid locale name|^createdb: error: database creation failed: ERROR: new LC_CTYPE \(foo'; SELECT '1\) is incompatible with the LC_CTYPE of the template database/s + ], + 'createdb with incorrect --lc-ctype'); + +$node->command_checks_all( + [ 'createdb', '--strategy', "foo", 'foobar2' ], + 1, + [qr/^$/], + [ + qr/^createdb: error: database creation failed: ERROR: invalid create database strategy "foo"/s + ], + 'createdb with incorrect --strategy'); + +# Check database creation strategy +$node->issues_sql_like( + [ 'createdb', '-T', 'foobar2', '-S', 'wal_log', 'foobar6' ], + qr/statement: CREATE DATABASE foobar6 STRATEGY wal_log TEMPLATE foobar2/, + 'create database with WAL_LOG strategy'); + +$node->issues_sql_like( + [ 'createdb', '-T', 'foobar2', '-S', 'file_copy', 'foobar7' ], + qr/statement: CREATE DATABASE foobar7 STRATEGY file_copy TEMPLATE foobar2/, + 'create database with FILE_COPY strategy'); + +done_testing(); diff --git a/src/bin/scripts/t/040_createuser.pl b/src/bin/scripts/t/040_createuser.pl new file mode 100644 index 0000000..2a34be8 --- /dev/null +++ b/src/bin/scripts/t/040_createuser.pl @@ -0,0 +1,39 @@ + +# Copyright (c) 2021-2022, PostgreSQL Global Development Group + +use strict; +use warnings; + +use PostgreSQL::Test::Cluster; +use PostgreSQL::Test::Utils; +use Test::More; + +program_help_ok('createuser'); +program_version_ok('createuser'); +program_options_handling_ok('createuser'); + +my $node = PostgreSQL::Test::Cluster->new('main'); +$node->init; +$node->start; + +$node->issues_sql_like( + [ 'createuser', 'regress_user1' ], + qr/statement: CREATE ROLE regress_user1 NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN;/, + 'SQL CREATE USER run'); +$node->issues_sql_like( + [ 'createuser', '-L', 'regress_role1' ], + qr/statement: CREATE ROLE regress_role1 NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT NOLOGIN;/, + 'create a non-login role'); +$node->issues_sql_like( + [ 'createuser', '-r', 'regress_user2' ], + qr/statement: CREATE ROLE regress_user2 NOSUPERUSER NOCREATEDB CREATEROLE INHERIT LOGIN;/, + 'create a CREATEROLE user'); +$node->issues_sql_like( + [ 'createuser', '-s', 'regress_user3' ], + qr/statement: CREATE ROLE regress_user3 SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN;/, + 'create a superuser'); + +$node->command_fails([ 'createuser', 'regress_user1' ], + 'fails if role already exists'); + +done_testing(); diff --git a/src/bin/scripts/t/050_dropdb.pl b/src/bin/scripts/t/050_dropdb.pl new file mode 100644 index 0000000..1ca9ab8 --- /dev/null +++ b/src/bin/scripts/t/050_dropdb.pl @@ -0,0 +1,43 @@ + +# Copyright (c) 2021-2022, PostgreSQL Global Development Group + +use strict; +use warnings; + +use PostgreSQL::Test::Cluster; +use PostgreSQL::Test::Utils; +use Test::More; + +program_help_ok('dropdb'); +program_version_ok('dropdb'); +program_options_handling_ok('dropdb'); + +my $node = PostgreSQL::Test::Cluster->new('main'); +$node->init; +$node->start; + +$node->safe_psql('postgres', 'CREATE DATABASE foobar1'); +$node->issues_sql_like( + [ 'dropdb', 'foobar1' ], + qr/statement: DROP DATABASE foobar1/, + 'SQL DROP DATABASE run'); + +$node->safe_psql('postgres', 'CREATE DATABASE foobar2'); +$node->issues_sql_like( + [ 'dropdb', '--force', 'foobar2' ], + qr/statement: DROP DATABASE foobar2 WITH \(FORCE\);/, + 'SQL DROP DATABASE (FORCE) run'); + +$node->command_fails([ 'dropdb', 'nonexistent' ], + 'fails with nonexistent database'); + +# check that invalid database can be dropped with dropdb +$node->safe_psql( + 'postgres', q( + CREATE DATABASE regression_invalid; + UPDATE pg_database SET datconnlimit = -2 WHERE datname = 'regression_invalid'; +)); +$node->command_ok([ 'dropdb', 'regression_invalid' ], + 'invalid database can be dropped'); + +done_testing(); diff --git a/src/bin/scripts/t/070_dropuser.pl b/src/bin/scripts/t/070_dropuser.pl new file mode 100644 index 0000000..e4eac21 --- /dev/null +++ b/src/bin/scripts/t/070_dropuser.pl @@ -0,0 +1,28 @@ + +# Copyright (c) 2021-2022, PostgreSQL Global Development Group + +use strict; +use warnings; + +use PostgreSQL::Test::Cluster; +use PostgreSQL::Test::Utils; +use Test::More; + +program_help_ok('dropuser'); +program_version_ok('dropuser'); +program_options_handling_ok('dropuser'); + +my $node = PostgreSQL::Test::Cluster->new('main'); +$node->init; +$node->start; + +$node->safe_psql('postgres', 'CREATE ROLE regress_foobar1'); +$node->issues_sql_like( + [ 'dropuser', 'regress_foobar1' ], + qr/statement: DROP ROLE regress_foobar1/, + 'SQL DROP ROLE run'); + +$node->command_fails([ 'dropuser', 'regress_nonexistent' ], + 'fails with nonexistent user'); + +done_testing(); diff --git a/src/bin/scripts/t/080_pg_isready.pl b/src/bin/scripts/t/080_pg_isready.pl new file mode 100644 index 0000000..c45ca66 --- /dev/null +++ b/src/bin/scripts/t/080_pg_isready.pl @@ -0,0 +1,25 @@ + +# Copyright (c) 2021-2022, PostgreSQL Global Development Group + +use strict; +use warnings; + +use PostgreSQL::Test::Cluster; +use PostgreSQL::Test::Utils; +use Test::More; + +program_help_ok('pg_isready'); +program_version_ok('pg_isready'); +program_options_handling_ok('pg_isready'); + +command_fails(['pg_isready'], 'fails with no server running'); + +my $node = PostgreSQL::Test::Cluster->new('main'); +$node->init; +$node->start; + +$node->command_ok( + [ 'pg_isready', "--timeout=$PostgreSQL::Test::Utils::timeout_default" ], + 'succeeds with server running'); + +done_testing(); diff --git a/src/bin/scripts/t/090_reindexdb.pl b/src/bin/scripts/t/090_reindexdb.pl new file mode 100644 index 0000000..398fc4e --- /dev/null +++ b/src/bin/scripts/t/090_reindexdb.pl @@ -0,0 +1,202 @@ + +# Copyright (c) 2021-2022, PostgreSQL Global Development Group + +use strict; +use warnings; + +use PostgreSQL::Test::Cluster; +use PostgreSQL::Test::Utils; +use Test::More; + +program_help_ok('reindexdb'); +program_version_ok('reindexdb'); +program_options_handling_ok('reindexdb'); + +my $node = PostgreSQL::Test::Cluster->new('main'); +$node->init; +$node->start; + +$ENV{PGOPTIONS} = '--client-min-messages=WARNING'; + +# Create a tablespace for testing. +my $tbspace_path = $node->basedir . '/regress_reindex_tbspace'; +mkdir $tbspace_path or die "cannot create directory $tbspace_path"; +my $tbspace_name = 'reindex_tbspace'; +$node->safe_psql('postgres', + "CREATE TABLESPACE $tbspace_name LOCATION '$tbspace_path';"); + +$node->issues_sql_like( + [ 'reindexdb', 'postgres' ], + qr/statement: REINDEX DATABASE postgres;/, + 'SQL REINDEX run'); + +# Use text as data type to get a toast table. +$node->safe_psql('postgres', + 'CREATE TABLE test1 (a text); CREATE INDEX test1x ON test1 (a);'); +# Collect toast table and index names of this relation, for later use. +my $toast_table = $node->safe_psql('postgres', + "SELECT reltoastrelid::regclass FROM pg_class WHERE oid = 'test1'::regclass;" +); +my $toast_index = $node->safe_psql('postgres', + "SELECT indexrelid::regclass FROM pg_index WHERE indrelid = '$toast_table'::regclass;" +); + +$node->issues_sql_like( + [ 'reindexdb', '-t', 'test1', 'postgres' ], + qr/statement: REINDEX TABLE public\.test1;/, + 'reindex specific table'); +$node->issues_sql_like( + [ 'reindexdb', '-t', 'test1', '--tablespace', $tbspace_name, 'postgres' ], + qr/statement: REINDEX \(TABLESPACE $tbspace_name\) TABLE public\.test1;/, + 'reindex specific table on tablespace'); +$node->issues_sql_like( + [ 'reindexdb', '-i', 'test1x', 'postgres' ], + qr/statement: REINDEX INDEX public\.test1x;/, + 'reindex specific index'); +$node->issues_sql_like( + [ 'reindexdb', '-S', 'pg_catalog', 'postgres' ], + qr/statement: REINDEX SCHEMA pg_catalog;/, + 'reindex specific schema'); +$node->issues_sql_like( + [ 'reindexdb', '-s', 'postgres' ], + qr/statement: REINDEX SYSTEM postgres;/, + 'reindex system tables'); +$node->issues_sql_like( + [ 'reindexdb', '-v', '-t', 'test1', 'postgres' ], + qr/statement: REINDEX \(VERBOSE\) TABLE public\.test1;/, + 'reindex with verbose output'); +$node->issues_sql_like( + [ + 'reindexdb', '-v', '-t', 'test1', + '--tablespace', $tbspace_name, 'postgres' + ], + qr/statement: REINDEX \(VERBOSE, TABLESPACE $tbspace_name\) TABLE public\.test1;/, + 'reindex with verbose output and tablespace'); + +# the same with --concurrently +$node->issues_sql_like( + [ 'reindexdb', '--concurrently', 'postgres' ], + qr/statement: REINDEX DATABASE CONCURRENTLY postgres;/, + 'SQL REINDEX CONCURRENTLY run'); + +$node->issues_sql_like( + [ 'reindexdb', '--concurrently', '-t', 'test1', 'postgres' ], + qr/statement: REINDEX TABLE CONCURRENTLY public\.test1;/, + 'reindex specific table concurrently'); +$node->issues_sql_like( + [ 'reindexdb', '--concurrently', '-i', 'test1x', 'postgres' ], + qr/statement: REINDEX INDEX CONCURRENTLY public\.test1x;/, + 'reindex specific index concurrently'); +$node->issues_sql_like( + [ 'reindexdb', '--concurrently', '-S', 'public', 'postgres' ], + qr/statement: REINDEX SCHEMA CONCURRENTLY public;/, + 'reindex specific schema concurrently'); +$node->command_fails([ 'reindexdb', '--concurrently', '-s', 'postgres' ], + 'reindex system tables concurrently'); +$node->issues_sql_like( + [ 'reindexdb', '--concurrently', '-v', '-t', 'test1', 'postgres' ], + qr/statement: REINDEX \(VERBOSE\) TABLE CONCURRENTLY public\.test1;/, + 'reindex with verbose output concurrently'); +$node->issues_sql_like( + [ + 'reindexdb', '--concurrently', '-v', '-t', + 'test1', '--tablespace', $tbspace_name, 'postgres' + ], + qr/statement: REINDEX \(VERBOSE, TABLESPACE $tbspace_name\) TABLE CONCURRENTLY public\.test1;/, + 'reindex concurrently with verbose output and tablespace'); + +# REINDEX TABLESPACE on toast indexes and tables fails. This is not +# part of the main regression test suite as these have unpredictable +# names, and CONCURRENTLY cannot be used in transaction blocks, preventing +# the use of TRY/CATCH blocks in a custom function to filter error +# messages. +$node->command_checks_all( + [ + 'reindexdb', '-t', $toast_table, '--tablespace', + $tbspace_name, 'postgres' + ], + 1, + [], + [qr/cannot move system relation/], + 'reindex toast table with tablespace'); +$node->command_checks_all( + [ + 'reindexdb', '--concurrently', '-t', $toast_table, + '--tablespace', $tbspace_name, 'postgres' + ], + 1, + [], + [qr/cannot move system relation/], + 'reindex toast table concurrently with tablespace'); +$node->command_checks_all( + [ + 'reindexdb', '-i', $toast_index, '--tablespace', + $tbspace_name, 'postgres' + ], + 1, + [], + [qr/cannot move system relation/], + 'reindex toast index with tablespace'); +$node->command_checks_all( + [ + 'reindexdb', '--concurrently', '-i', $toast_index, + '--tablespace', $tbspace_name, 'postgres' + ], + 1, + [], + [qr/cannot move system relation/], + 'reindex toast index concurrently with tablespace'); + +# connection strings +$node->command_ok([qw(reindexdb --echo --table=pg_am dbname=template1)], + 'reindexdb table with connection string'); +$node->command_ok( + [qw(reindexdb --echo dbname=template1)], + 'reindexdb database with connection string'); +$node->command_ok( + [qw(reindexdb --echo --system dbname=template1)], + 'reindexdb system with connection string'); + +# parallel processing +$node->safe_psql( + 'postgres', q| + CREATE SCHEMA s1; + CREATE TABLE s1.t1(id integer); + CREATE INDEX ON s1.t1(id); + CREATE SCHEMA s2; + CREATE TABLE s2.t2(id integer); + CREATE INDEX ON s2.t2(id); + -- empty schema + CREATE SCHEMA s3; +|); + +$node->command_fails( + [ 'reindexdb', '-j', '2', '-s', 'postgres' ], + 'parallel reindexdb cannot process system catalogs'); +$node->command_fails( + [ 'reindexdb', '-j', '2', '-i', 'i1', 'postgres' ], + 'parallel reindexdb cannot process indexes'); +$node->issues_sql_like( + [ 'reindexdb', '-j', '2', 'postgres' ], + qr/statement:\ REINDEX SYSTEM postgres; +.*statement:\ REINDEX TABLE public\.test1/s, + 'parallel reindexdb for database issues REINDEX SYSTEM first'); +# Note that the ordering of the commands is not stable, so the second +# command for s2.t2 is not checked after. +$node->issues_sql_like( + [ 'reindexdb', '-j', '2', '-S', 's1', '-S', 's2', 'postgres' ], + qr/statement:\ REINDEX TABLE s1.t1;/, + 'parallel reindexdb for schemas does a per-table REINDEX'); +$node->command_ok( + [ 'reindexdb', '-j', '2', '-S', 's3' ], + 'parallel reindexdb with empty schema'); +$node->command_checks_all( + [ 'reindexdb', '-j', '2', '--concurrently', '-d', 'postgres' ], + 0, + [qr/^$/], + [ + qr/^reindexdb: warning: cannot reindex system catalogs concurrently, skipping all/s + ], + 'parallel reindexdb for system with --concurrently skips catalogs'); + +done_testing(); diff --git a/src/bin/scripts/t/091_reindexdb_all.pl b/src/bin/scripts/t/091_reindexdb_all.pl new file mode 100644 index 0000000..b197ef9 --- /dev/null +++ b/src/bin/scripts/t/091_reindexdb_all.pl @@ -0,0 +1,35 @@ + +# Copyright (c) 2021-2022, PostgreSQL Global Development Group + +use strict; +use warnings; + +use PostgreSQL::Test::Cluster; +use Test::More; + +my $node = PostgreSQL::Test::Cluster->new('main'); +$node->init; +$node->start; + +$ENV{PGOPTIONS} = '--client-min-messages=WARNING'; + +$node->issues_sql_like( + [ 'reindexdb', '-a' ], + qr/statement: REINDEX.*statement: REINDEX/s, + 'reindex all databases'); + +$node->safe_psql( + 'postgres', q( + CREATE DATABASE regression_invalid; + UPDATE pg_database SET datconnlimit = -2 WHERE datname = 'regression_invalid'; +)); +$node->command_ok([ 'reindexdb', '-a' ], + 'invalid database not targeted by reindexdb -a'); + +# Doesn't quite belong here, but don't want to waste time by creating an +# invalid database in 090_reindexdb.pl as well. +$node->command_fails_like([ 'reindexdb', '-d', 'regression_invalid'], + qr/FATAL: cannot connect to invalid database "regression_invalid"/, + 'reindexdb cannot target invalid database'); + +done_testing(); diff --git a/src/bin/scripts/t/100_vacuumdb.pl b/src/bin/scripts/t/100_vacuumdb.pl new file mode 100644 index 0000000..96a818a --- /dev/null +++ b/src/bin/scripts/t/100_vacuumdb.pl @@ -0,0 +1,150 @@ + +# Copyright (c) 2021-2022, PostgreSQL Global Development Group + +use strict; +use warnings; + +use PostgreSQL::Test::Cluster; +use PostgreSQL::Test::Utils; +use Test::More; + +program_help_ok('vacuumdb'); +program_version_ok('vacuumdb'); +program_options_handling_ok('vacuumdb'); + +my $node = PostgreSQL::Test::Cluster->new('main'); +$node->init; +$node->start; + +$node->issues_sql_like( + [ 'vacuumdb', 'postgres' ], + qr/statement: VACUUM.*;/, + 'SQL VACUUM run'); +$node->issues_sql_like( + [ 'vacuumdb', '-f', 'postgres' ], + qr/statement: VACUUM \(FULL\).*;/, + 'vacuumdb -f'); +$node->issues_sql_like( + [ 'vacuumdb', '-F', 'postgres' ], + qr/statement: VACUUM \(FREEZE\).*;/, + 'vacuumdb -F'); +$node->issues_sql_like( + [ 'vacuumdb', '-zj2', 'postgres' ], + qr/statement: VACUUM \(ANALYZE\).*;/, + 'vacuumdb -zj2'); +$node->issues_sql_like( + [ 'vacuumdb', '-Z', 'postgres' ], + qr/statement: ANALYZE.*;/, + 'vacuumdb -Z'); +$node->issues_sql_like( + [ 'vacuumdb', '--disable-page-skipping', 'postgres' ], + qr/statement: VACUUM \(DISABLE_PAGE_SKIPPING\).*;/, + 'vacuumdb --disable-page-skipping'); +$node->issues_sql_like( + [ 'vacuumdb', '--skip-locked', 'postgres' ], + qr/statement: VACUUM \(SKIP_LOCKED\).*;/, + 'vacuumdb --skip-locked'); +$node->issues_sql_like( + [ 'vacuumdb', '--skip-locked', '--analyze-only', 'postgres' ], + qr/statement: ANALYZE \(SKIP_LOCKED\).*;/, + 'vacuumdb --skip-locked --analyze-only'); +$node->command_fails( + [ 'vacuumdb', '--analyze-only', '--disable-page-skipping', 'postgres' ], + '--analyze-only and --disable-page-skipping specified together'); +$node->issues_sql_like( + [ 'vacuumdb', '--no-index-cleanup', 'postgres' ], + qr/statement: VACUUM \(INDEX_CLEANUP FALSE\).*;/, + 'vacuumdb --no-index-cleanup'); +$node->command_fails( + [ 'vacuumdb', '--analyze-only', '--no-index-cleanup', 'postgres' ], + '--analyze-only and --no-index-cleanup specified together'); +$node->issues_sql_like( + [ 'vacuumdb', '--no-truncate', 'postgres' ], + qr/statement: VACUUM \(TRUNCATE FALSE\).*;/, + 'vacuumdb --no-truncate'); +$node->command_fails( + [ 'vacuumdb', '--analyze-only', '--no-truncate', 'postgres' ], + '--analyze-only and --no-truncate specified together'); +$node->issues_sql_like( + [ 'vacuumdb', '--no-process-toast', 'postgres' ], + qr/statement: VACUUM \(PROCESS_TOAST FALSE\).*;/, + 'vacuumdb --no-process-toast'); +$node->command_fails( + [ 'vacuumdb', '--analyze-only', '--no-process-toast', 'postgres' ], + '--analyze-only and --no-process-toast specified together'); +$node->issues_sql_like( + [ 'vacuumdb', '-P', 2, 'postgres' ], + qr/statement: VACUUM \(PARALLEL 2\).*;/, + 'vacuumdb -P 2'); +$node->issues_sql_like( + [ 'vacuumdb', '-P', 0, 'postgres' ], + qr/statement: VACUUM \(PARALLEL 0\).*;/, + 'vacuumdb -P 0'); +$node->command_ok([qw(vacuumdb -Z --table=pg_am dbname=template1)], + 'vacuumdb with connection string'); + +$node->command_fails( + [qw(vacuumdb -Zt pg_am;ABORT postgres)], + 'trailing command in "-t", without COLUMNS'); + +# Unwanted; better if it failed. +$node->command_ok( + [qw(vacuumdb -Zt pg_am(amname);ABORT postgres)], + 'trailing command in "-t", with COLUMNS'); + +$node->safe_psql( + 'postgres', q| + CREATE TABLE "need""q(uot" (")x" text); + CREATE TABLE vactable (a int, b int); + CREATE VIEW vacview AS SELECT 1 as a; + + CREATE FUNCTION f0(int) RETURNS int LANGUAGE SQL AS 'SELECT $1 * $1'; + CREATE FUNCTION f1(int) RETURNS int LANGUAGE SQL AS 'SELECT f0($1)'; + CREATE TABLE funcidx (x int); + INSERT INTO funcidx VALUES (0),(1),(2),(3); + CREATE INDEX i0 ON funcidx ((f1(x))); +|); +$node->command_ok([qw|vacuumdb -Z --table="need""q(uot"(")x") postgres|], + 'column list'); +$node->command_fails( + [qw|vacuumdb -Zt funcidx postgres|], + 'unqualifed name via functional index'); + +$node->command_fails( + [ 'vacuumdb', '--analyze', '--table', 'vactable(c)', 'postgres' ], + 'incorrect column name with ANALYZE'); +$node->command_fails([ 'vacuumdb', '-P', -1, 'postgres' ], + 'negative parallel degree'); +$node->issues_sql_like( + [ 'vacuumdb', '--analyze', '--table', 'vactable(a, b)', 'postgres' ], + qr/statement: VACUUM \(ANALYZE\) public.vactable\(a, b\);/, + 'vacuumdb --analyze with complete column list'); +$node->issues_sql_like( + [ 'vacuumdb', '--analyze-only', '--table', 'vactable(b)', 'postgres' ], + qr/statement: ANALYZE public.vactable\(b\);/, + 'vacuumdb --analyze-only with partial column list'); +$node->command_checks_all( + [ 'vacuumdb', '--analyze', '--table', 'vacview', 'postgres' ], + 0, + [qr/^.*vacuuming database "postgres"/], + [qr/^WARNING.*cannot vacuum non-tables or special system tables/s], + 'vacuumdb with view'); +$node->command_fails( + [ 'vacuumdb', '--table', 'vactable', '--min-mxid-age', '0', 'postgres' ], + 'vacuumdb --min-mxid-age with incorrect value'); +$node->command_fails( + [ 'vacuumdb', '--table', 'vactable', '--min-xid-age', '0', 'postgres' ], + 'vacuumdb --min-xid-age with incorrect value'); +$node->issues_sql_like( + [ + 'vacuumdb', '--table', 'vactable', '--min-mxid-age', + '2147483000', 'postgres' + ], + qr/GREATEST.*relminmxid.*2147483000/, + 'vacuumdb --table --min-mxid-age'); +$node->issues_sql_like( + [ 'vacuumdb', '--min-xid-age', '2147483001', 'postgres' ], + qr/GREATEST.*relfrozenxid.*2147483001/, + 'vacuumdb --table --min-xid-age'); + +done_testing(); diff --git a/src/bin/scripts/t/101_vacuumdb_all.pl b/src/bin/scripts/t/101_vacuumdb_all.pl new file mode 100644 index 0000000..d3fe59b --- /dev/null +++ b/src/bin/scripts/t/101_vacuumdb_all.pl @@ -0,0 +1,33 @@ + +# Copyright (c) 2021-2022, PostgreSQL Global Development Group + +use strict; +use warnings; + +use PostgreSQL::Test::Cluster; +use Test::More; + +my $node = PostgreSQL::Test::Cluster->new('main'); +$node->init; +$node->start; + +$node->issues_sql_like( + [ 'vacuumdb', '-a' ], + qr/statement: VACUUM.*statement: VACUUM/s, + 'vacuum all databases'); + +$node->safe_psql( + 'postgres', q( + CREATE DATABASE regression_invalid; + UPDATE pg_database SET datconnlimit = -2 WHERE datname = 'regression_invalid'; +)); +$node->command_ok([ 'vacuumdb', '-a' ], + 'invalid database not targeted by vacuumdb -a'); + +# Doesn't quite belong here, but don't want to waste time by creating an +# invalid database in 010_vacuumdb.pl as well. +$node->command_fails_like([ 'vacuumdb', '-d', 'regression_invalid'], + qr/FATAL: cannot connect to invalid database "regression_invalid"/, + 'vacuumdb cannot target invalid database'); + +done_testing(); diff --git a/src/bin/scripts/t/102_vacuumdb_stages.pl b/src/bin/scripts/t/102_vacuumdb_stages.pl new file mode 100644 index 0000000..caff3a3 --- /dev/null +++ b/src/bin/scripts/t/102_vacuumdb_stages.pl @@ -0,0 +1,40 @@ + +# Copyright (c) 2021-2022, PostgreSQL Global Development Group + +use strict; +use warnings; + +use PostgreSQL::Test::Cluster; +use Test::More; + +my $node = PostgreSQL::Test::Cluster->new('main'); +$node->init; +$node->start; + +$node->issues_sql_like( + [ 'vacuumdb', '--analyze-in-stages', 'postgres' ], + qr/statement:\ SET\ default_statistics_target=1;\ SET\ vacuum_cost_delay=0; + .*statement:\ ANALYZE + .*statement:\ SET\ default_statistics_target=10;\ RESET\ vacuum_cost_delay; + .*statement:\ ANALYZE + .*statement:\ RESET\ default_statistics_target; + .*statement:\ ANALYZE/sx, + 'analyze three times'); + +$node->issues_sql_like( + [ 'vacuumdb', '--analyze-in-stages', '--all' ], + qr/statement:\ SET\ default_statistics_target=1;\ SET\ vacuum_cost_delay=0; + .*statement:\ ANALYZE + .*statement:\ SET\ default_statistics_target=1;\ SET\ vacuum_cost_delay=0; + .*statement:\ ANALYZE + .*statement:\ SET\ default_statistics_target=10;\ RESET\ vacuum_cost_delay; + .*statement:\ ANALYZE + .*statement:\ SET\ default_statistics_target=10;\ RESET\ vacuum_cost_delay; + .*statement:\ ANALYZE + .*statement:\ RESET\ default_statistics_target; + .*statement:\ ANALYZE + .*statement:\ RESET\ default_statistics_target; + .*statement:\ ANALYZE/sx, + 'analyze more than one database in stages'); + +done_testing(); diff --git a/src/bin/scripts/t/200_connstr.pl b/src/bin/scripts/t/200_connstr.pl new file mode 100644 index 0000000..c865146 --- /dev/null +++ b/src/bin/scripts/t/200_connstr.pl @@ -0,0 +1,44 @@ + +# Copyright (c) 2021-2022, PostgreSQL Global Development Group + +use strict; +use warnings; + +use PostgreSQL::Test::Cluster; +use PostgreSQL::Test::Utils; +use Test::More; + +# Tests to check connection string handling in utilities + +# We're going to use byte sequences that aren't valid UTF-8 strings. Use +# LATIN1, which accepts any byte and has a conversion from each byte to UTF-8. +$ENV{LC_ALL} = 'C'; +$ENV{PGCLIENTENCODING} = 'LATIN1'; + +# Create database names covering the range of LATIN1 characters and +# run the utilities' --all options over them. +my $dbname1 = generate_ascii_string(1, 63); # contains '=' +my $dbname2 = + generate_ascii_string(67, 129); # skip 64-66 to keep length to 62 +my $dbname3 = generate_ascii_string(130, 192); +my $dbname4 = generate_ascii_string(193, 255); + +my $node = PostgreSQL::Test::Cluster->new('main'); +$node->init(extra => [ '--locale=C', '--encoding=LATIN1' ]); +$node->start; + +foreach my $dbname ($dbname1, $dbname2, $dbname3, $dbname4, 'CamelCase') +{ + $node->run_log([ 'createdb', $dbname ]); +} + +$node->command_ok( + [qw(vacuumdb --all --echo --analyze-only)], + 'vacuumdb --all with unusual database names'); +$node->command_ok([qw(reindexdb --all --echo)], + 'reindexdb --all with unusual database names'); +$node->command_ok( + [qw(clusterdb --all --echo --verbose)], + 'clusterdb --all with unusual database names'); + +done_testing(); -- cgit v1.2.3