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

Commit354e95d

Browse files
committed
Add --disable-page-skipping and --skip-locked to vacuumdb
DISABLE_PAGE_SKIPPING is available since v9.6, and SKIP_LOCKED sincev12. They lacked equivalents for vacuumdb, so this closes the gap.Author: Nathan BossartReviewed-by: Michael Paquier, Masahiko SawadaDiscussion:https://postgr.es/m/FFE5373C-E26A-495B-B5C8-911EC4A41C5E@amazon.com
1 parenta67212d commit354e95d

File tree

3 files changed

+126
-7
lines changed

3 files changed

+126
-7
lines changed

‎doc/src/sgml/ref/vacuumdb.sgml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,23 @@ PostgreSQL documentation
102102
</listitem>
103103
</varlistentry>
104104

105+
<varlistentry>
106+
<term><option>--disable-page-skipping</option></term>
107+
<listitem>
108+
<para>
109+
Disable all page-skipping behavior during processing based on
110+
the visibility map, similarly to the option
111+
<literal>DISABLE_PAGE_SKIPPING</literal> for <command>VACUUM</command>.
112+
</para>
113+
<note>
114+
<para>
115+
This option is only available for servers running
116+
<productname>PostgreSQL</productname> 9.6 and later.
117+
</para>
118+
</note>
119+
</listitem>
120+
</varlistentry>
121+
105122
<varlistentry>
106123
<term><option>-e</option></term>
107124
<term><option>--echo</option></term>
@@ -167,6 +184,21 @@ PostgreSQL documentation
167184
</listitem>
168185
</varlistentry>
169186

187+
<varlistentry>
188+
<term><option>--skip-locked</option></term>
189+
<listitem>
190+
<para>
191+
Skip relations that cannot be immediately locked for processing.
192+
</para>
193+
<note>
194+
<para>
195+
This option is only available for servers running
196+
<productname>PostgreSQL</productname> 12 and later.
197+
</para>
198+
</note>
199+
</listitem>
200+
</varlistentry>
201+
170202
<varlistentry>
171203
<term><option>-t <replaceable class="parameter">table</replaceable> [ (<replaceable class="parameter">column</replaceable> [,...]) ]</option></term>
172204
<term><option>--table=<replaceable class="parameter">table</replaceable> [ (<replaceable class="parameter">column</replaceable> [,...]) ]</option></term>

‎src/bin/scripts/t/100_vacuumdb.pl

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
use PostgresNode;
55
use TestLib;
6-
use Test::Moretests=>23;
6+
use Test::Moretests=>30;
77

88
program_help_ok('vacuumdb');
99
program_version_ok('vacuumdb');
@@ -33,6 +33,21 @@
3333
['vacuumdb','-Z','postgres' ],
3434
qr/statement: ANALYZE;/,
3535
'vacuumdb -Z');
36+
$node->issues_sql_like(
37+
['vacuumdb','--disable-page-skipping','postgres' ],
38+
qr/statement: VACUUM\(DISABLE_PAGE_SKIPPING\);/,
39+
'vacuumdb --disable-page-skipping');
40+
$node->issues_sql_like(
41+
['vacuumdb','--skip-locked','postgres' ],
42+
qr/statement: VACUUM\(SKIP_LOCKED\);/,
43+
'vacuumdb --skip-locked');
44+
$node->issues_sql_like(
45+
['vacuumdb','--skip-locked','--analyze-only','postgres' ],
46+
qr/statement: ANALYZE\(SKIP_LOCKED\);/,
47+
'vacuumdb --skip-locked --analyze-only');
48+
$node->command_fails(
49+
['vacuumdb','--analyze-only','--disable-page-skipping','postgres' ],
50+
'--analyze-only and --disable-page-skipping specified together');
3651
$node->command_ok([qw(vacuumdb -Z --table=pg_am dbname=template1)],
3752
'vacuumdb with connection string');
3853

‎src/bin/scripts/vacuumdb.c

Lines changed: 78 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ typedef struct vacuumingOptions
4040
booland_analyze;
4141
boolfull;
4242
boolfreeze;
43+
booldisable_page_skipping;
44+
boolskip_locked;
4345
}vacuumingOptions;
4446

4547

@@ -110,6 +112,8 @@ main(int argc, char *argv[])
110112
{"jobs",required_argument,NULL,'j'},
111113
{"maintenance-db",required_argument,NULL,2},
112114
{"analyze-in-stages",no_argument,NULL,3},
115+
{"disable-page-skipping",no_argument,NULL,4},
116+
{"skip-locked",no_argument,NULL,5},
113117
{NULL,0,NULL,0}
114118
};
115119

@@ -213,6 +217,12 @@ main(int argc, char *argv[])
213217
case3:
214218
analyze_in_stages=vacopts.analyze_only= true;
215219
break;
220+
case4:
221+
vacopts.disable_page_skipping= true;
222+
break;
223+
case5:
224+
vacopts.skip_locked= true;
225+
break;
216226
default:
217227
fprintf(stderr,_("Try \"%s --help\" for more information.\n"),progname);
218228
exit(1);
@@ -251,6 +261,12 @@ main(int argc, char *argv[])
251261
progname,"freeze");
252262
exit(1);
253263
}
264+
if (vacopts.disable_page_skipping)
265+
{
266+
fprintf(stderr,_("%s: cannot use the \"%s\" option when performing only analyze\n"),
267+
progname,"disable-page-skipping");
268+
exit(1);
269+
}
254270
/* allow 'and_analyze' with 'analyze_only' */
255271
}
256272

@@ -367,6 +383,22 @@ vacuum_one_database(const char *dbname, vacuumingOptions *vacopts,
367383
conn=connectDatabase(dbname,host,port,username,prompt_password,
368384
progname,echo, false, true);
369385

386+
if (vacopts->disable_page_skipping&&PQserverVersion(conn)<90600)
387+
{
388+
PQfinish(conn);
389+
fprintf(stderr,_("%s: cannot use the \"%s\" option on server versions older than PostgreSQL 9.6\n"),
390+
progname,"disable-page-skipping");
391+
exit(1);
392+
}
393+
394+
if (vacopts->skip_locked&&PQserverVersion(conn)<120000)
395+
{
396+
PQfinish(conn);
397+
fprintf(stderr,_("%s: cannot use the \"%s\" option on server versions older than PostgreSQL 12\n"),
398+
progname,"skip-locked");
399+
exit(1);
400+
}
401+
370402
if (!quiet)
371403
{
372404
if (stage!=ANALYZE_NO_STAGE)
@@ -630,23 +662,61 @@ prepare_vacuum_command(PQExpBuffer sql, PGconn *conn,
630662
booltable_pre_qualified,
631663
constchar*progname,boolecho)
632664
{
665+
constchar*paren=" (";
666+
constchar*comma=", ";
667+
constchar*sep=paren;
668+
633669
resetPQExpBuffer(sql);
634670

635671
if (vacopts->analyze_only)
636672
{
637673
appendPQExpBufferStr(sql,"ANALYZE");
638-
if (vacopts->verbose)
639-
appendPQExpBufferStr(sql," VERBOSE");
674+
675+
/* parenthesized grammar of ANALYZE is supported since v11 */
676+
if (PQserverVersion(conn) >=110000)
677+
{
678+
if (vacopts->skip_locked)
679+
{
680+
/* SKIP_LOCKED is supported since v12 */
681+
Assert(PQserverVersion(conn) >=120000);
682+
appendPQExpBuffer(sql,"%sSKIP_LOCKED",sep);
683+
sep=comma;
684+
}
685+
if (vacopts->verbose)
686+
{
687+
appendPQExpBuffer(sql,"%sVERBOSE",sep);
688+
sep=comma;
689+
}
690+
if (sep!=paren)
691+
appendPQExpBufferChar(sql,')');
692+
}
693+
else
694+
{
695+
if (vacopts->verbose)
696+
appendPQExpBufferStr(sql," VERBOSE");
697+
}
640698
}
641699
else
642700
{
643701
appendPQExpBufferStr(sql,"VACUUM");
702+
703+
/* parenthesized grammar of VACUUM is supported since v9.0 */
644704
if (PQserverVersion(conn) >=90000)
645705
{
646-
constchar*paren=" (";
647-
constchar*comma=", ";
648-
constchar*sep=paren;
649-
706+
if (vacopts->disable_page_skipping)
707+
{
708+
/* DISABLE_PAGE_SKIPPING is supported since v9.6 */
709+
Assert(PQserverVersion(conn) >=90600);
710+
appendPQExpBuffer(sql,"%sDISABLE_PAGE_SKIPPING",sep);
711+
sep=comma;
712+
}
713+
if (vacopts->skip_locked)
714+
{
715+
/* SKIP_LOCKED is supported since v12 */
716+
Assert(PQserverVersion(conn) >=120000);
717+
appendPQExpBuffer(sql,"%sSKIP_LOCKED",sep);
718+
sep=comma;
719+
}
650720
if (vacopts->full)
651721
{
652722
appendPQExpBuffer(sql,"%sFULL",sep);
@@ -1000,11 +1070,13 @@ help(const char *progname)
10001070
printf(_("\nOptions:\n"));
10011071
printf(_(" -a, --all vacuum all databases\n"));
10021072
printf(_(" -d, --dbname=DBNAME database to vacuum\n"));
1073+
printf(_(" --disable-page-skipping disable all page-skipping behavior\n"));
10031074
printf(_(" -e, --echo show the commands being sent to the server\n"));
10041075
printf(_(" -f, --full do full vacuuming\n"));
10051076
printf(_(" -F, --freeze freeze row transaction information\n"));
10061077
printf(_(" -j, --jobs=NUM use this many concurrent connections to vacuum\n"));
10071078
printf(_(" -q, --quiet don't write any messages\n"));
1079+
printf(_(" --skip-locked skip relations that cannot be immediately locked\n"));
10081080
printf(_(" -t, --table='TABLE[(COLUMNS)]' vacuum specific table(s) only\n"));
10091081
printf(_(" -v, --verbose write a lot of output\n"));
10101082
printf(_(" -V, --version output version information, then exit\n"));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp