| 1 |
|
| 2 |
# Copyright (c) 2021-2025, PostgreSQL Global Development Group |
| 3 |
|
| 4 |
use strict; |
| 5 |
use warnings FATAL => 'all'; |
| 6 |
|
| 7 |
use PostgreSQL::Test::Cluster; |
| 8 |
use PostgreSQL::Test::Utils; |
| 9 |
use Test::More; |
| 10 |
|
| 11 |
my $node = PostgreSQL::Test::Cluster->new('main'); |
| 12 |
$node->init; |
| 13 |
$node->start; |
| 14 |
|
| 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'); |
| 21 |
|
| 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'); |
| 29 |
|
| 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'); |
| 36 |
|
| 37 |
$node->safe_psql('postgres', |
| 38 |
'CREATE TABLE test1 (a int); CREATE INDEX test1x ON test1 (a); CLUSTER test1 USING test1x' |
| 39 |
); |
| 40 |
$node->safe_psql('template1', |
| 41 |
'CREATE TABLE test1 (a int); CREATE INDEX test1x ON test1 (a); CLUSTER test1 USING test1x' |
| 42 |
); |
| 43 |
$node->issues_sql_like( |
| 44 |
[ 'clusterdb', '--all', '--table' => 'test1' ], |
| 45 |
qr/statement: CLUSTER public\.test1/s, |
| 46 |
'cluster specific table in all databases'); |
| 47 |
|
| 48 |
done_testing(); |