Re: [HACKERS] object description for FDW user mappings

2015-03-05 Thread Amit Langote
On 06-03-2015 AM 01:32, Tom Lane wrote:
 Alvaro Herrera alvhe...@2ndquadrant.com writes:
  appendStringInfo(buffer, _(user mapping for %s in server %s), 
 usename,
   srv-servername);
 
 +1 for the concept, but to be nitpicky, in doesn't seem like the right
 word here.  on server would read better to me; or perhaps at server.
 

One more option may be for server (reading the doc for CREATE USER MAPPING)

Thanks,
Amit



-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] object description for FDW user mappings

2015-03-05 Thread Amit Langote
On 06-03-2015 AM 09:18, Amit Langote wrote:
 On 06-03-2015 AM 01:32, Tom Lane wrote:

 +1 for the concept, but to be nitpicky, in doesn't seem like the right
 word here.  on server would read better to me; or perhaps at server.

 
 One more option may be for server (reading the doc for CREATE USER MAPPING)

Oh, I see it's been done that way already.

Thanks,
Amit



-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] object description for FDW user mappings

2015-03-05 Thread Amit Langote
On 06-03-2015 AM 09:30, Tom Lane wrote:
 Amit Langote langote_amit...@lab.ntt.co.jp writes:
 
 One more option may be for server (reading the doc for CREATE USER MAPPING)
 
 Hm, but then you'd have user mapping for foo for server bar, which
 doesn't read so nicely either.
 

Yeah, I had totally missed the for foo part; I was thinking of it as of foo.

By the way, in this case, is foo the name/id of a local user or does it
really refer to some foo on the remote server?

Thanks,
Amit



-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] object description for FDW user mappings

2015-03-05 Thread Tom Lane
Amit Langote langote_amit...@lab.ntt.co.jp writes:
 By the way, in this case, is foo the name/id of a local user or does it
 really refer to some foo on the remote server?

It's the name of a local user.  I see your point that somebody might
misread this as suggesting that it's a remote username, but not sure
that there's anything great we can do here to disambiguate that.

regards, tom lane


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] object description for FDW user mappings

2015-03-05 Thread Tom Lane
Amit Langote langote_amit...@lab.ntt.co.jp writes:
 On 06-03-2015 AM 01:32, Tom Lane wrote:
 +1 for the concept, but to be nitpicky, in doesn't seem like the right
 word here.  on server would read better to me; or perhaps at server.

 One more option may be for server (reading the doc for CREATE USER MAPPING)

Hm, but then you'd have user mapping for foo for server bar, which
doesn't read so nicely either.

regards, tom lane


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] object description for FDW user mappings

2015-03-05 Thread David G Johnston
Tom Lane-2 wrote
 Amit Langote lt;

 Langote_Amit_f8@.co

 gt; writes:
 By the way, in this case, is foo the name/id of a local user or does it
 really refer to some foo on the remote server?
 
 It's the name of a local user.  I see your point that somebody might
 misread this as suggesting that it's a remote username, but not sure
 that there's anything great we can do here to disambiguate that.

Yeah, clarifying that point seems to add verbosity for little gain.

On the message aspect is it against style to use composite notation in a
case like this?

user mapping (%s, %s)

It is basically a single, if compound, noun so adding in/at/to doesn't feel
right...

David J.





--
View this message in context: 
http://postgresql.nabble.com/object-description-for-FDW-user-mappings-tp5840655p5840729.html
Sent from the PostgreSQL - hackers mailing list archive at Nabble.com.


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] object description for FDW user mappings

2015-03-05 Thread Tom Lane
Alvaro Herrera alvhe...@2ndquadrant.com writes:
 When commit cae565e503 introduced FDW user mappings, it used this in
 getObjectDescription for them:
   appendStringInfo(buffer, _(user mapping for %s), usename);

 This was later mostly copied (by yours truly) as object identity by
 commit f8348ea32e wherein I used this:
   appendStringInfo(buffer, %s, usename);

 As it turns out, this is wrong, because the pg_user_mapping catalog has
 a two-column primary key which is user OID and server OID.  Therefore
 it seems to me that the correct object description and identity must
 include both username and server name.  I propose we change the above to
 this:

   appendStringInfo(buffer, _(user mapping for %s in server %s), 
 usename,
srv-servername);

+1 for the concept, but to be nitpicky, in doesn't seem like the right
word here.  on server would read better to me; or perhaps at server.

regards, tom lane


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


[HACKERS] object description for FDW user mappings

2015-03-05 Thread Alvaro Herrera
When commit cae565e503 introduced FDW user mappings, it used this in
getObjectDescription for them:

appendStringInfo(buffer, _(user mapping for %s), usename);

This was later mostly copied (by yours truly) as object identity by
commit f8348ea32e wherein I used this:
appendStringInfo(buffer, %s, usename);

As it turns out, this is wrong, because the pg_user_mapping catalog has
a two-column primary key which is user OID and server OID.  Therefore
it seems to me that the correct object description and identity must
include both username and server name.  I propose we change the above to
this:

appendStringInfo(buffer, _(user mapping for %s in server %s), 
usename,
 srv-servername);

I propose to apply the (appropriately rebased) attached patch to all
back branches.  Note in particular the wording changes in some error
messages in the foreign_data test.

-- 
Álvaro Herrerahttp://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training  Services
From 82e8814c9f4b89d31d51b2fa370add1c04ae0f12 Mon Sep 17 00:00:00 2001
From: Alvaro Herrera alvhe...@alvh.no-ip.org
Date: Thu, 5 Mar 2015 12:30:53 -0300
Subject: [PATCH] fix user mapping object description/identity

---
 src/backend/catalog/objectaddress.c| 30 --
 src/test/regress/expected/foreign_data.out | 24 
 2 files changed, 32 insertions(+), 22 deletions(-)

diff --git a/src/backend/catalog/objectaddress.c b/src/backend/catalog/objectaddress.c
index 70043fc..0740b4f 100644
--- a/src/backend/catalog/objectaddress.c
+++ b/src/backend/catalog/objectaddress.c
@@ -2510,14 +2510,17 @@ getObjectDescription(const ObjectAddress *object)
 HeapTuple	tup;
 Oid			useid;
 char	   *usename;
+Form_pg_user_mapping umform;
+ForeignServer *srv;
 
 tup = SearchSysCache1(USERMAPPINGOID,
 	  ObjectIdGetDatum(object-objectId));
 if (!HeapTupleIsValid(tup))
 	elog(ERROR, cache lookup failed for user mapping %u,
 		 object-objectId);
-
-useid = ((Form_pg_user_mapping) GETSTRUCT(tup))-umuser;
+umform = (Form_pg_user_mapping) GETSTRUCT(tup);
+useid = umform-umuser;
+srv = GetForeignServer(umform-umserver);
 
 ReleaseSysCache(tup);
 
@@ -2526,7 +2529,8 @@ getObjectDescription(const ObjectAddress *object)
 else
 	usename = public;
 
-appendStringInfo(buffer, _(user mapping for %s), usename);
+appendStringInfo(buffer, _(user mapping for %s in server %s), usename,
+ srv-servername);
 break;
 			}
 
@@ -3906,19 +3910,18 @@ getObjectIdentityParts(const ObjectAddress *object,
 			{
 HeapTuple	tup;
 Oid			useid;
+Form_pg_user_mapping umform;
+ForeignServer *srv;
 const char *usename;
 
-/* no objname support */
-if (objname)
-	*objname = NIL;
-
 tup = SearchSysCache1(USERMAPPINGOID,
 	  ObjectIdGetDatum(object-objectId));
 if (!HeapTupleIsValid(tup))
 	elog(ERROR, cache lookup failed for user mapping %u,
 		 object-objectId);
-
-useid = ((Form_pg_user_mapping) GETSTRUCT(tup))-umuser;
+umform = (Form_pg_user_mapping) GETSTRUCT(tup);
+useid = umform-umuser;
+srv = GetForeignServer(umform-umserver);
 
 ReleaseSysCache(tup);
 
@@ -3927,7 +3930,14 @@ getObjectIdentityParts(const ObjectAddress *object,
 else
 	usename = public;
 
-appendStringInfoString(buffer, usename);
+if (objname)
+{
+	*objname = list_make1(pstrdup(usename));
+	*objargs = list_make1(pstrdup(srv-servername));
+}
+
+appendStringInfo(buffer, %s in server %s, usename,
+ srv-servername);
 break;
 			}
 
diff --git a/src/test/regress/expected/foreign_data.out b/src/test/regress/expected/foreign_data.out
index 632b7e5..4d0de1f 100644
--- a/src/test/regress/expected/foreign_data.out
+++ b/src/test/regress/expected/foreign_data.out
@@ -247,7 +247,7 @@ CREATE USER MAPPING FOR current_user SERVER s1;
 DROP FOREIGN DATA WRAPPER foo;  -- ERROR
 ERROR:  cannot drop foreign-data wrapper foo because other objects depend on it
 DETAIL:  server s1 depends on foreign-data wrapper foo
-user mapping for foreign_data_user depends on server s1
+user mapping for foreign_data_user in server s1 depends on server s1
 HINT:  Use DROP ... CASCADE to drop the dependent objects too.
 SET ROLE regress_test_role;
 DROP FOREIGN DATA WRAPPER foo CASCADE;  -- ERROR
@@ -256,7 +256,7 @@ RESET ROLE;
 DROP FOREIGN DATA WRAPPER foo CASCADE;
 NOTICE:  drop cascades to 2 other objects
 DETAIL:  drop cascades to server s1
-drop cascades to user mapping for foreign_data_user
+drop cascades to user mapping for foreign_data_user in server s1
 \dew+
 List of foreign-data wrappers
 Name|   Owner   | Handler |Validator | Access privileges | FDW Options | Description 
@@ -526,10 +526,10 @@ CREATE