Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit673a30f

Browse files
committed
Add a pg_dump option --lock-wait-timeout to allow failing the dump if unable
to acquire shared table locks within a specified amount of time.David Gould
1 parentb133ceb commit673a30f

File tree

2 files changed

+88
-47
lines changed

2 files changed

+88
-47
lines changed

‎doc/src/sgml/ref/pg_dump.sgml

Lines changed: 49 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/pg_dump.sgml,v 1.102 2008/04/13 03:49:21 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/pg_dump.sgml,v 1.103 2008/07/20 18:43:30 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -415,23 +415,6 @@ PostgreSQL documentation
415415
</listitem>
416416
</varlistentry>
417417

418-
<varlistentry>
419-
<term><option>--no-tablespaces</option></term>
420-
<listitem>
421-
<para>
422-
Do not output commands to select tablespaces.
423-
With this option, all objects will be created in whichever
424-
tablespace is the default during restore.
425-
</para>
426-
427-
<para>
428-
This option is only meaningful for the plain-text format. For
429-
the archive formats, you can specify the option when you
430-
call <command>pg_restore</command>.
431-
</para>
432-
</listitem>
433-
</varlistentry>
434-
435418
<varlistentry>
436419
<term><option>-s</option></term>
437420
<term><option>--schema-only</option></term>
@@ -550,15 +533,27 @@ PostgreSQL documentation
550533
</listitem>
551534
</varlistentry>
552535

536+
<varlistentry>
537+
<term><option>-Z <replaceable class="parameter">0..9</replaceable></option></term>
538+
<term><option>--compress=<replaceable class="parameter">0..9</replaceable></option></term>
539+
<listitem>
540+
<para>
541+
Specify the compression level to use in archive formats that
542+
support compression. (Currently only the custom archive
543+
format supports compression.)
544+
</para>
545+
</listitem>
546+
</varlistentry>
547+
553548
<varlistentry>
554549
<term><option>--disable-dollar-quoting</></term>
555550
<listitem>
556551
<para>
557552
This option disables the use of dollar quoting for function bodies,
558553
and forces them to be quoted using SQL standard string syntax.
559554
</para>
560-
</listitem>
561-
</varlistentry>
555+
</listitem>
556+
</varlistentry>
562557

563558
<varlistentry>
564559
<term><option>--disable-triggers</></term>
@@ -587,6 +582,39 @@ PostgreSQL documentation
587582
</listitem>
588583
</varlistentry>
589584

585+
<varlistentry>
586+
<term><option>--lock-wait-timeout=<replaceable class="parameter">timeout</replaceable></option></term>
587+
<listitem>
588+
<para>
589+
Do not wait forever to acquire shared table locks at the beginning of
590+
the dump. Instead fail if unable to lock a table within the specified
591+
<replaceable class="parameter">timeout</>. The timeout may be
592+
specified in any of the formats accepted by <command>SET
593+
statement_timeout</>. (Allowed values vary depending on the server
594+
version you are dumping from, but an integer number of milliseconds
595+
is accepted by all versions since 7.3. This option is ignored when
596+
dumping from a pre-7.3 server.)
597+
</para>
598+
</listitem>
599+
</varlistentry>
600+
601+
<varlistentry>
602+
<term><option>--no-tablespaces</option></term>
603+
<listitem>
604+
<para>
605+
Do not output commands to select tablespaces.
606+
With this option, all objects will be created in whichever
607+
tablespace is the default during restore.
608+
</para>
609+
610+
<para>
611+
This option is only meaningful for the plain-text format. For
612+
the archive formats, you can specify the option when you
613+
call <command>pg_restore</command>.
614+
</para>
615+
</listitem>
616+
</varlistentry>
617+
590618
<varlistentry>
591619
<term><option>--use-set-session-authorization</></term>
592620
<listitem>
@@ -601,18 +629,6 @@ PostgreSQL documentation
601629
</para>
602630
</listitem>
603631
</varlistentry>
604-
605-
<varlistentry>
606-
<term><option>-Z <replaceable class="parameter">0..9</replaceable></option></term>
607-
<term><option>--compress=<replaceable class="parameter">0..9</replaceable></option></term>
608-
<listitem>
609-
<para>
610-
Specify the compression level to use in archive formats that
611-
support compression. (Currently only the custom archive
612-
format supports compression.)
613-
</para>
614-
</listitem>
615-
</varlistentry>
616632
</variablelist>
617633
</para>
618634

