2 # Copyright (c) 2021-2025, PostgreSQL Global Development Group
5 use warnings FATAL
=> 'all';
7 use PostgreSQL
::Test
::Cluster
;
8 use PostgreSQL
::Test
::Utils
;
11 program_help_ok
('dropdb');
12 program_version_ok
('dropdb');
13 program_options_handling_ok
('dropdb');
15 my $node = PostgreSQL
::Test
::Cluster
->new('main');
19 $node->safe_psql('postgres', 'CREATE DATABASE foobar1');
20 $node->issues_sql_like(
21 [ 'dropdb', 'foobar1' ],
22 qr/statement: DROP DATABASE foobar1/,
23 'SQL DROP DATABASE run');
25 $node->safe_psql('postgres', 'CREATE DATABASE foobar2');
26 $node->issues_sql_like(
27 [ 'dropdb', '--force', 'foobar2' ],
28 qr/statement: DROP DATABASE foobar2 WITH \(FORCE\);/,
29 'SQL DROP DATABASE (FORCE) run');
31 $node->command_fails_like(
32 [ 'dropdb', 'nonexistent' ],
33 qr/database "nonexistent" does not exist/,
34 'fails with nonexistent database');
36 # check that invalid database can be dropped with dropdb
39 CREATE DATABASE regression_invalid
;
40 UPDATE pg_database SET datconnlimit
= -2 WHERE datname
= 'regression_invalid';
42 $node->command_ok([ 'dropdb', 'regression_invalid' ],
43 'invalid database can be dropped');