Improve "user mapping not found" error message
authorPeter Eisentraut <[email protected]>
Thu, 30 Nov 2023 04:33:55 +0000 (05:33 +0100)
committerPeter Eisentraut <[email protected]>
Thu, 30 Nov 2023 04:34:28 +0000 (05:34 +0100)
Display the name of the foreign server for which the user mapping was
not found.

Author: Ian Lawrence Barwick <[email protected]>
Reviewed-by: Laurenz Albe <[email protected]>
Reviewed-by: Peter Eisentraut <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/CAB8KJ=jFzNaeyFtLcTZNOc6fd1+F93pGVLFa-wyt31wn7VNxqQ@mail.gmail.com

contrib/postgres_fdw/expected/postgres_fdw.out
src/backend/foreign/foreign.c

index 22cae37a1ebb01a0dcf6b48c10503f1741945a4d..0a5bdf8bcc0776d10467cd5945d009c71d05cfe6 100644 (file)
@@ -2717,10 +2717,10 @@ ALTER FOREIGN TABLE ft4 OPTIONS (ADD use_remote_estimate 'true');
 -- regress_view_owner_another, the view owner, though it fails as expected
 -- due to the lack of a user mapping for that user.
 EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM v4;
-ERROR:  user mapping not found for "regress_view_owner_another"
+ERROR:  user mapping not found for user "regress_view_owner_another", server "loopback"
 -- Likewise, but with the query under an UNION ALL
 EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM (SELECT * FROM v4 UNION ALL SELECT * FROM v4);
-ERROR:  user mapping not found for "regress_view_owner_another"
+ERROR:  user mapping not found for user "regress_view_owner_another", server "loopback"
 -- Should not get that error once a user mapping is created
 CREATE USER MAPPING FOR regress_view_owner_another SERVER loopback OPTIONS (password_required 'false');
 EXPLAIN (VERBOSE, COSTS OFF) SELECT * FROM v4;
index ca3ad55b628f10035685dc3190379a8461b92206..fc3edef2a867d78d79308c7c0e5011e5bc3fd4e3 100644 (file)
@@ -217,10 +217,14 @@ GetUserMapping(Oid userid, Oid serverid)
    }
 
    if (!HeapTupleIsValid(tp))
+   {
+       ForeignServer *server = GetForeignServer(serverid);
+
        ereport(ERROR,
                (errcode(ERRCODE_UNDEFINED_OBJECT),
-                errmsg("user mapping not found for \"%s\"",
-                       MappingUserName(userid))));
+                errmsg("user mapping not found for user \"%s\", server \"%s\"",
+                       MappingUserName(userid), server->servername)));
+   }
 
    um = (UserMapping *) palloc(sizeof(UserMapping));
    um->umid = ((Form_pg_user_mapping) GETSTRUCT(tp))->oid;