@@ -663,7 +679,7 @@ PostgreSQL documentation
663679
<listitem>
664680
<para>
665681
Force <application>pg_dump</application> to prompt for a
666-
password before connecting to a database.
682+
password before connecting to a database.
667683
</para>
668684

669685
<para>

‎src/bin/pg_dump/pg_dump.c

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*by PostgreSQL
1313
*
1414
* 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 $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -71,6 +71,7 @@ boolattrNames;/* put attr names into insert strings */
7171
boolschemaOnly;
7272
booldataOnly;
7373
boolaclsSkip;
74+
constchar*lockWaitTimeout;
7475

7576
/* subquery used to convert user ID (eg, datdba) to user name */
7677
staticconstchar*username_subquery;
@@ -264,6 +265,7 @@ main(int argc, char **argv)
264265
*/
265266
{"disable-dollar-quoting",no_argument,&disable_dollar_quoting,1},
266267
{"disable-triggers",no_argument,&disable_triggers,1},
268+
{"lock-wait-timeout",required_argument,NULL,2},
267269
{"no-tablespaces",no_argument,&outputNoTablespaces,1},
268270
{"use-set-session-authorization",no_argument,&use_setsessauth,1},
269271

@@ -279,6 +281,7 @@ main(int argc, char **argv)
279281
strcpy(g_opaque_type,"opaque");
280282

281283
dataOnly=schemaOnly=dumpInserts=attrNames= false;
284+
lockWaitTimeout=NULL;
282285

283286
progname=get_progname(argv[0]);
284287

@@ -437,6 +440,11 @@ main(int argc, char **argv)
437440
/* This covers the long options equivalent to -X xxx. */
438441
break;
439442

443+
case2:
444+
/* lock-wait-timeout */
445+
lockWaitTimeout=optarg;
446+
break;
447+
440448
default:
441449
fprintf(stderr,_("Try \"%s --help\" for more information.\n"),progname);
442450
exit(1);
@@ -754,12 +762,13 @@ help(const char *progname)
754762
printf(_(" %s [OPTION]... [DBNAME]\n"),progname);
755763

756764
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"));
763772

764773
printf(_("\nOptions controlling the output content:\n"));
765774
printf(_(" -a, --data-only dump only the data, not the schema\n"));
@@ -2957,8 +2966,6 @@ getTables(int *numTables)
29572966
intntups;
29582967
inti;
29592968
PQExpBufferquery=createPQExpBuffer();
2960-
PQExpBufferdelqry=createPQExpBuffer();
2961-
PQExpBufferlockquery=createPQExpBuffer();
29622969
TableInfo*tblinfo;
29632970
inti_reltableoid;
29642971
inti_reloid;
@@ -3192,6 +3199,21 @@ getTables(int *numTables)
31923199
i_reltablespace=PQfnumber(res,"reltablespace");
31933200
i_reloptions=PQfnumber(res,"reloptions");
31943201

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+
31953217
for (i=0;i<ntups;i++)
31963218
{
31973219
tblinfo[i].dobj.objType=DO_TABLE;
@@ -3246,12 +3268,12 @@ getTables(int *numTables)
32463268
*/
32473269
if (tblinfo[i].dobj.dump&&tblinfo[i].relkind==RELKIND_RELATION)
32483270
{
3249-
resetPQExpBuffer(lockquery);
3250-
appendPQExpBuffer(lockquery,
3271+
resetPQExpBuffer(query);
3272+
appendPQExpBuffer(query,
32513273
"LOCK TABLE %s IN ACCESS SHARE MODE",
32523274
fmtQualifiedId(tblinfo[i].dobj.namespace->dobj.name,
32533275
tblinfo[i].dobj.name));
3254-
do_sql_command(g_conn,lockquery->data);
3276+
do_sql_command(g_conn,query->data);
32553277
}
32563278

32573279
/* Emit notice if join for owner failed */
@@ -3260,6 +3282,11 @@ getTables(int *numTables)
32603282
tblinfo[i].dobj.name);
32613283
}
32623284

3285+
if (lockWaitTimeout&&g_fout->remoteVersion >=70300)
3286+
{
3287+
do_sql_command(g_conn,"SET statement_timeout = 0");
3288+
}
3289+
32633290
PQclear(res);
32643291

32653292
/*
@@ -3292,8 +3319,6 @@ getTables(int *numTables)
32923319
}
32933320

32943321
destroyPQExpBuffer(query);
3295-
destroyPQExpBuffer(delqry);
3296-
destroyPQExpBuffer(lockquery);
32973322

32983323
returntblinfo;
32993324
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp