diff --git a/doc/src/sgml/ref/vacuumdb.sgml b/doc/src/sgml/ref/vacuumdb.sgml index 53147480515e..84c76d7350c8 100644 --- a/doc/src/sgml/ref/vacuumdb.sgml +++ b/doc/src/sgml/ref/vacuumdb.sgml @@ -292,6 +292,14 @@ PostgreSQL documentation This option can only be used in conjunction with or . + + Note that requires + SELECT privileges on + pg_statistic + and + pg_statistic_ext_data, + which are restricted to superusers by default. + diff --git a/src/bin/scripts/vacuumdb.c b/src/bin/scripts/vacuumdb.c index fd236087e90a..2087b4131a2e 100644 --- a/src/bin/scripts/vacuumdb.c +++ b/src/bin/scripts/vacuumdb.c @@ -801,6 +801,30 @@ retrieve_objects(PGconn *conn, vacuumingOptions *vacopts, SimpleStringList *found_objs = palloc0(sizeof(SimpleStringList)); bool objects_listed = false; + if (vacopts->missing_stats_only) + { + PQExpBufferData aclcheck; + + initPQExpBuffer(&aclcheck); + appendPQExpBufferStr(&aclcheck, + "SELECT has_table_privilege('pg_catalog.pg_statistic', 'select'), " + "has_table_privilege('pg_catalog.pg_statistic_ext_data', 'select')"); + res = executeQuery(conn, aclcheck.data, echo); + termPQExpBuffer(&aclcheck); + if (strcmp(PQgetvalue(res, 0, 0), "t") != 0) + { + PQfinish(conn); + pg_fatal("--missing-stats-only requires SELECT privileges on pg_statistic"); + } + else if (strcmp(PQgetvalue(res, 0, 1), "t") != 0) + { + PQfinish(conn); + pg_fatal("--missing-stats-only requires SELECT privileges on pg_statistic_ext_data"); + } + + termPQExpBuffer(&aclcheck); + } + initPQExpBuffer(&catalog_query); for (cell = objects ? objects->head : NULL; cell; cell = cell->next) {