Add --disable-page-skipping and --skip-locked to vacuumdb
DISABLE_PAGE_SKIPPING is available since v9.6, and SKIP_LOCKED since v12. They lacked equivalents for vacuumdb, so this closes the gap. Author: Nathan Bossart Reviewed-by: Michael Paquier, Masahiko Sawada Discussion: https://postgr.es/m/FFE5373C-E26A-495B-B5C8-911EC4A41C5E@amazon.com
This commit is contained in:
parent
a67212de19
commit
354e95d1f2
@ -102,6 +102,23 @@ PostgreSQL documentation
|
|||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry>
|
||||||
|
<term><option>--disable-page-skipping</option></term>
|
||||||
|
<listitem>
|
||||||
|
<para>
|
||||||
|
Disable all page-skipping behavior during processing based on
|
||||||
|
the visibility map, similarly to the option
|
||||||
|
<literal>DISABLE_PAGE_SKIPPING</literal> for <command>VACUUM</command>.
|
||||||
|
</para>
|
||||||
|
<note>
|
||||||
|
<para>
|
||||||
|
This option is only available for servers running
|
||||||
|
<productname>PostgreSQL</productname> 9.6 and later.
|
||||||
|
</para>
|
||||||
|
</note>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
<term><option>-e</option></term>
|
<term><option>-e</option></term>
|
||||||
<term><option>--echo</option></term>
|
<term><option>--echo</option></term>
|
||||||
@ -167,6 +184,21 @@ PostgreSQL documentation
|
|||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry>
|
||||||
|
<term><option>--skip-locked</option></term>
|
||||||
|
<listitem>
|
||||||
|
<para>
|
||||||
|
Skip relations that cannot be immediately locked for processing.
|
||||||
|
</para>
|
||||||
|
<note>
|
||||||
|
<para>
|
||||||
|
This option is only available for servers running
|
||||||
|
<productname>PostgreSQL</productname> 12 and later.
|
||||||
|
</para>
|
||||||
|
</note>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
<term><option>-t <replaceable class="parameter">table</replaceable> [ (<replaceable class="parameter">column</replaceable> [,...]) ]</option></term>
|
<term><option>-t <replaceable class="parameter">table</replaceable> [ (<replaceable class="parameter">column</replaceable> [,...]) ]</option></term>
|
||||||
<term><option>--table=<replaceable class="parameter">table</replaceable> [ (<replaceable class="parameter">column</replaceable> [,...]) ]</option></term>
|
<term><option>--table=<replaceable class="parameter">table</replaceable> [ (<replaceable class="parameter">column</replaceable> [,...]) ]</option></term>
|
||||||
|
@ -3,7 +3,7 @@ use warnings;
|
|||||||
|
|
||||||
use PostgresNode;
|
use PostgresNode;
|
||||||
use TestLib;
|
use TestLib;
|
||||||
use Test::More tests => 23;
|
use Test::More tests => 30;
|
||||||
|
|
||||||
program_help_ok('vacuumdb');
|
program_help_ok('vacuumdb');
|
||||||
program_version_ok('vacuumdb');
|
program_version_ok('vacuumdb');
|
||||||
@ -33,6 +33,21 @@ $node->issues_sql_like(
|
|||||||
[ 'vacuumdb', '-Z', 'postgres' ],
|
[ 'vacuumdb', '-Z', 'postgres' ],
|
||||||
qr/statement: ANALYZE;/,
|
qr/statement: ANALYZE;/,
|
||||||
'vacuumdb -Z');
|
'vacuumdb -Z');
|
||||||
|
$node->issues_sql_like(
|
||||||
|
[ 'vacuumdb', '--disable-page-skipping', 'postgres' ],
|
||||||
|
qr/statement: VACUUM \(DISABLE_PAGE_SKIPPING\);/,
|
||||||
|
'vacuumdb --disable-page-skipping');
|
||||||
|
$node->issues_sql_like(
|
||||||
|
[ 'vacuumdb', '--skip-locked', 'postgres' ],
|
||||||
|
qr/statement: VACUUM \(SKIP_LOCKED\);/,
|
||||||
|
'vacuumdb --skip-locked');
|
||||||
|
$node->issues_sql_like(
|
||||||
|
[ 'vacuumdb', '--skip-locked', '--analyze-only', 'postgres' ],
|
||||||
|
qr/statement: ANALYZE \(SKIP_LOCKED\);/,
|
||||||
|
'vacuumdb --skip-locked --analyze-only');
|
||||||
|
$node->command_fails(
|
||||||
|
[ 'vacuumdb', '--analyze-only', '--disable-page-skipping', 'postgres' ],
|
||||||
|
'--analyze-only and --disable-page-skipping specified together');
|
||||||
$node->command_ok([qw(vacuumdb -Z --table=pg_am dbname=template1)],
|
$node->command_ok([qw(vacuumdb -Z --table=pg_am dbname=template1)],
|
||||||
'vacuumdb with connection string');
|
'vacuumdb with connection string');
|
||||||
|
|
||||||
|
@ -40,6 +40,8 @@ typedef struct vacuumingOptions
|
|||||||
bool and_analyze;
|
bool and_analyze;
|
||||||
bool full;
|
bool full;
|
||||||
bool freeze;
|
bool freeze;
|
||||||
|
bool disable_page_skipping;
|
||||||
|
bool skip_locked;
|
||||||
} vacuumingOptions;
|
} vacuumingOptions;
|
||||||
|
|
||||||
|
|
||||||
@ -110,6 +112,8 @@ main(int argc, char *argv[])
|
|||||||
{"jobs", required_argument, NULL, 'j'},
|
{"jobs", required_argument, NULL, 'j'},
|
||||||
{"maintenance-db", required_argument, NULL, 2},
|
{"maintenance-db", required_argument, NULL, 2},
|
||||||
{"analyze-in-stages", no_argument, NULL, 3},
|
{"analyze-in-stages", no_argument, NULL, 3},
|
||||||
|
{"disable-page-skipping", no_argument, NULL, 4},
|
||||||
|
{"skip-locked", no_argument, NULL, 5},
|
||||||
{NULL, 0, NULL, 0}
|
{NULL, 0, NULL, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -213,6 +217,12 @@ main(int argc, char *argv[])
|
|||||||
case 3:
|
case 3:
|
||||||
analyze_in_stages = vacopts.analyze_only = true;
|
analyze_in_stages = vacopts.analyze_only = true;
|
||||||
break;
|
break;
|
||||||
|
case 4:
|
||||||
|
vacopts.disable_page_skipping = true;
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
vacopts.skip_locked = true;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
|
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
|
||||||
exit(1);
|
exit(1);
|
||||||
@ -251,6 +261,12 @@ main(int argc, char *argv[])
|
|||||||
progname, "freeze");
|
progname, "freeze");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
if (vacopts.disable_page_skipping)
|
||||||
|
{
|
||||||
|
fprintf(stderr, _("%s: cannot use the \"%s\" option when performing only analyze\n"),
|
||||||
|
progname, "disable-page-skipping");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
/* allow 'and_analyze' with 'analyze_only' */
|
/* allow 'and_analyze' with 'analyze_only' */
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -367,6 +383,22 @@ vacuum_one_database(const char *dbname, vacuumingOptions *vacopts,
|
|||||||
conn = connectDatabase(dbname, host, port, username, prompt_password,
|
conn = connectDatabase(dbname, host, port, username, prompt_password,
|
||||||
progname, echo, false, true);
|
progname, echo, false, true);
|
||||||
|
|
||||||
|
if (vacopts->disable_page_skipping && PQserverVersion(conn) < 90600)
|
||||||
|
{
|
||||||
|
PQfinish(conn);
|
||||||
|
fprintf(stderr, _("%s: cannot use the \"%s\" option on server versions older than PostgreSQL 9.6\n"),
|
||||||
|
progname, "disable-page-skipping");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vacopts->skip_locked && PQserverVersion(conn) < 120000)
|
||||||
|
{
|
||||||
|
PQfinish(conn);
|
||||||
|
fprintf(stderr, _("%s: cannot use the \"%s\" option on server versions older than PostgreSQL 12\n"),
|
||||||
|
progname, "skip-locked");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
if (!quiet)
|
if (!quiet)
|
||||||
{
|
{
|
||||||
if (stage != ANALYZE_NO_STAGE)
|
if (stage != ANALYZE_NO_STAGE)
|
||||||
@ -630,23 +662,61 @@ prepare_vacuum_command(PQExpBuffer sql, PGconn *conn,
|
|||||||
bool table_pre_qualified,
|
bool table_pre_qualified,
|
||||||
const char *progname, bool echo)
|
const char *progname, bool echo)
|
||||||
{
|
{
|
||||||
|
const char *paren = " (";
|
||||||
|
const char *comma = ", ";
|
||||||
|
const char *sep = paren;
|
||||||
|
|
||||||
resetPQExpBuffer(sql);
|
resetPQExpBuffer(sql);
|
||||||
|
|
||||||
if (vacopts->analyze_only)
|
if (vacopts->analyze_only)
|
||||||
{
|
{
|
||||||
appendPQExpBufferStr(sql, "ANALYZE");
|
appendPQExpBufferStr(sql, "ANALYZE");
|
||||||
if (vacopts->verbose)
|
|
||||||
appendPQExpBufferStr(sql, " VERBOSE");
|
/* parenthesized grammar of ANALYZE is supported since v11 */
|
||||||
|
if (PQserverVersion(conn) >= 110000)
|
||||||
|
{
|
||||||
|
if (vacopts->skip_locked)
|
||||||
|
{
|
||||||
|
/* SKIP_LOCKED is supported since v12 */
|
||||||
|
Assert(PQserverVersion(conn) >= 120000);
|
||||||
|
appendPQExpBuffer(sql, "%sSKIP_LOCKED", sep);
|
||||||
|
sep = comma;
|
||||||
|
}
|
||||||
|
if (vacopts->verbose)
|
||||||
|
{
|
||||||
|
appendPQExpBuffer(sql, "%sVERBOSE", sep);
|
||||||
|
sep = comma;
|
||||||
|
}
|
||||||
|
if (sep != paren)
|
||||||
|
appendPQExpBufferChar(sql, ')');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (vacopts->verbose)
|
||||||
|
appendPQExpBufferStr(sql, " VERBOSE");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
appendPQExpBufferStr(sql, "VACUUM");
|
appendPQExpBufferStr(sql, "VACUUM");
|
||||||
|
|
||||||
|
/* parenthesized grammar of VACUUM is supported since v9.0 */
|
||||||
if (PQserverVersion(conn) >= 90000)
|
if (PQserverVersion(conn) >= 90000)
|
||||||
{
|
{
|
||||||
const char *paren = " (";
|
if (vacopts->disable_page_skipping)
|
||||||
const char *comma = ", ";
|
{
|
||||||
const char *sep = paren;
|
/* DISABLE_PAGE_SKIPPING is supported since v9.6 */
|
||||||
|
Assert(PQserverVersion(conn) >= 90600);
|
||||||
|
appendPQExpBuffer(sql, "%sDISABLE_PAGE_SKIPPING", sep);
|
||||||
|
sep = comma;
|
||||||
|
}
|
||||||
|
if (vacopts->skip_locked)
|
||||||
|
{
|
||||||
|
/* SKIP_LOCKED is supported since v12 */
|
||||||
|
Assert(PQserverVersion(conn) >= 120000);
|
||||||
|
appendPQExpBuffer(sql, "%sSKIP_LOCKED", sep);
|
||||||
|
sep = comma;
|
||||||
|
}
|
||||||
if (vacopts->full)
|
if (vacopts->full)
|
||||||
{
|
{
|
||||||
appendPQExpBuffer(sql, "%sFULL", sep);
|
appendPQExpBuffer(sql, "%sFULL", sep);
|
||||||
@ -1000,11 +1070,13 @@ help(const char *progname)
|
|||||||
printf(_("\nOptions:\n"));
|
printf(_("\nOptions:\n"));
|
||||||
printf(_(" -a, --all vacuum all databases\n"));
|
printf(_(" -a, --all vacuum all databases\n"));
|
||||||
printf(_(" -d, --dbname=DBNAME database to vacuum\n"));
|
printf(_(" -d, --dbname=DBNAME database to vacuum\n"));
|
||||||
|
printf(_(" --disable-page-skipping disable all page-skipping behavior\n"));
|
||||||
printf(_(" -e, --echo show the commands being sent to the server\n"));
|
printf(_(" -e, --echo show the commands being sent to the server\n"));
|
||||||
printf(_(" -f, --full do full vacuuming\n"));
|
printf(_(" -f, --full do full vacuuming\n"));
|
||||||
printf(_(" -F, --freeze freeze row transaction information\n"));
|
printf(_(" -F, --freeze freeze row transaction information\n"));
|
||||||
printf(_(" -j, --jobs=NUM use this many concurrent connections to vacuum\n"));
|
printf(_(" -j, --jobs=NUM use this many concurrent connections to vacuum\n"));
|
||||||
printf(_(" -q, --quiet don't write any messages\n"));
|
printf(_(" -q, --quiet don't write any messages\n"));
|
||||||
|
printf(_(" --skip-locked skip relations that cannot be immediately locked\n"));
|
||||||
printf(_(" -t, --table='TABLE[(COLUMNS)]' vacuum specific table(s) only\n"));
|
printf(_(" -t, --table='TABLE[(COLUMNS)]' vacuum specific table(s) only\n"));
|
||||||
printf(_(" -v, --verbose write a lot of output\n"));
|
printf(_(" -v, --verbose write a lot of output\n"));
|
||||||
printf(_(" -V, --version output version information, then exit\n"));
|
printf(_(" -V, --version output version information, then exit\n"));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user