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

Commit 5cf4000

Browse files
committed
Fix user mapping object description
We were using "user mapping for user XYZ" as description for user mappings, but that's ambiguous because users can have mappings on multiple foreign servers; therefore change it to "for user XYZ on server UVW" instead. Object identities for user mappings are also updated in the same way, in branches 9.3 and above. The incomplete description string was introduced together with the whole SQL/MED infrastructure by commit cae565e of 8.4 era, so backpatch all the way back.
1 parent 73f236f commit 5cf4000

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

src/backend/catalog/objectaddress.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2028,14 +2028,17 @@ getObjectDescription(const ObjectAddress *object)
20282028
HeapTuple tup;
20292029
Oid useid;
20302030
char *usename;
2031+
Form_pg_user_mapping umform;
2032+
ForeignServer *srv;
20312033

20322034
tup = SearchSysCache1(USERMAPPINGOID,
20332035
ObjectIdGetDatum(object->objectId));
20342036
if (!HeapTupleIsValid(tup))
20352037
elog(ERROR, "cache lookup failed for user mapping %u",
20362038
object->objectId);
2037-
2038-
useid = ((Form_pg_user_mapping) GETSTRUCT(tup))->umuser;
2039+
umform = (Form_pg_user_mapping) GETSTRUCT(tup);
2040+
useid = umform->umuser;
2041+
srv = GetForeignServer(umform->umserver);
20392042

20402043
ReleaseSysCache(tup);
20412044

@@ -2044,7 +2047,8 @@ getObjectDescription(const ObjectAddress *object)
20442047
else
20452048
usename = "public";
20462049

2047-
appendStringInfo(&buffer, _("user mapping for %s"), usename);
2050+
appendStringInfo(&buffer, _("user mapping for %s on server %s"), usename,
2051+
srv->servername);
20482052
break;
20492053
}
20502054

@@ -3197,15 +3201,18 @@ getObjectIdentity(const ObjectAddress *object)
31973201
{
31983202
HeapTuple tup;
31993203
Oid useid;
3204+
Form_pg_user_mapping umform;
3205+
ForeignServer *srv;
32003206
const char *usename;
32013207

32023208
tup = SearchSysCache1(USERMAPPINGOID,
32033209
ObjectIdGetDatum(object->objectId));
32043210
if (!HeapTupleIsValid(tup))
32053211
elog(ERROR, "cache lookup failed for user mapping %u",
32063212
object->objectId);
3207-
3208-
useid = ((Form_pg_user_mapping) GETSTRUCT(tup))->umuser;
3213+
umform = (Form_pg_user_mapping) GETSTRUCT(tup);
3214+
useid = umform->umuser;
3215+
srv = GetForeignServer(umform->umserver);
32093216

32103217
ReleaseSysCache(tup);
32113218

@@ -3214,7 +3221,8 @@ getObjectIdentity(const ObjectAddress *object)
32143221
else
32153222
usename = "public";
32163223

3217-
appendStringInfo(&buffer, "%s", usename);
3224+
appendStringInfo(&buffer, "%s on server %s", usename,
3225+
srv->servername);
32183226
break;
32193227
}
32203228

src/test/regress/expected/foreign_data.out

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ CREATE USER MAPPING FOR current_user SERVER s1;
247247
DROP FOREIGN DATA WRAPPER foo; -- ERROR
248248
ERROR: cannot drop foreign-data wrapper foo because other objects depend on it
249249
DETAIL: server s1 depends on foreign-data wrapper foo
250-
user mapping for foreign_data_user depends on server s1
250+
user mapping for foreign_data_user on server s1 depends on server s1
251251
HINT: Use DROP ... CASCADE to drop the dependent objects too.
252252
SET ROLE regress_test_role;
253253
DROP FOREIGN DATA WRAPPER foo CASCADE; -- ERROR
@@ -256,7 +256,7 @@ RESET ROLE;
256256
DROP FOREIGN DATA WRAPPER foo CASCADE;
257257
NOTICE: drop cascades to 2 other objects
258258
DETAIL: drop cascades to server s1
259-
drop cascades to user mapping for foreign_data_user
259+
drop cascades to user mapping for foreign_data_user on server s1
260260
\dew+
261261
List of foreign-data wrappers
262262
Name | Owner | Handler | Validator | Access privileges | FDW Options | Description
@@ -528,10 +528,10 @@ CREATE USER MAPPING FOR current_user SERVER s3;
528528

529529
DROP SERVER s3; -- ERROR
530530
ERROR: cannot drop server s3 because other objects depend on it
531-
DETAIL: user mapping for foreign_data_user depends on server s3
531+
DETAIL: user mapping for foreign_data_user on server s3 depends on server s3
532532
HINT: Use DROP ... CASCADE to drop the dependent objects too.
533533
DROP SERVER s3 CASCADE;
534-
NOTICE: drop cascades to user mapping for foreign_data_user
534+
NOTICE: drop cascades to user mapping for foreign_data_user on server s3
535535
\des
536536
List of foreign servers
537537
Name | Owner | Foreign-data wrapper
@@ -1144,8 +1144,8 @@ GRANT USAGE ON FOREIGN SERVER s9 TO regress_test_role;
11441144
CREATE USER MAPPING FOR current_user SERVER s9;
11451145
DROP SERVER s9 CASCADE;
11461146
NOTICE: drop cascades to 2 other objects
1147-
DETAIL: drop cascades to user mapping for public
1148-
drop cascades to user mapping for unprivileged_role
1147+
DETAIL: drop cascades to user mapping for public on server s9
1148+
drop cascades to user mapping for unprivileged_role on server s9
11491149
RESET ROLE;
11501150
CREATE SERVER s9 FOREIGN DATA WRAPPER foo;
11511151
GRANT USAGE ON FOREIGN SERVER s9 TO unprivileged_role;
@@ -1170,14 +1170,14 @@ DROP ROLE regress_test_role; -- ERROR
11701170
ERROR: role "regress_test_role" cannot be dropped because some objects depend on it
11711171
DETAIL: privileges for server s4
11721172
privileges for foreign-data wrapper foo
1173-
owner of user mapping for regress_test_role
1174-
owner of user mapping for regress_test_role
1173+
owner of user mapping for regress_test_role on server s6
1174+
owner of user mapping for regress_test_role on server s5
11751175
owner of server s5
11761176
owner of server t2
11771177
DROP SERVER s5 CASCADE;
1178-
NOTICE: drop cascades to user mapping for regress_test_role
1178+
NOTICE: drop cascades to user mapping for regress_test_role on server s5
11791179
DROP SERVER t1 CASCADE;
1180-
NOTICE: drop cascades to user mapping for public
1180+
NOTICE: drop cascades to user mapping for public on server t1
11811181
DROP SERVER t2;
11821182
DROP USER MAPPING FOR regress_test_role SERVER s6;
11831183
-- This test causes some order dependent cascade detail output,
@@ -1188,8 +1188,8 @@ NOTICE: drop cascades to 5 other objects
11881188
\set VERBOSITY default
11891189
DROP SERVER s8 CASCADE;
11901190
NOTICE: drop cascades to 2 other objects
1191-
DETAIL: drop cascades to user mapping for foreign_data_user
1192-
drop cascades to user mapping for public
1191+
DETAIL: drop cascades to user mapping for foreign_data_user on server s8
1192+
drop cascades to user mapping for public on server s8
11931193
DROP ROLE regress_test_indirect;
11941194
DROP ROLE regress_test_role;
11951195
DROP ROLE unprivileged_role; -- ERROR

0 commit comments

Comments
 (0)