Major Version Upgrade failure due to orphan roles entries in catalog
Hi,
We have identified an issue causing upgrade failures. The following steps
detail how to reproduce the issue:
*Create an orphan role entry*
/* Postgres version:: PostgreSQL 16.6 */
/* The same can be reproduced in version 17 as well */
create role my_group;
create role dropped_member;
begin;
grant my_group to dropped_member;
OTHER SESSION: drop role dropped_member;
BACK IN ORIGINAL SESSION:
commit;
*Upgrade to Postgres v17*
And the upgrade fails with an error :
*GRANT "my_group" TO "" WITH INHERIT TRUE GRANTED BY "postgres";ERROR:
zero-length delimited identifier at or near """"*
The issue seems to be coming from pg_dumpall for building grants during
pg_upgrade.
https://github.com/postgres/postgres/blob/master/src/bin/pg_dump/pg_dumpall.c#L992
-Virender
On Tue, 2025-02-11 at 15:32 +0530, Virender Singla wrote:
We have identified an issue causing upgrade failures. The following steps detail how to reproduce the issue:
Create an orphan role entry
/* Postgres version:: PostgreSQL 16.6 */
/* The same can be reproduced in version 17 as well */create role my_group;
create role dropped_member;
begin;
grant my_group to dropped_member;
OTHER SESSION: drop role dropped_member;
BACK IN ORIGINAL SESSION:
commit;Upgrade to Postgres v17
And the upgrade fails with an error :
GRANT "my_group" TO "" WITH INHERIT TRUE GRANTED BY "postgres";
ERROR: zero-length delimited identifier at or near """"The issue seems to be coming from pg_dumpall for building grants during pg_upgrade.
https://github.com/postgres/postgres/blob/master/src/bin/pg_dump/pg_dumpall.c#L992
I agree that that is a bug.
I guess the GRANT statement should put a FOR KEY SHARE lock on the pg_authid row
for "dropped_member", similar to what we do for foreign keys.
Yours,
Laurenz Albe
--
*E-Mail Disclaimer*
Der Inhalt dieser E-Mail ist ausschliesslich fuer den
bezeichneten Adressaten bestimmt. Wenn Sie nicht der vorgesehene Adressat
dieser E-Mail oder dessen Vertreter sein sollten, so beachten Sie bitte,
dass jede Form der Kenntnisnahme, Veroeffentlichung, Vervielfaeltigung oder
Weitergabe des Inhalts dieser E-Mail unzulaessig ist. Wir bitten Sie, sich
in diesem Fall mit dem Absender der E-Mail in Verbindung zu setzen.
*CONFIDENTIALITY NOTICE & DISCLAIMER
*This message and any attachment are
confidential and may be privileged or otherwise protected from disclosure
and solely for the use of the person(s) or entity to whom it is intended.
If you have received this message in error and are not the intended
recipient, please notify the sender immediately and delete this message and
any attachment from your system. If you are not the intended recipient, be
advised that any use of this message is prohibited and may be unlawful, and
you must not copy this message or attachment or disclose the contents to
any other person.
BTW a similar variant has been fixed in PG 16 but does not fix the above
case.
create role dropped_group;
create role member;
begin;
grant dropped_group to member;
OTHER SESSION: drop role dropped_group;
BACK IN ORIGINAL SESSION:
commit;
On Tue, Feb 11, 2025 at 7:50 PM Laurenz Albe <laurenz.albe@cybertec.at>
wrote:
Show quoted text
On Tue, 2025-02-11 at 15:32 +0530, Virender Singla wrote:
We have identified an issue causing upgrade failures. The following
steps detail how to reproduce the issue:
Create an orphan role entry
/* Postgres version:: PostgreSQL 16.6 */
/* The same can be reproduced in version 17 as well */create role my_group;
create role dropped_member;
begin;
grant my_group to dropped_member;
OTHER SESSION: drop role dropped_member;
BACK IN ORIGINAL SESSION:
commit;Upgrade to Postgres v17
And the upgrade fails with an error :
GRANT "my_group" TO "" WITH INHERIT TRUE GRANTED BY "postgres";
ERROR: zero-length delimited identifier at or near """"The issue seems to be coming from pg_dumpall for building grants during
pg_upgrade.
https://github.com/postgres/postgres/blob/master/src/bin/pg_dump/pg_dumpall.c#L992
I agree that that is a bug.
I guess the GRANT statement should put a FOR KEY SHARE lock on the
pg_authid row
for "dropped_member", similar to what we do for foreign keys.Yours,
Laurenz Albe--
*E-Mail Disclaimer*
Der Inhalt dieser E-Mail ist ausschliesslich fuer den
bezeichneten Adressaten bestimmt. Wenn Sie nicht der vorgesehene Adressat
dieser E-Mail oder dessen Vertreter sein sollten, so beachten Sie bitte,
dass jede Form der Kenntnisnahme, Veroeffentlichung, Vervielfaeltigung
oder
Weitergabe des Inhalts dieser E-Mail unzulaessig ist. Wir bitten Sie, sich
in diesem Fall mit dem Absender der E-Mail in Verbindung zu setzen.*CONFIDENTIALITY NOTICE & DISCLAIMER
*This message and any attachment are
confidential and may be privileged or otherwise protected from disclosure
and solely for the use of the person(s) or entity to whom it is intended.
If you have received this message in error and are not the intended
recipient, please notify the sender immediately and delete this message
and
any attachment from your system. If you are not the intended recipient, be
advised that any use of this message is prohibited and may be unlawful,
and
you must not copy this message or attachment or disclose the contents to
any other person.
Laurenz Albe <laurenz.albe@cybertec.at> writes:
On Tue, 2025-02-11 at 15:32 +0530, Virender Singla wrote:
/* Postgres version:: PostgreSQL 16.6 */
/* The same can be reproduced in version 17 as well */create role my_group;
create role dropped_member;
begin;
grant my_group to dropped_member;
OTHER SESSION: drop role dropped_member;
BACK IN ORIGINAL SESSION:
commit;
[ leaves a dangling pg_auth_members entry behind ]
I guess the GRANT statement should put a FOR KEY SHARE lock on the pg_authid row
for "dropped_member", similar to what we do for foreign keys.
There is a lock taken already, which is why the DROP ROLE blocks.
What there is not is a recheck that the role still exists once
we have its lock.
I poked into this, and in code terms it seems like the problem is
that AddRoleMems adds a pg_auth_members entry but makes it depend
on only one of the three roles listed in the entry. That seems
wrong on its face. The connection to this problem is that the
dependency-adding code would take care of the lock+recheck, if
it only knew that the pg_auth_members entry ought to be treated
as depending on dropped_member.
The code the attached patch is touching is from commit 6566133c5.
I'm not going to blame the bug on that commit, because before that
we had dependencies on *zero* of the three roles; at least it added
one on the grantor. But I'm wondering whether Robert thought about
the other two roles and explicitly rejected making dependencies
for them, and if so why.
In addition to fixing the described race condition, this patch
means that DROP OWNED BY on either the granted role or the member
will drop the grant. This seems consistent with the goals of
6566133c5 and with our general approach to dropping privileges
during DROP OWNED BY; but it didn't happen that way before.
I'm wondering a little bit if we could simplify/remove some of the
code in user.c by relying on processing of these dependency entries
to carry the load instead during DROP ROLE. But it passes check-world
as-is, so maybe leaving well enough alone is best.
regards, tom lane
Attachments:
add-missing-dependencies-for-pg_auth_members-wip.patchtext/x-diff; charset=us-ascii; name=add-missing-dependencies-for-pg_auth_members-wip.patchDownload+17-5
On 2025-Feb-11, Virender Singla wrote:
And the upgrade fails with an error :
*GRANT "my_group" TO "" WITH INHERIT TRUE GRANTED BY "postgres";ERROR:
zero-length delimited identifier at or near """"*The issue seems to be coming from pg_dumpall for building grants during
pg_upgrade.
Hmm, I think fixing the bug as Tom suggests downthread is probably a
good idea, but I think we should in addition change pg_dumpall to avoid
printing a GRANT line if there's no grantee. Maybe turning one of these LEFT
JOINs into a regular inner join is a sufficient fix for that:
/* Generate and execute query. */
printfPQExpBuffer(buf, "SELECT ur.rolname AS role, "
"um.rolname AS member, "
"ug.oid AS grantorid, "
"ug.rolname AS grantor, "
"a.admin_option");
if (dump_grant_options)
appendPQExpBufferStr(buf, ", a.inherit_option, a.set_option");
appendPQExpBuffer(buf, " FROM pg_auth_members a "
"LEFT JOIN %s ur on ur.oid = a.roleid "
"LEFT JOIN %s um on um.oid = a.member "
"LEFT JOIN %s ug on ug.oid = a.grantor "
"WHERE NOT (ur.rolname ~ '^pg_' AND um.rolname ~ '^pg_')"
"ORDER BY 1,2,4", role_catalog, role_catalog, role_catalog);
--
Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/
"I am amazed at [the pgsql-sql] mailing list for the wonderful support, and
lack of hesitasion in answering a lost soul's question, I just wished the rest
of the mailing list could be like this." (Fotis)
/messages/by-id/200606261359.k5QDxE2p004593@auth-smtp.hol.gr
=?utf-8?Q?=C3=81lvaro?= Herrera <alvherre@alvh.no-ip.org> writes:
Hmm, I think fixing the bug as Tom suggests downthread is probably a
good idea, but I think we should in addition change pg_dumpall to avoid
printing a GRANT line if there's no grantee.
On the one hand, my proposed patch can do nothing to fix existing
dangling entries in pg_auth_members, so hacking pg_dump seems like
a good workaround if the problem already exists. On the other hand,
if we make pg_dump do that then we won't detect future problems of
the same ilk.
Maybe turning one of these LEFT
JOINs into a regular inner join is a sufficient fix for that:
Probably change all three, if we're to do this at all.
regards, tom lane
=?utf-8?Q?=C3=81lvaro?= Herrera <alvherre@alvh.no-ip.org> writes:
Hmm, I think fixing the bug as Tom suggests downthread is probably a
good idea, but I think we should in addition change pg_dumpall to avoid
printing a GRANT line if there's no grantee. Maybe turning one of these LEFT
JOINs into a regular inner join is a sufficient fix for that:
After looking at this I thought it was worth a little more code to warn
about the dangling role OID, instead of just silently ignoring it.
Here's a couple of more-polished patches.
I'm unsure whether to back-patch the 0001 patch, as it does imply
more pg_shdepend entries than we have today, so it's sort of a
backdoor catalog change. But we're mostly interested in the
transient behavior of having a lock+recheck during entry insertion,
so maybe it's fine. 0002 should be back-patched in any case.
(BTW, I was distressed to learn from the code coverage report
that we have zero test coverage of the hardly-trivial logic in
dumpRoleMembership. I didn't try to address that here. I did
test this new logic by dint of manually deleting from pg_authid.)
regards, tom lane
Attachments:
v1-0002-Fix-pg_dumpall-to-cope-with-dangling-OIDs-in-pg_a.patchtext/x-diff; charset=us-ascii; name*0=v1-0002-Fix-pg_dumpall-to-cope-with-dangling-OIDs-in-pg_a.p; name*1=atchDownload+57-10
v1-0001-Avoid-race-condition-between-GRANT-role-and-DROP-.patchtext/x-diff; charset=us-ascii; name*0=v1-0001-Avoid-race-condition-between-GRANT-role-and-DROP-.p; name*1=atchDownload+63-7
On Thu, 2025-02-20 at 17:19 -0500, Tom Lane wrote:
After looking at this I thought it was worth a little more code to warn
about the dangling role OID, instead of just silently ignoring it.
Here's a couple of more-polished patches.I'm unsure whether to back-patch the 0001 patch, as it does imply
more pg_shdepend entries than we have today, so it's sort of a
backdoor catalog change. But we're mostly interested in the
transient behavior of having a lock+recheck during entry insertion,
so maybe it's fine. 0002 should be back-patched in any case.
I'd say that adding new catalog entries in a way that is compatible
shouldn't be a problem, but I still wouldn't backpatch the 0001 patch,
because it is not necessary. The orphaned pg_auth_members entry didn't
cause any harm, and a few warnings more during an upgrade shouldn't be
a big problem.
I have one question about the first patch:
diff --git a/src/backend/commands/user.c b/src/backend/commands/user.c index 0db174e6f1..0c84886e82 100644 --- a/src/backend/commands/user.c +++ b/src/backend/commands/user.c @@ -489,7 +490,7 @@ CreateRole(ParseState *pstate, CreateRoleStmt *stmt) * Advance command counter so we can see new record; else tests in * AddRoleMems may fail. */ - if (addroleto || adminmembers || rolemembers) + if (addroleto || adminmembers || rolemembers || !superuser()) CommandCounterIncrement();/* Default grant. */
That change seems unrelated to the problem at hand, and I don't see it
mentioned in the commit message. Is that an oversight you fixed on the
fly?
Apart from that, the patches look fine.
Yours,
Laurenz Albe
--
*E-Mail Disclaimer*
Der Inhalt dieser E-Mail ist ausschliesslich fuer den
bezeichneten Adressaten bestimmt. Wenn Sie nicht der vorgesehene Adressat
dieser E-Mail oder dessen Vertreter sein sollten, so beachten Sie bitte,
dass jede Form der Kenntnisnahme, Veroeffentlichung, Vervielfaeltigung oder
Weitergabe des Inhalts dieser E-Mail unzulaessig ist. Wir bitten Sie, sich
in diesem Fall mit dem Absender der E-Mail in Verbindung zu setzen.
*CONFIDENTIALITY NOTICE & DISCLAIMER
*This message and any attachment are
confidential and may be privileged or otherwise protected from disclosure
and solely for the use of the person(s) or entity to whom it is intended.
If you have received this message in error and are not the intended
recipient, please notify the sender immediately and delete this message and
any attachment from your system. If you are not the intended recipient, be
advised that any use of this message is prohibited and may be unlawful, and
you must not copy this message or attachment or disclose the contents to
any other person.
Laurenz Albe <laurenz.albe@cybertec.at> writes:
I have one question about the first patch:
- if (addroleto || adminmembers || rolemembers) + if (addroleto || adminmembers || rolemembers || !superuser()) CommandCounterIncrement();
That change seems unrelated to the problem at hand, and I don't see it
mentioned in the commit message. Is that an oversight you fixed on the
fly?
Well, kinda, because the patch doesn't work without it. The
problematic case is where none of those 3 flags are set and also
!superuser, so that we decide we need the default grant implemented a
few lines further down. That grant now has an explicit reference to
the new roleid, and if we haven't CommandCounterIncrement'ed, the
pg_shdepend code will error out because it doesn't see the catalog
entry for roleid.
regards, tom lane
On Fri, 2025-02-21 at 09:41 -0500, Tom Lane wrote:
Laurenz Albe <laurenz.albe@cybertec.at> writes:
I have one question about the first patch:
- if (addroleto || adminmembers || rolemembers) + if (addroleto || adminmembers || rolemembers || !superuser()) CommandCounterIncrement();That change seems unrelated to the problem at hand, and I don't see it
mentioned in the commit message. Is that an oversight you fixed on the
fly?Well, kinda, because the patch doesn't work without it. The
problematic case is where none of those 3 flags are set and also
!superuser, so that we decide we need the default grant implemented a
few lines further down. That grant now has an explicit reference to
the new roleid, and if we haven't CommandCounterIncrement'ed, the
pg_shdepend code will error out because it doesn't see the catalog
entry for roleid.
Thanks for the explanation. That might be worth a comment.
Yours,
Laurenz Albe
--
*E-Mail Disclaimer*
Der Inhalt dieser E-Mail ist ausschliesslich fuer den
bezeichneten Adressaten bestimmt. Wenn Sie nicht der vorgesehene Adressat
dieser E-Mail oder dessen Vertreter sein sollten, so beachten Sie bitte,
dass jede Form der Kenntnisnahme, Veroeffentlichung, Vervielfaeltigung oder
Weitergabe des Inhalts dieser E-Mail unzulaessig ist. Wir bitten Sie, sich
in diesem Fall mit dem Absender der E-Mail in Verbindung zu setzen.
*CONFIDENTIALITY NOTICE & DISCLAIMER
*This message and any attachment are
confidential and may be privileged or otherwise protected from disclosure
and solely for the use of the person(s) or entity to whom it is intended.
If you have received this message in error and are not the intended
recipient, please notify the sender immediately and delete this message and
any attachment from your system. If you are not the intended recipient, be
advised that any use of this message is prohibited and may be unlawful, and
you must not copy this message or attachment or disclose the contents to
any other person.
Laurenz Albe <laurenz.albe@cybertec.at> writes:
Thanks for the explanation. That might be worth a comment.
The adjacent comment already says
/*
* Advance command counter so we can see new record; else tests in
* AddRoleMems may fail.
*/
so I didn't see anything to add there. Maybe "We can skip this in
cases where we will not call AddRoleMems"? Or maybe the better answer
is to conclude that the whole idea of not calling
CommandCounterIncrement unconditionally is too fragile and not worth
expending brain cells on, and just rip out the if-test.
regards, tom lane
On Fri, 2025-02-21 at 11:31 -0500, Tom Lane wrote:
Laurenz Albe <laurenz.albe@cybertec.at> writes:
Thanks for the explanation. That might be worth a comment.
The adjacent comment already says
/*
* Advance command counter so we can see new record; else tests in
* AddRoleMems may fail.
*/so I didn't see anything to add there. Maybe "We can skip this in
cases where we will not call AddRoleMems"? Or maybe the better answer
is to conclude that the whole idea of not calling
CommandCounterIncrement unconditionally is too fragile and not worth
expending brain cells on, and just rip out the if-test.
Both the extra sentence and the simplification feel like an improvement.
I am fine with either.
Yours,
Laurenz Albe
--
*E-Mail Disclaimer*
Der Inhalt dieser E-Mail ist ausschliesslich fuer den
bezeichneten Adressaten bestimmt. Wenn Sie nicht der vorgesehene Adressat
dieser E-Mail oder dessen Vertreter sein sollten, so beachten Sie bitte,
dass jede Form der Kenntnisnahme, Veroeffentlichung, Vervielfaeltigung oder
Weitergabe des Inhalts dieser E-Mail unzulaessig ist. Wir bitten Sie, sich
in diesem Fall mit dem Absender der E-Mail in Verbindung zu setzen.
*CONFIDENTIALITY NOTICE & DISCLAIMER
*This message and any attachment are
confidential and may be privileged or otherwise protected from disclosure
and solely for the use of the person(s) or entity to whom it is intended.
If you have received this message in error and are not the intended
recipient, please notify the sender immediately and delete this message and
any attachment from your system. If you are not the intended recipient, be
advised that any use of this message is prohibited and may be unlawful, and
you must not copy this message or attachment or disclose the contents to
any other person.
Laurenz Albe <laurenz.albe@cybertec.at> writes:
On Fri, 2025-02-21 at 11:31 -0500, Tom Lane wrote:
... Or maybe the better answer
is to conclude that the whole idea of not calling
CommandCounterIncrement unconditionally is too fragile and not worth
expending brain cells on, and just rip out the if-test.
Both the extra sentence and the simplification feel like an improvement.
I am fine with either.
The more I think about it the more I like just getting rid of the
test. It'll likely break with every future change to this logic,
until somebody finally gives up on it; so why not now?
I'll make it so. Thanks for reviewing!
regards, tom lane
On Thu, Feb 13, 2025 at 12:07 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
The code the attached patch is touching is from commit 6566133c5.
I'm not going to blame the bug on that commit, because before that
we had dependencies on *zero* of the three roles; at least it added
one on the grantor. But I'm wondering whether Robert thought about
the other two roles and explicitly rejected making dependencies
for them, and if so why.
For some reason, I came to the conclusion that it wasn't needed.
Apparently, that was incorrect.
--
Robert Haas
EDB: http://www.enterprisedb.com
On Thu, Feb 20, 2025 at 5:19 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
I'm unsure whether to back-patch the 0001 patch, as it does imply
more pg_shdepend entries than we have today, so it's sort of a
backdoor catalog change. But we're mostly interested in the
transient behavior of having a lock+recheck during entry insertion,
so maybe it's fine. 0002 should be back-patched in any case.
I recently learned of a case where this commit caused role grants to
be erroneously emitted from the output of pg_dumpall. In the case in
question, a v16 pg_dumpall was used against an older server. Hence,
dump_grantors was false, and any generated GRANT commands would not
have included in the grantor anyway. Nevertheless, this logic caused
those grants to be skipped altogether:
+ if (PQgetisnull(res, i, i_grantor))
+ {
+ /* translator: %s represents a numeric role OID */
+ pg_log_warning("found orphaned pg_auth_members
entry for role %s",
+ PQgetvalue(res, i, i_grantorid));
+ done[i - start] = true;
+ --remaining;
+ continue;
+ }
I don't think this logic makes sense. In pre-16 releases, we don't
even try to maintain the grantor field properly. Consider this test
case:
create role foo;
create role bar;
create role baz createrole;
set role baz;
grant foo to bar;
reset role;
drop role baz;
If you do this on v15 and then run v15's pg_dumpall, it will dump
"GRANT foo to bar", with no GRANTOR clause due to the PQgetisnull()
gating that logic. v16's pg_dumpall will dump nothing and emit a
warning instead. Arguably, pre-v16 pg_dumpall shouldn't EVER be
dumping the grantor since the grantorid could be an old role OID that
has been recycled for a new role, and relying on that for anything
security-critical seems like a mistake, but that behavior is also
longstanding. But omitting the grant altogether seems like an
overreaction. I understand that we need to do that when the *member*
is invalid, of course; in that case, there's no alternative. But
that's not the case for the grantor.
--
Robert Haas
EDB: http://www.enterprisedb.com
Robert Haas <robertmhaas@gmail.com> writes:
I recently learned of a case where this commit caused role grants to
be erroneously emitted from the output of pg_dumpall. In the case in
question, a v16 pg_dumpall was used against an older server. Hence,
dump_grantors was false, and any generated GRANT commands would not
have included in the grantor anyway. Nevertheless, this logic caused
those grants to be skipped altogether:
...
If you do this on v15 and then run v15's pg_dumpall, it will dump
"GRANT foo to bar", with no GRANTOR clause due to the PQgetisnull()
gating that logic. v16's pg_dumpall will dump nothing and emit a
warning instead. Arguably, pre-v16 pg_dumpall shouldn't EVER be
dumping the grantor since the grantorid could be an old role OID that
has been recycled for a new role, and relying on that for anything
security-critical seems like a mistake, but that behavior is also
longstanding. But omitting the grant altogether seems like an
overreaction. I understand that we need to do that when the *member*
is invalid, of course; in that case, there's no alternative. But
that's not the case for the grantor.
Hmm. As per the commit message,
Pre-v16 branches already coped with dangling grantor OIDs by simply
omitting the GRANTED BY clause. I left that behavior as-is, although
it's somewhat inconsistent with the behavior of later branches.
So what you're saying is that I should have made the later branches
do that also. I guess it's arguably better than dropping the grant
altogether ... but the end result will be that the grant is now
granted by the superuser running the restore, which doesn't seem
very good either.
regards, tom lane
On Wed, Feb 25, 2026 at 10:36 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
So what you're saying is that I should have made the later branches
do that also. I guess it's arguably better than dropping the grant
altogether ... but the end result will be that the grant is now
granted by the superuser running the restore, which doesn't seem
very good either.
It does not, but it seems better than having a v16 pg_dumpall and v15
pg_dumpall produce non-logically-equivalent dumps of the same
database. My instinct is that this test:
if (PQgetisnull(res, i, i_grantor))
Should instead look like this:
if (PQgetisnull(res, i, i_grantor) &&
dump_grantors)
In v16+, if the grantor is not valid, that's unexpected and something
has gone wrong, perhaps due to insufficient locking, or maybe due to
catalog corruption. The warning is a fair response to a
seemingly-corrupted catalog state. But in v15-, this is just business
as usual; there's no particular expectation that the grantor must be a
valid role OID, and IMHO the best thing to do is give the same result
that a pre-v16 pg_dumpall would have produced.
I'm not actually completely confident that I have a fully correct
analysis of this problem. But I do think that it's hard to argue that
dumping the same database with different pg_dumpall versions should
produce logically different results.
--
Robert Haas
EDB: http://www.enterprisedb.com
Robert Haas <robertmhaas@gmail.com> writes:
In v16+, if the grantor is not valid, that's unexpected and something
has gone wrong, perhaps due to insufficient locking, or maybe due to
catalog corruption. The warning is a fair response to a
seemingly-corrupted catalog state. But in v15-, this is just business
as usual; there's no particular expectation that the grantor must be a
valid role OID, and IMHO the best thing to do is give the same result
that a pre-v16 pg_dumpall would have produced.
I don't entirely agree that it's "business as usual": somebody screwed
up to get the database into that state. I'm not here to apportion
blame for that between the user and the database, but I do think it's
appropriate for pg_dumpall to complain that it's facing invalid data.
If you're good with pg_dumpall producing a warning and then emitting
the GRANT with no grantor clause, I will go make that happen.
regards, tom lane
On Wed, Feb 25, 2026 at 11:50 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
I don't entirely agree that it's "business as usual": somebody screwed
up to get the database into that state. I'm not here to apportion
blame for that between the user and the database, but I do think it's
appropriate for pg_dumpall to complain that it's facing invalid data.If you're good with pg_dumpall producing a warning and then emitting
the GRANT with no grantor clause, I will go make that happen.
Well, I guess I don't really see why there should be a warning. I
mean, if you're not here to apportion blame between the user and
database, then allow me to step in: in v15-, it's entirely the
database's fault. It does absolutely zilch to keep that field valid.
As I showed in the earlier example, all the user has to do is create a
role, do something, and drop the role, and that field is no longer
valid. That's about the simplest scenario imaginable, and I don't
think any user would expect it to produce a corrupted database, and I
think the status quo ante prior to this commit was that we did not
consider that to be a corrupted database.
If that feels like the wrong answer to you, I suggest that the reason
is that you're not used to PostgreSQL code being as horrifically bad
as this code was prior to v16. I don't know of anywhere else in the
database where we store an OID and do absolutely nothing to ensure its
validity. Sure, we've found some holes over the years where we didn't
do enough, especially around concurrency, and we've probably all seen
examples of TOAST corruption where a value can't be de-TOASTed due to
some inconsistency. But those are examples of where we had had some
guards in place and they weren't as thorough as they needed to be, or
where the user voided the warranty by doing something stupid, or where
the storage manhandled the data. But before
6566133c5f52771198aca07ed18f84519fac1be7, we didn't just have
inadequate machinery in this area: we had none. I remember being
absolutely gobsmacked at this discovery that it had been this way for
years and apparently nobody was too fussed about it. It seemed to me
then and it seems to me now that such handling was way below our usual
quality standards, even for older code when we weren't as strict as we
are today. But that's nevertheless how it was.
Now, if you go and do as you propose here, and adjust the code so that
the grant is dumped but a warning is produced, my fear is that someone
upgrading from v15- to v16+ will see that warning and think that there
is a problem with their database that needs fixing. But, except for
the fact that they should really upgrade to a newer and better
version, that's not really true. They're just running a version where
no care was put into making that field valid, and so sometimes it
isn't. I suppose that is OK in the end: when such a user files a
support ticket with $EMPLOYER or any other company, somebody can
simply tell that user that the warning requires no corrective action
and can be safely ignored. But of course, they'll have to know that
this is the case, and not everyone will have read this discussion.
Moreover, we'll emit essentially the same warning for the member case,
where the warning does point to a problem that someone might want to
think about correcting, and exactly the same warning against a v16+
database where it indicates that something has actually gone wrong. I
don't know why we would want to do that instead of what I proposed,
but if you're dead-set on it, I can live with it: it will at least
mean people can upgrade without having perfectly good role grants
disappear into the ether.
--
Robert Haas
EDB: http://www.enterprisedb.com
Robert Haas <robertmhaas@gmail.com> writes:
On Wed, Feb 25, 2026 at 11:50 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
If you're good with pg_dumpall producing a warning and then emitting
the GRANT with no grantor clause, I will go make that happen.
Well, I guess I don't really see why there should be a warning.
Because the result of the restore will not match how things were
in the source database? True, we do not have any way to make them
match, but that doesn't mean that pg_dumpall has fulfilled all
expectations.
Now, if you go and do as you propose here, and adjust the code so that
the grant is dumped but a warning is produced, my fear is that someone
upgrading from v15- to v16+ will see that warning and think that there
is a problem with their database that needs fixing.
On the other hand, if we produce no warning and yet the restored DB
is unlike the original, that could also be cause for concern.
Moreover, we'll emit essentially the same warning for the member case,
where the warning does point to a problem that someone might want to
think about correcting, and exactly the same warning against a v16+
database where it indicates that something has actually gone wrong.
That's a fair point, but maybe it could be addressed by phrasing the
message differently for the different cases.
regards, tom lane