Fix pgbench performance issue induced by commit af35fe501.
[pgsql.git] / src / bin / scripts / t / 011_clusterdb_all.pl
blobcf06c8c1f8e085f1e32505c2e70395e66b94ed5d
2 # Copyright (c) 2021-2025, PostgreSQL Global Development Group
4 use strict;
5 use warnings FATAL => 'all';
7 use PostgreSQL::Test::Cluster;
8 use PostgreSQL::Test::Utils;
9 use Test::More;
11 my $node = PostgreSQL::Test::Cluster->new('main');
12 $node->init;
13 $node->start;
15 # clusterdb -a is not compatible with -d. This relies on PGDATABASE to be
16 # set, something PostgreSQL::Test::Cluster does.
17 $node->issues_sql_like(
18 [ 'clusterdb', '--all' ],
19 qr/statement: CLUSTER.*statement: CLUSTER/s,
20 'cluster all databases');
22 $node->safe_psql(
23 'postgres', q(
24 CREATE DATABASE regression_invalid;
25 UPDATE pg_database SET datconnlimit = -2 WHERE datname = 'regression_invalid';
26 ));
27 $node->command_ok([ 'clusterdb', '--all' ],
28 'invalid database not targeted by clusterdb -a');
30 # Doesn't quite belong here, but don't want to waste time by creating an
31 # invalid database in 010_clusterdb.pl as well.
32 $node->command_fails_like(
33 [ 'clusterdb', '--dbname' => 'regression_invalid' ],
34 qr/FATAL: cannot connect to invalid database "regression_invalid"/,
35 'clusterdb cannot target invalid database');
37 $node->safe_psql('postgres',
38 'CREATE TABLE test1 (a int); CREATE INDEX test1x ON test1 (a); CLUSTER test1 USING test1x'
40 $node->safe_psql('template1',
41 'CREATE TABLE test1 (a int); CREATE INDEX test1x ON test1 (a); CLUSTER test1 USING test1x'
43 $node->issues_sql_like(
44 [ 'clusterdb', '--all', '--table' => 'test1' ],
45 qr/statement: CLUSTER public\.test1/s,
46 'cluster specific table in all databases');
48 done_testing();