diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 12:15:05 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 12:15:05 +0000 |
commit | 46651ce6fe013220ed397add242004d764fc0153 (patch) | |
tree | 6e5299f990f88e60174a1d3ae6e48eedd2688b2b /src/bin/scripts/t | |
parent | Initial commit. (diff) | |
download | postgresql-14-upstream.tar.xz postgresql-14-upstream.zip |
Adding upstream version 14.5.upstream/14.5upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/bin/scripts/t')
-rw-r--r-- | src/bin/scripts/t/010_clusterdb.pl | 36 | ||||
-rw-r--r-- | src/bin/scripts/t/011_clusterdb_all.pl | 22 | ||||
-rw-r--r-- | src/bin/scripts/t/020_createdb.pl | 53 | ||||
-rw-r--r-- | src/bin/scripts/t/040_createuser.pl | 37 | ||||
-rw-r--r-- | src/bin/scripts/t/050_dropdb.pl | 32 | ||||
-rw-r--r-- | src/bin/scripts/t/070_dropuser.pl | 26 | ||||
-rw-r--r-- | src/bin/scripts/t/080_pg_isready.pl | 23 | ||||
-rw-r--r-- | src/bin/scripts/t/090_reindexdb.pl | 200 | ||||
-rw-r--r-- | src/bin/scripts/t/091_reindexdb_all.pl | 19 | ||||
-rw-r--r-- | src/bin/scripts/t/100_vacuumdb.pl | 148 | ||||
-rw-r--r-- | src/bin/scripts/t/101_vacuumdb_all.pl | 17 | ||||
-rw-r--r-- | src/bin/scripts/t/102_vacuumdb_stages.pl | 38 | ||||
-rw-r--r-- | src/bin/scripts/t/200_connstr.pl | 42 |
13 files changed, 693 insertions, 0 deletions
diff --git a/src/bin/scripts/t/010_clusterdb.pl b/src/bin/scripts/t/010_clusterdb.pl new file mode 100644 index 0000000..6d483be --- /dev/null +++ b/src/bin/scripts/t/010_clusterdb.pl @@ -0,0 +1,36 @@ + +# Copyright (c) 2021, PostgreSQL Global Development Group + +use strict; +use warnings; + +use PostgresNode; +use TestLib; +use Test::More tests => 14; + +program_help_ok('clusterdb'); +program_version_ok('clusterdb'); +program_options_handling_ok('clusterdb'); + +my $node = get_new_node('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'); 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..c7e8514 --- /dev/null +++ b/src/bin/scripts/t/011_clusterdb_all.pl @@ -0,0 +1,22 @@ + +# Copyright (c) 2021, PostgreSQL Global Development Group + +use strict; +use warnings; + +use PostgresNode; +use TestLib; +use Test::More tests => 2; + +my $node = get_new_node('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'); diff --git a/src/bin/scripts/t/020_createdb.pl b/src/bin/scripts/t/020_createdb.pl new file mode 100644 index 0000000..7261ebb --- /dev/null +++ b/src/bin/scripts/t/020_createdb.pl @@ -0,0 +1,53 @@ + +# Copyright (c) 2021, PostgreSQL Global Development Group + +use strict; +use warnings; + +use PostgresNode; +use TestLib; +use Test::More tests => 22; + +program_help_ok('createdb'); +program_version_ok('createdb'); +program_options_handling_ok('createdb'); + +my $node = get_new_node('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'); + +$node->command_fails([ 'createdb', 'foobar1' ], + 'fails if database already exists'); + +# 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'); diff --git a/src/bin/scripts/t/040_createuser.pl b/src/bin/scripts/t/040_createuser.pl new file mode 100644 index 0000000..8fdd32d --- /dev/null +++ b/src/bin/scripts/t/040_createuser.pl @@ -0,0 +1,37 @@ + +# Copyright (c) 2021, PostgreSQL Global Development Group + +use strict; +use warnings; + +use PostgresNode; +use TestLib; +use Test::More tests => 17; + +program_help_ok('createuser'); +program_version_ok('createuser'); +program_options_handling_ok('createuser'); + +my $node = get_new_node('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'); diff --git a/src/bin/scripts/t/050_dropdb.pl b/src/bin/scripts/t/050_dropdb.pl new file mode 100644 index 0000000..646cb4e --- /dev/null +++ b/src/bin/scripts/t/050_dropdb.pl @@ -0,0 +1,32 @@ + +# Copyright (c) 2021, PostgreSQL Global Development Group + +use strict; +use warnings; + +use PostgresNode; +use TestLib; +use Test::More tests => 13; + +program_help_ok('dropdb'); +program_version_ok('dropdb'); +program_options_handling_ok('dropdb'); + +my $node = get_new_node('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'); diff --git a/src/bin/scripts/t/070_dropuser.pl b/src/bin/scripts/t/070_dropuser.pl new file mode 100644 index 0000000..cbcb09b --- /dev/null +++ b/src/bin/scripts/t/070_dropuser.pl @@ -0,0 +1,26 @@ + +# Copyright (c) 2021, PostgreSQL Global Development Group + +use strict; +use warnings; + +use PostgresNode; +use TestLib; +use Test::More tests => 11; + +program_help_ok('dropuser'); +program_version_ok('dropuser'); +program_options_handling_ok('dropuser'); + +my $node = get_new_node('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'); 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..375f0fe --- /dev/null +++ b/src/bin/scripts/t/080_pg_isready.pl @@ -0,0 +1,23 @@ + +# Copyright (c) 2021, PostgreSQL Global Development Group + +use strict; +use warnings; + +use PostgresNode; +use TestLib; +use Test::More tests => 10; + +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 = get_new_node('main'); +$node->init; +$node->start; + +$node->command_ok( + [ 'pg_isready', "--timeout=$TestLib::timeout_default" ], + 'succeeds with server running'); diff --git a/src/bin/scripts/t/090_reindexdb.pl b/src/bin/scripts/t/090_reindexdb.pl new file mode 100644 index 0000000..8bdedcb --- /dev/null +++ b/src/bin/scripts/t/090_reindexdb.pl @@ -0,0 +1,200 @@ + +# Copyright (c) 2021, PostgreSQL Global Development Group + +use strict; +use warnings; + +use PostgresNode; +use TestLib; +use Test::More tests => 58; + +program_help_ok('reindexdb'); +program_version_ok('reindexdb'); +program_options_handling_ok('reindexdb'); + +my $node = get_new_node('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'); 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..299b198 --- /dev/null +++ b/src/bin/scripts/t/091_reindexdb_all.pl @@ -0,0 +1,19 @@ + +# Copyright (c) 2021, PostgreSQL Global Development Group + +use strict; +use warnings; + +use PostgresNode; +use Test::More tests => 2; + +my $node = get_new_node('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'); diff --git a/src/bin/scripts/t/100_vacuumdb.pl b/src/bin/scripts/t/100_vacuumdb.pl new file mode 100644 index 0000000..0addc97 --- /dev/null +++ b/src/bin/scripts/t/100_vacuumdb.pl @@ -0,0 +1,148 @@ + +# Copyright (c) 2021, PostgreSQL Global Development Group + +use strict; +use warnings; + +use PostgresNode; +use TestLib; +use Test::More tests => 58; + +program_help_ok('vacuumdb'); +program_version_ok('vacuumdb'); +program_options_handling_ok('vacuumdb'); + +my $node = get_new_node('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'); 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..504f252 --- /dev/null +++ b/src/bin/scripts/t/101_vacuumdb_all.pl @@ -0,0 +1,17 @@ + +# Copyright (c) 2021, PostgreSQL Global Development Group + +use strict; +use warnings; + +use PostgresNode; +use Test::More tests => 2; + +my $node = get_new_node('main'); +$node->init; +$node->start; + +$node->issues_sql_like( + [ 'vacuumdb', '-a' ], + qr/statement: VACUUM.*statement: VACUUM/s, + 'vacuum all databases'); 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..155c77e --- /dev/null +++ b/src/bin/scripts/t/102_vacuumdb_stages.pl @@ -0,0 +1,38 @@ + +# Copyright (c) 2021, PostgreSQL Global Development Group + +use strict; +use warnings; + +use PostgresNode; +use Test::More tests => 4; + +my $node = get_new_node('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'); diff --git a/src/bin/scripts/t/200_connstr.pl b/src/bin/scripts/t/200_connstr.pl new file mode 100644 index 0000000..b1ceab7 --- /dev/null +++ b/src/bin/scripts/t/200_connstr.pl @@ -0,0 +1,42 @@ + +# Copyright (c) 2021, PostgreSQL Global Development Group + +use strict; +use warnings; + +use PostgresNode; +use TestLib; +use Test::More tests => 3; + +# 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 = get_new_node('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'); |