@@ -34,6 +34,7 @@ main(int argc, char *argv[])
34
34
{"interactive" , no_argument , NULL , 'i' },
35
35
{"if-exists" , no_argument , & if_exists , 1 },
36
36
{"maintenance-db" , required_argument , NULL , 2 },
37
+ {"force" , no_argument , NULL , 'f' },
37
38
{NULL , 0 , NULL , 0 }
38
39
};
39
40
@@ -49,6 +50,7 @@ main(int argc, char *argv[])
49
50
enum trivalue prompt_password = TRI_DEFAULT ;
50
51
bool echo = false;
51
52
bool interactive = false;
53
+ bool force = false;
52
54
53
55
PQExpBufferData sql ;
54
56
@@ -61,7 +63,7 @@ main(int argc, char *argv[])
61
63
62
64
handle_help_version_opts (argc , argv , "dropdb" , help );
63
65
64
- while ((c = getopt_long (argc , argv , "h:p:U:wWei " , long_options , & optindex )) != -1 )
66
+ while ((c = getopt_long (argc , argv , "h:p:U:wWeif " , long_options , & optindex )) != -1 )
65
67
{
66
68
switch (c )
67
69
{
@@ -86,6 +88,9 @@ main(int argc, char *argv[])
86
88
case 'i' :
87
89
interactive = true;
88
90
break ;
91
+ case 'f' :
92
+ force = true;
93
+ break ;
89
94
case 0 :
90
95
/* this covers the long options */
91
96
break ;
@@ -123,8 +128,10 @@ main(int argc, char *argv[])
123
128
124
129
initPQExpBuffer (& sql );
125
130
126
- appendPQExpBuffer (& sql , "DROP DATABASE %s%s;" ,
127
- (if_exists ? "IF EXISTS " : "" ), fmtId (dbname ));
131
+ appendPQExpBuffer (& sql , "DROP DATABASE %s%s%s;" ,
132
+ (if_exists ? "IF EXISTS " : "" ),
133
+ fmtId (dbname ),
134
+ force ? " WITH (FORCE)" : "" );
128
135
129
136
/* Avoid trying to drop postgres db while we are connected to it. */
130
137
if (maintenance_db == NULL && strcmp (dbname , "postgres" ) == 0 )
@@ -159,6 +166,7 @@ help(const char *progname)
159
166
printf (_ ("\nOptions:\n" ));
160
167
printf (_ (" -e, --echo show the commands being sent to the server\n" ));
161
168
printf (_ (" -i, --interactive prompt before deleting anything\n" ));
169
+ printf (_ (" -f, --force try to terminate other connections before dropping\n" ));
162
170
printf (_ (" -V, --version output version information, then exit\n" ));
163
171
printf (_ (" --if-exists don't report error if database doesn't exist\n" ));
164
172
printf (_ (" -?, --help show this help, then exit\n" ));
0 commit comments