Skip to content

Commit 39042c1

Browse files
author
Commitfest Bot
committed
[CF 5986] v5 - vacuumdb --missing-stats-only and permission issue
This branch was automatically generated by a robot using patches from an email thread registered at: https://commitfest.postgresql.org/patch/5986 The branch will be overwritten each time a new patch version is posted to the thread, and also periodically to check for bitrot caused by changes on the master branch. Patch(es): https://www.postgresql.org/message-id/[email protected] Author(s): Corey Huinker
2 parents 989b2e4 + c82f4b4 commit 39042c1

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

doc/src/sgml/ref/vacuumdb.sgml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,14 @@ PostgreSQL documentation
292292
This option can only be used in conjunction with
293293
<option>--analyze-only</option> or <option>--analyze-in-stages</option>.
294294
</para>
295+
<para>
296+
Note that <option>--missing-stats-only</option> requires
297+
<literal>SELECT</literal> privileges on
298+
<link linkend="catalog-pg-statistic"><structname>pg_statistic</structname></link>
299+
and
300+
<link linkend="catalog-pg-statistic-ext-data"><structname>pg_statistic_ext_data</structname></link>,
301+
which are restricted to superusers by default.
302+
</para>
295303
</listitem>
296304
</varlistentry>
297305

src/bin/scripts/vacuumdb.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,30 @@ retrieve_objects(PGconn *conn, vacuumingOptions *vacopts,
801801
SimpleStringList *found_objs = palloc0(sizeof(SimpleStringList));
802802
bool objects_listed = false;
803803

804+
if (vacopts->missing_stats_only)
805+
{
806+
PQExpBufferData aclcheck;
807+
808+
initPQExpBuffer(&aclcheck);
809+
appendPQExpBufferStr(&aclcheck,
810+
"SELECT has_table_privilege('pg_catalog.pg_statistic', 'select'), "
811+
"has_table_privilege('pg_catalog.pg_statistic_ext_data', 'select')");
812+
res = executeQuery(conn, aclcheck.data, echo);
813+
termPQExpBuffer(&aclcheck);
814+
if (strcmp(PQgetvalue(res, 0, 0), "t") != 0)
815+
{
816+
PQfinish(conn);
817+
pg_fatal("--missing-stats-only requires SELECT privileges on pg_statistic");
818+
}
819+
else if (strcmp(PQgetvalue(res, 0, 1), "t") != 0)
820+
{
821+
PQfinish(conn);
822+
pg_fatal("--missing-stats-only requires SELECT privileges on pg_statistic_ext_data");
823+
}
824+
825+
termPQExpBuffer(&aclcheck);
826+
}
827+
804828
initPQExpBuffer(&catalog_query);
805829
for (cell = objects ? objects->head : NULL; cell; cell = cell->next)
806830
{

0 commit comments

Comments
 (0)