v10-0002-Add-disable-index-cleanup-option-to-vacuumdb.patch
text/x-patch
Filename: v10-0002-Add-disable-index-cleanup-option-to-vacuumdb.patch
Type: text/x-patch
Part: 1
Patch
Format: format-patch
Series: patch v10-0002
Subject: Add --disable-index-cleanup option to vacuumdb.
| File | + | − |
|---|---|---|
| doc/src/sgml/ref/vacuumdb.sgml | 15 | 0 |
| src/bin/scripts/t/100_vacuumdb.pl | 8 | 1 |
| src/bin/scripts/vacuumdb.c | 29 | 0 |
From 1beffb4775f1d4ab15dfd88730c733b0a6b10eb7 Mon Sep 17 00:00:00 2001
From: Masahiko Sawada <sawada.mshk@gmail.com>
Date: Fri, 1 Feb 2019 16:02:50 +0100
Subject: [PATCH v10 2/2] Add --disable-index-cleanup option to vacuumdb.
---
doc/src/sgml/ref/vacuumdb.sgml | 15 +++++++++++++++
src/bin/scripts/t/100_vacuumdb.pl | 9 ++++++++-
src/bin/scripts/vacuumdb.c | 29 +++++++++++++++++++++++++++++
3 files changed, 52 insertions(+), 1 deletion(-)
diff --git a/doc/src/sgml/ref/vacuumdb.sgml b/doc/src/sgml/ref/vacuumdb.sgml
index 41c7f3d..02d6e46 100644
--- a/doc/src/sgml/ref/vacuumdb.sgml
+++ b/doc/src/sgml/ref/vacuumdb.sgml
@@ -118,6 +118,21 @@ PostgreSQL documentation
</varlistentry>
<varlistentry>
+ <term><option>--disable-index-cleanup</option></term>
+ <listitem>
+ <para>
+ Disable index vacuuming and index cleanup.
+ </para>
+ <note>
+ <para>
+ This option is only available for servers running
+ <productname>PostgreSQL</productname> 12 and later.
+ </para>
+ </note>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
<term><option>-e</option></term>
<term><option>--echo</option></term>
<listitem>
diff --git a/src/bin/scripts/t/100_vacuumdb.pl b/src/bin/scripts/t/100_vacuumdb.pl
index 7f3a9b1..2b7cd18 100644
--- a/src/bin/scripts/t/100_vacuumdb.pl
+++ b/src/bin/scripts/t/100_vacuumdb.pl
@@ -3,7 +3,7 @@ use warnings;
use PostgresNode;
use TestLib;
-use Test::More tests => 44;
+use Test::More tests => 47;
program_help_ok('vacuumdb');
program_version_ok('vacuumdb');
@@ -38,6 +38,10 @@ $node->issues_sql_like(
qr/statement: VACUUM \(DISABLE_PAGE_SKIPPING\).*;/,
'vacuumdb --disable-page-skipping');
$node->issues_sql_like(
+ [ 'vacuumdb', '--disable-index-cleanup', 'postgres' ],
+ qr/statement: VACUUM \(INDEX_CLEANUP FALSE\).*;/,
+ 'vacuumdb --disable-index-cleanup');
+$node->issues_sql_like(
[ 'vacuumdb', '--skip-locked', 'postgres' ],
qr/statement: VACUUM \(SKIP_LOCKED\).*;/,
'vacuumdb --skip-locked');
@@ -48,6 +52,9 @@ $node->issues_sql_like(
$node->command_fails(
[ 'vacuumdb', '--analyze-only', '--disable-page-skipping', 'postgres' ],
'--analyze-only and --disable-page-skipping specified together');
+$node->command_fails(
+ [ 'vacuumdb', '--analyze-only', '--disable-index-cleanup', 'postgres' ],
+ '--analyze-only and --disable-index-cleanup specified together');
$node->command_ok([qw(vacuumdb -Z --table=pg_am dbname=template1)],
'vacuumdb with connection string');
diff --git a/src/bin/scripts/vacuumdb.c b/src/bin/scripts/vacuumdb.c
index 5ac41ea..c090ee7 100644
--- a/src/bin/scripts/vacuumdb.c
+++ b/src/bin/scripts/vacuumdb.c
@@ -42,6 +42,7 @@ typedef struct vacuumingOptions
bool full;
bool freeze;
bool disable_page_skipping;
+ bool disable_index_cleanup;
bool skip_locked;
int min_xid_age;
int min_mxid_age;
@@ -117,6 +118,7 @@ main(int argc, char *argv[])
{"skip-locked", no_argument, NULL, 5},
{"min-xid-age", required_argument, NULL, 6},
{"min-mxid-age", required_argument, NULL, 7},
+ {"disable-index-cleanup", no_argument, NULL, 8},
{NULL, 0, NULL, 0}
};
@@ -244,6 +246,11 @@ main(int argc, char *argv[])
exit(1);
}
break;
+ case 8:
+ {
+ vacopts.disable_index_cleanup = true;
+ break;
+ }
default:
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
exit(1);
@@ -288,6 +295,12 @@ main(int argc, char *argv[])
progname, "disable-page-skipping");
exit(1);
}
+ if (vacopts.disable_index_cleanup)
+ {
+ fprintf(stderr, _("%s: cannot use the \"%s\" option when performing only analyze\n"),
+ progname, "disable-index-cleanup");
+ exit(1);
+ }
/* allow 'and_analyze' with 'analyze_only' */
}
@@ -418,6 +431,14 @@ vacuum_one_database(const char *dbname, vacuumingOptions *vacopts,
exit(1);
}
+ if (vacopts->disable_index_cleanup && PQserverVersion(conn) < 120000)
+ {
+ PQfinish(conn);
+ fprintf(stderr, _("%s: cannot use the \"%s\" option on server versions older than PostgreSQL 12\n"),
+ progname, "disable-index-cleanup");
+ exit(1);
+ }
+
if (vacopts->skip_locked && PQserverVersion(conn) < 120000)
{
PQfinish(conn);
@@ -868,6 +889,13 @@ prepare_vacuum_command(PQExpBuffer sql, int serverVersion,
appendPQExpBuffer(sql, "%sDISABLE_PAGE_SKIPPING", sep);
sep = comma;
}
+ if (vacopts->disable_index_cleanup)
+ {
+ /* INDEX_CLEANUP is supported since 12 */
+ Assert(serverVersion >= 120000);
+ appendPQExpBuffer(sql, "%sINDEX_CLEANUP FALSE", sep);
+ sep = comma;
+ }
if (vacopts->skip_locked)
{
/* SKIP_LOCKED is supported since v12 */
@@ -1221,6 +1249,7 @@ help(const char *progname)
printf(_(" -a, --all vacuum all databases\n"));
printf(_(" -d, --dbname=DBNAME database to vacuum\n"));
printf(_(" --disable-page-skipping disable all page-skipping behavior\n"));
+ printf(_(" --disable-index-cleanup disable index vacuuming and index cleanup\n"));
printf(_(" -e, --echo show the commands being sent to the server\n"));
printf(_(" -f, --full do full vacuuming\n"));
printf(_(" -F, --freeze freeze row transaction information\n"));
--
1.8.3.1