index 3fbdb337164a16c1daee85c75649b17a405d2c1e..f79bbb9a85ae7766e0e75b4d4ac36ab96add29f2 100644 (file)
</listitem>
</varlistentry>
+ <varlistentry>
+ <term><option>-f</option></term>
+ <term><option>--force</option></term>
+ <listitem>
+ <para>
+ Attempt to terminate all existing connections to the target database
+ before dropping it. See <xref linkend="sql-dropdatabase"/> for more
+ information on this option.
+ </para>
+ </listitem>
+ </varlistentry>
+
<varlistentry>
<term><option>-V</option></term>
<term><option>--version</option></term>
index dacd8e5f1dcc9a60c6370c703d402591923f1e74..382bff907ac0762709aa74f458ec48770a871509 100644 (file)
{"interactive", no_argument, NULL, 'i'},
{"if-exists", no_argument, &if_exists, 1},
{"maintenance-db", required_argument, NULL, 2},
+ {"force", no_argument, NULL, 'f'},
{NULL, 0, NULL, 0}
};
enum trivalue prompt_password = TRI_DEFAULT;
bool echo = false;
bool interactive = false;
+ bool force = false;
PQExpBufferData sql;
handle_help_version_opts(argc, argv, "dropdb", help);
- while ((c = getopt_long(argc, argv, "h:p:U:wWei", long_options, &optindex)) != -1)
+ while ((c = getopt_long(argc, argv, "h:p:U:wWeif", long_options, &optindex)) != -1)
{
switch (c)
{
case 'i':
interactive = true;
break;
+ case 'f':
+ force = true;
+ break;
case 0:
/* this covers the long options */
break;
initPQExpBuffer(&sql);
- appendPQExpBuffer(&sql, "DROP DATABASE %s%s;",
- (if_exists ? "IF EXISTS " : ""), fmtId(dbname));
+ appendPQExpBuffer(&sql, "DROP DATABASE %s%s%s;",
+ (if_exists ? "IF EXISTS " : ""),
+ fmtId(dbname),
+ force ? " WITH (FORCE)" : "");
/* Avoid trying to drop postgres db while we are connected to it. */
if (maintenance_db == NULL && strcmp(dbname, "postgres") == 0)
printf(_("\nOptions:\n"));
printf(_(" -e, --echo show the commands being sent to the server\n"));
printf(_(" -i, --interactive prompt before deleting anything\n"));
+ printf(_(" -f, --force try to terminate other connections before dropping\n"));
printf(_(" -V, --version output version information, then exit\n"));
printf(_(" --if-exists don't report error if database doesn't exist\n"));
printf(_(" -?, --help show this help, then exit\n"));
index 25aa54a4ae4b2ee98872c67312214c85db10dad2..c51babe093fb48f264a4570b38612328bd29e36f 100644 (file)
use PostgresNode;
use TestLib;
-use Test::More tests => 11;
+use Test::More tests => 13;
program_help_ok('dropdb');
program_version_ok('dropdb');
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');