12
12
*by PostgreSQL
13
13
*
14
14
* IDENTIFICATION
15
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.496 2008/07/18 03:32:52 tgl Exp $
15
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.497 2008/07/20 18:43:30 tgl Exp $
16
16
*
17
17
*-------------------------------------------------------------------------
18
18
*/
@@ -71,6 +71,7 @@ boolattrNames;/* put attr names into insert strings */
71
71
bool schemaOnly ;
72
72
bool dataOnly ;
73
73
bool aclsSkip ;
74
+ const char * lockWaitTimeout ;
74
75
75
76
/* subquery used to convert user ID (eg, datdba) to user name */
76
77
static const char * username_subquery ;
@@ -264,6 +265,7 @@ main(int argc, char **argv)
264
265
*/
265
266
{"disable-dollar-quoting" ,no_argument ,& disable_dollar_quoting ,1 },
266
267
{"disable-triggers" ,no_argument ,& disable_triggers ,1 },
268
+ {"lock-wait-timeout" ,required_argument ,NULL ,2 },
267
269
{"no-tablespaces" ,no_argument ,& outputNoTablespaces ,1 },
268
270
{"use-set-session-authorization" ,no_argument ,& use_setsessauth ,1 },
269
271
@@ -279,6 +281,7 @@ main(int argc, char **argv)
279
281
strcpy (g_opaque_type ,"opaque" );
280
282
281
283
dataOnly = schemaOnly = dumpInserts = attrNames = false;
284
+ lockWaitTimeout = NULL ;
282
285
283
286
progname = get_progname (argv [0 ]);
284
287
@@ -437,6 +440,11 @@ main(int argc, char **argv)
437
440
/* This covers the long options equivalent to -X xxx. */
438
441
break ;
439
442
443
+ case 2 :
444
+ /* lock-wait-timeout */
445
+ lockWaitTimeout = optarg ;
446
+ break ;
447
+
440
448
default :
441
449
fprintf (stderr ,_ ("Try \"%s --help\" for more information.\n" ),progname );
442
450
exit (1 );
@@ -754,12 +762,13 @@ help(const char *progname)
754
762
printf (_ (" %s [OPTION]... [DBNAME]\n" ),progname );
755
763
756
764
printf (_ ("\nGeneral options:\n" ));
757
- printf (_ (" -f, --file=FILENAME output file name\n" ));
758
- printf (_ (" -F, --format=c|t|p output file format (custom, tar, plain text)\n" ));
759
- printf (_ (" -v, --verbose verbose mode\n" ));
760
- printf (_ (" -Z, --compress=0-9 compression level for compressed formats\n" ));
761
- printf (_ (" --help show this help, then exit\n" ));
762
- printf (_ (" --version output version information, then exit\n" ));
765
+ printf (_ (" -f, --file=FILENAME output file name\n" ));
766
+ printf (_ (" -F, --format=c|t|p output file format (custom, tar, plain text)\n" ));
767
+ printf (_ (" -v, --verbose verbose mode\n" ));
768
+ printf (_ (" -Z, --compress=0-9 compression level for compressed formats\n" ));
769
+ printf (_ (" --lock-wait-timeout=TIMEOUT fail after waiting TIMEOUT for a table lock\n" ));
770
+ printf (_ (" --help show this help, then exit\n" ));
771
+ printf (_ (" --version output version information, then exit\n" ));
763
772
764
773
printf (_ ("\nOptions controlling the output content:\n" ));
765
774
printf (_ (" -a, --data-only dump only the data, not the schema\n" ));
@@ -2957,8 +2966,6 @@ getTables(int *numTables)
2957
2966
int ntups ;
2958
2967
int i ;
2959
2968
PQExpBuffer query = createPQExpBuffer ();
2960
- PQExpBuffer delqry = createPQExpBuffer ();
2961
- PQExpBuffer lockquery = createPQExpBuffer ();
2962
2969
TableInfo * tblinfo ;
2963
2970
int i_reltableoid ;
2964
2971
int i_reloid ;
@@ -3192,6 +3199,21 @@ getTables(int *numTables)
3192
3199
i_reltablespace = PQfnumber (res ,"reltablespace" );
3193
3200
i_reloptions = PQfnumber (res ,"reloptions" );
3194
3201
3202
+ if (lockWaitTimeout && g_fout -> remoteVersion >=70300 )
3203
+ {
3204
+ /*
3205
+ * Arrange to fail instead of waiting forever for a table lock.
3206
+ *
3207
+ * NB: this coding assumes that the only queries issued within
3208
+ * the following loop are LOCK TABLEs; else the timeout may be
3209
+ * undesirably applied to other things too.
3210
+ */
3211
+ resetPQExpBuffer (query );
3212
+ appendPQExpBuffer (query ,"SET statement_timeout = " );
3213
+ appendStringLiteralConn (query ,lockWaitTimeout ,g_conn );
3214
+ do_sql_command (g_conn ,query -> data );
3215
+ }
3216
+
3195
3217
for (i = 0 ;i < ntups ;i ++ )
3196
3218
{
3197
3219
tblinfo [i ].dobj .objType = DO_TABLE ;
@@ -3246,12 +3268,12 @@ getTables(int *numTables)
3246
3268
*/
3247
3269
if (tblinfo [i ].dobj .dump && tblinfo [i ].relkind == RELKIND_RELATION )
3248
3270
{
3249
- resetPQExpBuffer (lockquery );
3250
- appendPQExpBuffer (lockquery ,
3271
+ resetPQExpBuffer (query );
3272
+ appendPQExpBuffer (query ,
3251
3273
"LOCK TABLE %s IN ACCESS SHARE MODE" ,
3252
3274
fmtQualifiedId (tblinfo [i ].dobj .namespace -> dobj .name ,
3253
3275
tblinfo [i ].dobj .name ));
3254
- do_sql_command (g_conn ,lockquery -> data );
3276
+ do_sql_command (g_conn ,query -> data );
3255
3277
}
3256
3278
3257
3279
/* Emit notice if join for owner failed */
@@ -3260,6 +3282,11 @@ getTables(int *numTables)
3260
3282
tblinfo [i ].dobj .name );
3261
3283
}
3262
3284
3285
+ if (lockWaitTimeout && g_fout -> remoteVersion >=70300 )
3286
+ {
3287
+ do_sql_command (g_conn ,"SET statement_timeout = 0" );
3288
+ }
3289
+
3263
3290
PQclear (res );
3264
3291
3265
3292
/*
@@ -3292,8 +3319,6 @@ getTables(int *numTables)
3292
3319
}
3293
3320
3294
3321
destroyPQExpBuffer (query );
3295
- destroyPQExpBuffer (delqry );
3296
- destroyPQExpBuffer (lockquery );
3297
3322
3298
3323
return tblinfo ;
3299
3324
}