Skip to content

Commit f78611b

Browse files
committed
Improve error messages emitted when VACUUM and ANALYZE skip a table.
Per gripe from Clodoaldo Pinto Neto on Message-ID: <a595de7a0801060326qbfc790ax2a60573043c2e2be@mail.gmail.com>
1 parent bccc8e3 commit f78611b

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

src/backend/commands/analyze.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/commands/analyze.c,v 1.114 2008/01/03 21:23:15 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/analyze.c,v 1.115 2008/02/20 14:31:35 alvherre Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -22,6 +22,7 @@
2222
#include "catalog/index.h"
2323
#include "catalog/indexing.h"
2424
#include "catalog/namespace.h"
25+
#include "catalog/pg_namespace.h"
2526
#include "commands/dbcommands.h"
2627
#include "commands/vacuum.h"
2728
#include "executor/executor.h"
@@ -161,9 +162,20 @@ analyze_rel(Oid relid, VacuumStmt *vacstmt,
161162
{
162163
/* No need for a WARNING if we already complained during VACUUM */
163164
if (!vacstmt->vacuum)
164-
ereport(WARNING,
165-
(errmsg("skipping \"%s\" --- only table or database owner can analyze it",
166-
RelationGetRelationName(onerel))));
165+
{
166+
if (onerel->rd_rel->relisshared)
167+
ereport(WARNING,
168+
(errmsg("skipping \"%s\" --- only superuser can analyze it",
169+
RelationGetRelationName(onerel))));
170+
else if (onerel->rd_rel->relnamespace == PG_CATALOG_NAMESPACE)
171+
ereport(WARNING,
172+
(errmsg("skipping \"%s\" --- only superuser or database owner can analyze it",
173+
RelationGetRelationName(onerel))));
174+
else
175+
ereport(WARNING,
176+
(errmsg("skipping \"%s\" --- only table or database owner can analyze it",
177+
RelationGetRelationName(onerel))));
178+
}
167179
relation_close(onerel, ShareUpdateExclusiveLock);
168180
return;
169181
}

src/backend/commands/vacuum.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
*
1515
* IDENTIFICATION
16-
* $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.364 2008/02/11 19:14:30 tgl Exp $
16+
* $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.365 2008/02/20 14:31:35 alvherre Exp $
1717
*
1818
*-------------------------------------------------------------------------
1919
*/
@@ -30,6 +30,7 @@
3030
#include "access/xlog.h"
3131
#include "catalog/namespace.h"
3232
#include "catalog/pg_database.h"
33+
#include "catalog/pg_namespace.h"
3334
#include "commands/dbcommands.h"
3435
#include "commands/vacuum.h"
3536
#include "executor/executor.h"
@@ -1048,9 +1049,18 @@ vacuum_rel(Oid relid, VacuumStmt *vacstmt, char expected_relkind)
10481049
if (!(pg_class_ownercheck(RelationGetRelid(onerel), GetUserId()) ||
10491050
(pg_database_ownercheck(MyDatabaseId, GetUserId()) && !onerel->rd_rel->relisshared)))
10501051
{
1051-
ereport(WARNING,
1052-
(errmsg("skipping \"%s\" --- only table or database owner can vacuum it",
1053-
RelationGetRelationName(onerel))));
1052+
if (onerel->rd_rel->relisshared)
1053+
ereport(WARNING,
1054+
(errmsg("skipping \"%s\" --- only superuser can vacuum it",
1055+
RelationGetRelationName(onerel))));
1056+
else if (onerel->rd_rel->relnamespace == PG_CATALOG_NAMESPACE)
1057+
ereport(WARNING,
1058+
(errmsg("skipping \"%s\" --- only superuser or database owner can vacuum it",
1059+
RelationGetRelationName(onerel))));
1060+
else
1061+
ereport(WARNING,
1062+
(errmsg("skipping \"%s\" --- only table or database owner can vacuum it",
1063+
RelationGetRelationName(onerel))));
10541064
relation_close(onerel, lmode);
10551065
CommitTransactionCommand();
10561066
return;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy