Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 2a34672

Browse files
committed
Use new errdetail_log() mechanism to provide a less klugy way of reporting
large numbers of dependencies on a role that couldn't be dropped. Per a comment from Alvaro.
1 parent 32b58d0 commit 2a34672

File tree

3 files changed

+33
-59
lines changed

3 files changed

+33
-59
lines changed

src/backend/catalog/pg_shdepend.c

Lines changed: 24 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/catalog/pg_shdepend.c,v 1.24 2008/03/24 19:12:49 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/catalog/pg_shdepend.c,v 1.25 2008/03/24 19:47:35 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -454,11 +454,14 @@ typedef struct
454454
* checkSharedDependencies
455455
*
456456
* Check whether there are shared dependency entries for a given shared
457-
* object. Returns a string containing a newline-separated list of object
457+
* object; return true if so.
458+
*
459+
* In addition, return a string containing a newline-separated list of object
458460
* descriptions that depend on the shared object, or NULL if none is found.
459-
* The size of the returned string is limited to about MAX_REPORTED_DEPS lines;
460-
* if there are more objects than that, the output is returned truncated at
461-
* that point while the full message is logged to the postmaster log.
461+
* We actually return two such strings; the "detail" result is suitable for
462+
* returning to the client as an errdetail() string, and is limited in size.
463+
* The "detail_log" string is potentially much longer, and should be emitted
464+
* to the server log only.
462465
*
463466
* We can find three different kinds of dependencies: dependencies on objects
464467
* of the current database; dependencies on shared objects; and dependencies
@@ -468,8 +471,9 @@ typedef struct
468471
*
469472
* If we find a SHARED_DEPENDENCY_PIN entry, we can error out early.
470473
*/
471-
char *
472-
checkSharedDependencies(Oid classId, Oid objectId)
474+
bool
475+
checkSharedDependencies(Oid classId, Oid objectId,
476+
char **detail_msg, char **detail_log_msg)
473477
{
474478
Relation sdepRel;
475479
ScanKeyData key[2];
@@ -487,9 +491,7 @@ checkSharedDependencies(Oid classId, Oid objectId)
487491
/*
488492
* We limit the number of dependencies reported to the client to
489493
* MAX_REPORTED_DEPS, since client software may not deal well with
490-
* enormous error strings. The server log always gets a full report,
491-
* which is collected in a separate StringInfo if and only if we detect
492-
* that the client report is going to be truncated.
494+
* enormous error strings. The server log always gets a full report.
493495
*/
494496
#define MAX_REPORTED_DEPS 100
495497

@@ -546,15 +548,9 @@ checkSharedDependencies(Oid classId, Oid objectId)
546548
sdepForm->deptype, 0);
547549
}
548550
else
549-
{
550551
numNotReportedDeps++;
551-
/* initialize the server-only log line */
552-
if (alldescs.len == 0)
553-
appendBinaryStringInfo(&alldescs, descs.data, descs.len);
554-
555-
storeObjectDescription(&alldescs, LOCAL_OBJECT, &object,
556-
sdepForm->deptype, 0);
557-
}
552+
storeObjectDescription(&alldescs, LOCAL_OBJECT, &object,
553+
sdepForm->deptype, 0);
558554
}
559555
else if (sdepForm->dbid == InvalidOid)
560556
{
@@ -565,15 +561,9 @@ checkSharedDependencies(Oid classId, Oid objectId)
565561
sdepForm->deptype, 0);
566562
}
567563
else
568-
{
569564
numNotReportedDeps++;
570-
/* initialize the server-only log line */
571-
if (alldescs.len == 0)
572-
appendBinaryStringInfo(&alldescs, descs.data, descs.len);
573-
574-
storeObjectDescription(&alldescs, SHARED_OBJECT, &object,
575-
sdepForm->deptype, 0);
576-
}
565+
storeObjectDescription(&alldescs, SHARED_OBJECT, &object,
566+
sdepForm->deptype, 0);
577567
}
578568
else
579569
{
@@ -612,9 +602,7 @@ checkSharedDependencies(Oid classId, Oid objectId)
612602
heap_close(sdepRel, AccessShareLock);
613603

614604
/*
615-
* Report dependencies on remote databases. If we're truncating the
616-
* output already, don't put a line per database, but a single one for all
617-
* of them. Otherwise add as many as fit in MAX_REPORTED_DEPS.
605+
* Summarize dependencies in remote databases.
618606
*/
619607
foreach(cell, remDeps)
620608
{
@@ -631,15 +619,9 @@ checkSharedDependencies(Oid classId, Oid objectId)
631619
SHARED_DEPENDENCY_INVALID, dep->count);
632620
}
633621
else
634-
{
635622
numNotReportedDbs++;
636-
/* initialize the server-only log line */
637-
if (alldescs.len == 0)
638-
appendBinaryStringInfo(&alldescs, descs.data, descs.len);
639-
640-
storeObjectDescription(&alldescs, REMOTE_OBJECT, &object,
641-
SHARED_DEPENDENCY_INVALID, dep->count);
642-
}
623+
storeObjectDescription(&alldescs, REMOTE_OBJECT, &object,
624+
SHARED_DEPENDENCY_INVALID, dep->count);
643625
}
644626

645627
list_free_deep(remDeps);
@@ -648,7 +630,8 @@ checkSharedDependencies(Oid classId, Oid objectId)
648630
{
649631
pfree(descs.data);
650632
pfree(alldescs.data);
651-
return NULL;
633+
*detail_msg = *detail_log_msg = NULL;
634+
return false;
652635
}
653636

654637
if (numNotReportedDeps > 0)
@@ -660,22 +643,9 @@ checkSharedDependencies(Oid classId, Oid objectId)
660643
"(see server log for list)"),
661644
numNotReportedDbs);
662645

663-
if (numNotReportedDeps > 0 || numNotReportedDbs > 0)
664-
{
665-
ObjectAddress obj;
666-
667-
obj.classId = classId;
668-
obj.objectId = objectId;
669-
obj.objectSubId = 0;
670-
ereport(LOG,
671-
(errmsg("there are objects dependent on %s",
672-
getObjectDescription(&obj)),
673-
errdetail("%s", alldescs.data)));
674-
}
675-
676-
pfree(alldescs.data);
677-
678-
return descs.data;
646+
*detail_msg = descs.data;
647+
*detail_log_msg = alldescs.data;
648+
return true;
679649
}
680650

681651
/*

src/backend/commands/user.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $PostgreSQL: pgsql/src/backend/commands/user.c,v 1.178 2008/01/01 19:45:49 momjian Exp $
9+
* $PostgreSQL: pgsql/src/backend/commands/user.c,v 1.179 2008/03/24 19:47:35 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -828,6 +828,7 @@ DropRole(DropRoleStmt *stmt)
828828
tmp_tuple;
829829
ScanKeyData scankey;
830830
char *detail;
831+
char *detail_log;
831832
SysScanDesc sscan;
832833
Oid roleid;
833834

@@ -885,12 +886,14 @@ DropRole(DropRoleStmt *stmt)
885886
LockSharedObject(AuthIdRelationId, roleid, 0, AccessExclusiveLock);
886887

887888
/* Check for pg_shdepend entries depending on this role */
888-
if ((detail = checkSharedDependencies(AuthIdRelationId, roleid)) != NULL)
889+
if (checkSharedDependencies(AuthIdRelationId, roleid,
890+
&detail, &detail_log))
889891
ereport(ERROR,
890892
(errcode(ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST),
891893
errmsg("role \"%s\" cannot be dropped because some objects depend on it",
892894
role),
893-
errdetail("%s", detail)));
895+
errdetail("%s", detail),
896+
errdetail_log("%s", detail_log)));
894897

895898
/*
896899
* Remove the role from the pg_authid table

src/include/catalog/dependency.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/catalog/dependency.h,v 1.33 2008/01/01 19:45:56 momjian Exp $
10+
* $PostgreSQL: pgsql/src/include/catalog/dependency.h,v 1.34 2008/03/24 19:47:35 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -229,7 +229,8 @@ extern void updateAclDependencies(Oid classId, Oid objectId,
229229
int noldmembers, Oid *oldmembers,
230230
int nnewmembers, Oid *newmembers);
231231

232-
extern char *checkSharedDependencies(Oid classId, Oid objectId);
232+
extern bool checkSharedDependencies(Oid classId, Oid objectId,
233+
char **detail_msg, char **detail_log_msg);
233234

234235
extern void copyTemplateDependencies(Oid templateDbId, Oid newDbId);
235236

0 commit comments

Comments
 (0)