From: Andreas 'ads' Scherbaum <ads@pgug.de>
To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Subject: Find dangling membership roles in pg_dumpall
Date: Wed, 26 Apr 2023 12:18:16 +0200
Message-ID: <de44299d-cd31-b41f-2c2a-161fa5e586a5@pgug.de> (raw)
Hello,
pg_dumpall.c has a function dumpRoleMembership() which dumps all
membership roles. This function includes a piece of code which checks
if the membership tree has an open end which can't be resolved.
However that code is never used.
The variable prev_remaining is initially set to 0, and then never changed.
Which in turn never executes this code:
if (remaining == prev_remaining)
because the loop is only entered while "remaining > 0".
The attached patch fixes this problem, and updates prev_remaining inside
the loop.
Co-Author: Artur Zakirov <zaartur@gmail.com>
who reviewed the patch.
Regards
--
Andreas 'ads' Scherbaum
German PostgreSQL User Group
European PostgreSQL User Group - Board of Directors
Volunteer Regional Contact, Germany - PostgreSQL Project
Attachments:pg_dumpall.patch (text/x-patch, 872B) downloaddiff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.cindex 71a1319865..1e2a32c39a 100644--- a/src/bin/pg_dump/pg_dumpall.c+++ b/src/bin/pg_dump/pg_dumpall.c@@ -1044,6 +1044,9 @@ dumpRoleMembership(PGconn *conn)
* graph whose vertices are grants and whose edges point from
* grantors to members should be connected and acyclic. If we fail
* to make progress, either we or the server have messed up.
+ * Initially $prev_remaining is 0, while initially $remaining can't+ * be 0. If a subsequent loop produces no new results the loop+ * aborts here.
*/
if (remaining == prev_remaining)
{
@@ -1052,6 +1055,7 @@ dumpRoleMembership(PGconn *conn)
PQfinish(conn);
exit_nicely(1);
}
+ prev_remaining = remaining;
/* Make one pass over the grants for this role. */
for (i = start; i < end; ++i)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-hackers@postgresql.org
Cc: ads@pgug.de
Subject: Re: Find dangling membership roles in pg_dumpall
In-Reply-To: <de44299d-cd31-b41f-2c2a-161fa5e586a5@pgug.de>
References: <de44299d-cd31-b41f-2c2a-161fa5e586a5@pgug.de>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox