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

Commitb859d94

Browse files
committed
Provide pg_amcheck with an --install-missing option
This will install amcheck in the database if not present. The defaultschema is for the extension is pg_catalog, but this can be overridden byproviding a value for the option.Mark Dilger, slightly editorialized by me.(rather divergent)Discussion:https://postgr.es/m/bdc0f7c2-09e3-ee57-8471-569dfb509234@dunslane.net
1 parentaa27120 commitb859d94

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

‎doc/src/sgml/ref/pg_amcheck.sgml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,23 @@ PostgreSQL documentation
217217
</listitem>
218218
</varlistentry>
219219

220+
<varlistentry>
221+
<term><option>--install-missing</option></term>
222+
<term><option>--install-missing=<replaceable class="parameter">schema</replaceable></option></term>
223+
<listitem>
224+
<para>
225+
Install any missing extensions that are required to check the
226+
database(s). If not yet installed, each extension's objects will be
227+
installed into the given
228+
<replaceable class="parameter">schema</replaceable>, or if not specified
229+
into schema <literal>pg_catalog</literal>.
230+
</para>
231+
<para>
232+
At present, the only required extension is <xref linkend="amcheck"/>.
233+
</para>
234+
</listitem>
235+
</varlistentry>
236+
220237
<varlistentry>
221238
<term><option>-j <replaceable class="parameter">num</replaceable></option></term>
222239
<term><option>--jobs=<replaceable class="parameter">num</replaceable></option></term>

‎src/bin/pg_amcheck/pg_amcheck.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ typedef struct AmcheckOptions
6161
boolshow_progress;
6262
intjobs;
6363

64+
/*
65+
* Whether to install missing extensions, and optionally the name of the
66+
* schema in which to install the extension's objects.
67+
*/
68+
boolinstall_missing;
69+
char*install_schema;
70+
6471
/* Objects to check or not to check, as lists of PatternInfo structs. */
6572
PatternInfoArrayinclude;
6673
PatternInfoArrayexclude;
@@ -109,6 +116,8 @@ static AmcheckOptions opts = {
109116
.strict_names= true,
110117
.show_progress= false,
111118
.jobs=1,
119+
.install_missing= false,
120+
.install_schema="pg_catalog",
112121
.include= {NULL,0},
113122
.exclude= {NULL,0},
114123
.excludetbl= false,
@@ -259,6 +268,7 @@ main(int argc, char *argv[])
259268
{"no-strict-names",no_argument,NULL,10},
260269
{"heapallindexed",no_argument,NULL,11},
261270
{"parent-check",no_argument,NULL,12},
271+
{"install-missing",optional_argument,NULL,13},
262272

263273
{NULL,0,NULL,0}
264274
};
@@ -435,6 +445,11 @@ main(int argc, char *argv[])
435445
case12:
436446
opts.parent_check= true;
437447
break;
448+
case13:
449+
opts.install_missing= true;
450+
if (optarg)
451+
opts.install_schema=pg_strdup(optarg);
452+
break;
438453
default:
439454
fprintf(stderr,
440455
_("Try \"%s --help\" for more information.\n"),
@@ -543,6 +558,29 @@ main(int argc, char *argv[])
543558
conn=connectDatabase(&cparams,progname,opts.echo, false, true);
544559
}
545560

561+
/*
562+
* Optionally install amcheck if not already installed in this
563+
* database.
564+
*/
565+
if (opts.install_missing)
566+
{
567+
char*schema;
568+
char*install_sql;
569+
570+
/*
571+
* Must re-escape the schema name for each database, as the
572+
* escaping rules may change.
573+
*/
574+
schema=PQescapeIdentifier(conn,opts.install_schema,
575+
strlen(opts.install_schema));
576+
install_sql=psprintf("CREATE EXTENSION IF NOT EXISTS amcheck WITH SCHEMA %s",
577+
schema);
578+
579+
executeCommand(conn,install_sql,opts.echo);
580+
pfree(install_sql);
581+
pfree(schema);
582+
}
583+
546584
/*
547585
* Verify that amcheck is installed for this next database. User
548586
* error could result in a database not having amcheck that should
@@ -1153,6 +1191,7 @@ help(const char *progname)
11531191
printf(_(" -V, --version output version information, then exit\n"));
11541192
printf(_(" -P, --progress show progress information\n"));
11551193
printf(_(" -?, --help show this help, then exit\n"));
1194+
printf(_(" --install-missing install missing extensions\n"));
11561195

11571196
printf(_("\nReport bugs to <%s>.\n"),PACKAGE_BUGREPORT);
11581197
printf(_("%s home page: <%s>\n"),PACKAGE_NAME,PACKAGE_URL);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp