pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feedPATCH: SET ROLE as connection parameter
5+ messages / 2 participants
[nested] [flat]
* PATCH: SET ROLE as connection parameter
@ 2009-08-05 15:53 JUNG, Christian <christian.jung@saarstahl.com>
0 siblings, 2 replies; 5+ messages in thread
From: JUNG, Christian @ 2009-08-05 15:53 UTC (permalink / raw)
To: pgsql-jdbc
Hi,
here's a small patch to set the role at connection time (parameter "role"). The patch was made against the current CVS-version.
bye
Chris
--
phone: +49 6898/10-4987
web : www.saarstahl.de
mail : Hofstattstraße 106a
D 66333 Voelklingen
Attachments:
pgjdbc-role.patch (application/octet-stream, 1.4K) download
diff -ur pgjdbc.orig/doc/pgjdbc.xml pgjdbc/doc/pgjdbc.xml
--- pgjdbc.orig/doc/pgjdbc.xml 2009-06-20 17:19:40.000000000 +0200
+++ pgjdbc/doc/pgjdbc.xml 2009-08-05 17:50:25.110472000 +0200
@@ -669,6 +669,14 @@
</listitem>
</varlistentry>
+ <varlistentry>
+ <term><varname>role</varname> = <type>String</type></term>
+ <listitem>
+ <para>
+ Set the initial role of the session upon connection.
+ </para>
+ </listitem>
+ </varlistentry>
</variablelist>
</para>
diff -ur pgjdbc.orig/org/postgresql/jdbc2/AbstractJdbc2Connection.java pgjdbc/org/postgresql/jdbc2/AbstractJdbc2Connection.java
--- pgjdbc.orig/org/postgresql/jdbc2/AbstractJdbc2Connection.java 2009-07-01 07:00:40.000000000 +0200
+++ pgjdbc/org/postgresql/jdbc2/AbstractJdbc2Connection.java 2009-08-05 17:43:52.702374000 +0200
@@ -175,6 +175,17 @@
openStackTrace = new Throwable("Connection was created at this point:");
enableDriverManagerLogging();
}
+
+ // Set role if supplied:
+ String role = info.getProperty("role");
+ if (role != null)
+ {
+ if (logger.logDebug())
+ {
+ logger.debug(" role = " + role);
+ }
+ execSQLUpdate("SET ROLE '" + escapeString(role) + "'");
+ }
}
private final TimestampUtils timestampUtils;
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: PATCH: SET ROLE as connection parameter
@ 2009-08-27 11:39 JUNG, Christian <christian.jung@saarstahl.com>
parent: JUNG, Christian <christian.jung@saarstahl.com>
1 sibling, 0 replies; 5+ messages in thread
From: JUNG, Christian @ 2009-08-27 11:39 UTC (permalink / raw)
To: pgsql-jdbc
Hi,
I've submitted a patch some time ago, which enables the user to set the
role within the connection string. It enables applications, which don't
have the knowledge of PostgreSQL-roles or "fine-tuning-mechanisms", to
use roles.
Has anyone reviewed this patch?
bye
Chris
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: PATCH: SET ROLE as connection parameter
@ 2009-09-02 16:30 Kris Jurka <books@ejurka.com>
parent: JUNG, Christian <christian.jung@saarstahl.com>
1 sibling, 1 reply; 5+ messages in thread
From: Kris Jurka @ 2009-09-02 16:30 UTC (permalink / raw)
To: JUNG, Christian <christian.jung@saarstahl.com>; +Cc: pgsql-jdbc
On Wed, 5 Aug 2009, JUNG, Christian wrote:
> here's a small patch to set the role at connection time (parameter
> "role"). The patch was made against the current CVS-version.
>
1) Can this be done in the V3 ConnectionFactoryImpl's sendStartupPacket by
adding it to the params array? If so that would save a network roundtrip
per connection that used this option.
2) It doesn't have Datasource support. Any option that can be set via the
URL should also be settable on a Datasource.
3) In the past people have asked to be able to set other GUC parameters
(search_path, optimizer hints, ...) and we've resisted because we didn't
want to support some, but not all of these options. If we're going to do
this one, we should probably bite the bullet and do search_path as well
because that's a pretty commonly requested item.
Kris Jurka
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: PATCH: SET ROLE as connection parameter
@ 2009-09-03 10:47 JUNG, Christian <christian.jung@saarstahl.com>
parent: Kris Jurka <books@ejurka.com>
0 siblings, 1 reply; 5+ messages in thread
From: JUNG, Christian @ 2009-09-03 10:47 UTC (permalink / raw)
To: Kris Jurka <books@ejurka.com>; +Cc: pgsql-jdbc
> -----Original Message-----
> From: Kris Jurka [mailto:books@ejurka.com]
> Sent: Wednesday, September 02, 2009 6:30 PM
> To: JUNG, Christian
> Cc: pgsql-jdbc@postgresql.org
> Subject: Re: [JDBC] PATCH: SET ROLE as connection parameter
> 1) Can this be done in the V3 ConnectionFactoryImpl's
sendStartupPacket by
> adding it to the params array? If so that would save a network
roundtrip
> per connection that used this option.
I'm afraid that setting the role in the startup packet won't work. It's
only possible to change the role if the connection is in transaction
state (as far as I understand the GUC stuff in the backend code
correctly).
> want to support some, but not all of these options. If we're going to
do
> this one, we should probably bite the bullet and do search_path as
well
> because that's a pretty commonly requested item.
What's your opinion about the implementation?
Should the options be stored in a HashMap and the user be allowed to set
any key-/value-pair (no check if keys are allowed/mistyped, easy to use
new features) or should there be dedicated getter/setter (new features
have to be coded)?
bye
Chris
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: PATCH: SET ROLE as connection parameter
@ 2009-09-04 00:49 Kris Jurka <books@ejurka.com>
parent: JUNG, Christian <christian.jung@saarstahl.com>
0 siblings, 0 replies; 5+ messages in thread
From: Kris Jurka @ 2009-09-04 00:49 UTC (permalink / raw)
To: JUNG, Christian <christian.jung@saarstahl.com>; +Cc: pgsql-jdbc
On Thu, 3 Sep 2009, JUNG, Christian wrote:
> sendStartupPacket by
>> adding it to the params array? If so that would save a network
>> -----Original Message-----
>> 1) Can this be done in the V3 ConnectionFactoryImpl's
> roundtrip
>> per connection that used this option.
>
> I'm afraid that setting the role in the startup packet won't work. It's
> only possible to change the role if the connection is in transaction
> state (as far as I understand the GUC stuff in the backend code
> correctly).
Hmm, it looks like this works on CVS HEAD, but not before that. It must
be related to the removal of flatfiles.c. We can't make any version
specific decisions prior to establishing a connection, so we can't do it
in the startup packet, but I think it should still be in the
ConnectionFactory code. For the V2 Protocol it can be done in the
existing network trip done by runInitialQueries.
> Should the options be stored in a HashMap and the user be allowed to set
> any key-/value-pair (no check if keys are allowed/mistyped, easy to use
> new features) or should there be dedicated getter/setter (new features
> have to be coded)?
The previous discussion was that this wouldn't work for Datasources which
have to be accessed in a Java-Bean(y) way, so they can only take simply
parameters, not a Map. So I'd just do role and search_path for the moment
because we don't have any good ideas on how a general solution would work.
Kris Jurka
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2009-09-04 00:49 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2009-08-05 15:53 PATCH: SET ROLE as connection parameter JUNG, Christian <christian.jung@saarstahl.com>
2009-08-27 11:39 ` JUNG, Christian <christian.jung@saarstahl.com>
2009-09-02 16:30 ` Kris Jurka <books@ejurka.com>
2009-09-03 10:47 ` JUNG, Christian <christian.jung@saarstahl.com>
2009-09-04 00:49 ` Kris Jurka <books@ejurka.com>
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