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

Commit9550ea3

Browse files
committed
Add --no-index-cleanup and --no-truncate to vacuumdb.
Both INDEX_CLEANUP and TRUNCATE have been available since v12, and areenabled by default except if respectively vacuum_index_cleanup andvacuum_truncate are disabled for a given relation. This change addssupport for disabling these options from vacuumdb.Author: Nathan BossartReviewed-by: Michael Paquier, Masahiko SawadaDiscussion:https://postgr.es/m/6F7F17EF-B1F2-4681-8D03-BA96365717C0@amazon.com
1 parent14903f2 commit9550ea3

File tree

3 files changed

+102
-2
lines changed

3 files changed

+102
-2
lines changed

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,36 @@ PostgreSQL documentation
226226
</listitem>
227227
</varlistentry>
228228

229+
<varlistentry>
230+
<term><option>--no-index-cleanup</option></term>
231+
<listitem>
232+
<para>
233+
Do not remove index entries pointing to dead tuples.
234+
</para>
235+
<note>
236+
<para>
237+
This option is only available for servers running
238+
<productname>PostgreSQL</productname> 12 and later.
239+
</para>
240+
</note>
241+
</listitem>
242+
</varlistentry>
243+
244+
<varlistentry>
245+
<term><option>--no-truncate</option></term>
246+
<listitem>
247+
<para>
248+
Do not truncate empty pages at the end of the table.
249+
</para>
250+
<note>
251+
<para>
252+
This option is only available for servers running
253+
<productname>PostgreSQL</productname> 12 and later.
254+
</para>
255+
</note>
256+
</listitem>
257+
</varlistentry>
258+
229259
<varlistentry>
230260
<term><option>-P <replaceable class="parameter">parallel_degree</replaceable></option></term>
231261
<term><option>--parallel=<replaceable class="parameter">parallel_degree</replaceable></option></term>

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

Lines changed: 15 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=>49;
6+
use Test::Moretests=>55;
77

88
program_help_ok('vacuumdb');
99
program_version_ok('vacuumdb');
@@ -48,6 +48,20 @@
4848
$node->command_fails(
4949
['vacuumdb','--analyze-only','--disable-page-skipping','postgres' ],
5050
'--analyze-only and --disable-page-skipping specified together');
51+
$node->issues_sql_like(
52+
['vacuumdb','--no-index-cleanup','postgres' ],
53+
qr/statement: VACUUM\(INDEX_CLEANUP FALSE\).*;/,
54+
'vacuumdb --no-index-cleanup');
55+
$node->command_fails(
56+
['vacuumdb','--analyze-only','--no-index-cleanup','postgres' ],
57+
'--analyze-only and --no-index-cleanup specified together');
58+
$node->issues_sql_like(
59+
['vacuumdb','--no-truncate','postgres' ],
60+
qr/statement: VACUUM\(TRUNCATE FALSE\).*;/,
61+
'vacuumdb --no-truncate');
62+
$node->command_fails(
63+
['vacuumdb','--analyze-only','--no-truncate','postgres' ],
64+
'--analyze-only and --no-truncate specified together');
5165
$node->issues_sql_like(
5266
['vacuumdb','-P', 2,'postgres' ],
5367
qr/statement: VACUUM\(PARALLEL 2\).*;/,

‎src/bin/scripts/vacuumdb.c

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ typedef struct vacuumingOptions
3737
intmin_mxid_age;
3838
intparallel_workers;/* >= 0 indicates user specified the
3939
* parallel degree, otherwise -1 */
40+
booldo_index_cleanup;
41+
booldo_truncate;
4042
}vacuumingOptions;
4143

4244

@@ -96,6 +98,8 @@ main(int argc, char *argv[])
9698
{"skip-locked",no_argument,NULL,5},
9799
{"min-xid-age",required_argument,NULL,6},
98100
{"min-mxid-age",required_argument,NULL,7},
101+
{"no-index-cleanup",no_argument,NULL,8},
102+
{"no-truncate",no_argument,NULL,9},
99103
{NULL,0,NULL,0}
100104
};
101105

@@ -117,9 +121,11 @@ main(int argc, char *argv[])
117121
intconcurrentCons=1;
118122
inttbl_count=0;
119123

120-
/* initialize optionsto all false*/
124+
/* initialize options */
121125
memset(&vacopts,0,sizeof(vacopts));
122126
vacopts.parallel_workers=-1;
127+
vacopts.do_index_cleanup= true;
128+
vacopts.do_truncate= true;
123129

124130
pg_logging_init(argv[0]);
125131
progname=get_progname(argv[0]);
@@ -223,6 +229,12 @@ main(int argc, char *argv[])
223229
exit(1);
224230
}
225231
break;
232+
case8:
233+
vacopts.do_index_cleanup= false;
234+
break;
235+
case9:
236+
vacopts.do_truncate= false;
237+
break;
226238
default:
227239
fprintf(stderr,_("Try \"%s --help\" for more information.\n"),progname);
228240
exit(1);
@@ -267,6 +279,18 @@ main(int argc, char *argv[])
267279
"disable-page-skipping");
268280
exit(1);
269281
}
282+
if (!vacopts.do_index_cleanup)
283+
{
284+
pg_log_error("cannot use the \"%s\" option when performing only analyze",
285+
"no-index-cleanup");
286+
exit(1);
287+
}
288+
if (!vacopts.do_truncate)
289+
{
290+
pg_log_error("cannot use the \"%s\" option when performing only analyze",
291+
"no-truncate");
292+
exit(1);
293+
}
270294
/* allow 'and_analyze' with 'analyze_only' */
271295
}
272296

@@ -412,6 +436,22 @@ vacuum_one_database(const char *dbname, vacuumingOptions *vacopts,
412436
exit(1);
413437
}
414438

439+
if (!vacopts->do_index_cleanup&&PQserverVersion(conn)<120000)
440+
{
441+
PQfinish(conn);
442+
pg_log_error("cannot use the \"%s\" option on server versions older than PostgreSQL %s",
443+
"no-index-cleanup","12");
444+
exit(1);
445+
}
446+
447+
if (!vacopts->do_truncate&&PQserverVersion(conn)<120000)
448+
{
449+
PQfinish(conn);
450+
pg_log_error("cannot use the \"%s\" option on server versions older than PostgreSQL %s",
451+
"no-truncate","12");
452+
exit(1);
453+
}
454+
415455
if (vacopts->skip_locked&&PQserverVersion(conn)<120000)
416456
{
417457
PQfinish(conn);
@@ -832,6 +872,20 @@ prepare_vacuum_command(PQExpBuffer sql, int serverVersion,
832872
appendPQExpBuffer(sql,"%sDISABLE_PAGE_SKIPPING",sep);
833873
sep=comma;
834874
}
875+
if (!vacopts->do_index_cleanup)
876+
{
877+
/* INDEX_CLEANUP is supported since v12 */
878+
Assert(serverVersion >=120000);
879+
appendPQExpBuffer(sql,"%sINDEX_CLEANUP FALSE",sep);
880+
sep=comma;
881+
}
882+
if (!vacopts->do_truncate)
883+
{
884+
/* TRUNCATE is supported since v12 */
885+
Assert(serverVersion >=120000);
886+
appendPQExpBuffer(sql,"%sTRUNCATE FALSE",sep);
887+
sep=comma;
888+
}
835889
if (vacopts->skip_locked)
836890
{
837891
/* SKIP_LOCKED is supported since v12 */
@@ -930,6 +984,8 @@ help(const char *progname)
930984
printf(_(" -j, --jobs=NUM use this many concurrent connections to vacuum\n"));
931985
printf(_(" --min-mxid-age=MXID_AGE minimum multixact ID age of tables to vacuum\n"));
932986
printf(_(" --min-xid-age=XID_AGE minimum transaction ID age of tables to vacuum\n"));
987+
printf(_(" --no-index-cleanup don't remove index entries that point to dead tuples\n"));
988+
printf(_(" --no-truncate don't truncate empty pages at the end of the table\n"));
933989
printf(_(" -P, --parallel=PARALLEL_DEGREE use this many background workers for vacuum, if available\n"));
934990
printf(_(" -q, --quiet don't write any messages\n"));
935991
printf(_(" --skip-locked skip relations that cannot be immediately locked\n"));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp