Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[JDBC] Search path in connection string

488 views
Skip to first unread message

Julien Demoor

unread,
Jul 30, 2012, 8:55:56 AM7/30/12
to
There have been a number of messages on this list suggesting that the Postgres JDBC driver should support setting the search path as part of the connection string.

Can this be considered?

I have a use case where there doesn't appear to be any good alternatives: using BIRT, with multiple clients sharing a Postgres database with one schema each, one cannot just execute a SET SCHEMA statement (UPDATE pg_settings ... is not possible either) and qualifying object names is also not always possible (say, if there are stored procedures involved that use unqualified object names).

Besides being useful in this case and surely others, this feature makes sense: schemas can be used to offer separation of database objects very similar to that offered by having multiple databases, and the database itself is part of the connection string.


Regards,
Julien

David Johnston

unread,
Jul 30, 2012, 8:41:17 PM7/30/12
to

From: pgsql-jd...@postgresql.org [mailto:pgsql-jd...@postgresql.org] On Behalf Of Julien Demoor
Sent: Monday, July 30, 2012 8:56 AM
To: pgsql...@postgresql.org
Subject: [JDBC] Search path in connection string

Julien

 

 

You can customize the connection string to accomplish this.  You vary the “user” that is connecting and configure a search_path specific to that user.

 

ALTER ROLE custom_role SET search_path = …

 

David J.

 

Valentine Gogichashvili

unread,
Jul 31, 2012, 10:03:12 AM7/31/12
to
Hello Julien,

As normally you would always use a connection pool (like BoneCP or c3p0), you can easily configure an InitSQL property to initialize your connection as needed.

Note that JDBC driver for now does not support search_path at all, as the OID cache lookup is not taking it into an account. So prepare for some crazy problems when for example returning a type that exists in several schemas with the same name. 

With best regards, 

-- Valentine

Valentine Gogichashvili

unread,
Jul 31, 2012, 3:40:11 PM7/31/12
to
On Tue, Jul 31, 2012 at 8:05 PM, Julien Demoor <jde...@gmail.com> wrote:
2012/7/31 Valentine Gogichashvili <val...@gmail.com>
Hello Julien,

As normally you would always use a connection pool (like BoneCP or c3p0), you can easily configure an InitSQL property to initialize your connection as needed.

Note that JDBC driver for now does not support search_path at all, as the OID cache lookup is not taking it into an account. So prepare for some crazy problems when for example returning a type that exists in several schemas with the same name. 

With best regards, 

-- Valentine

Hello Valentine,

I'll see if connection pools are available with BIRT (I'm using the integrated web viewer so I can't go around its limitations).

Thanks for the tip regarding the support for the search_path. Should I expect issues if the types that share a name across schemas have the same definition?

Regards,
Julien

Hello Julien, 

You can always write a simple wrapper, that will override getConnection() and preinizialize there as needed.

The problem is now, that OID cache for types does not take into an account search_path at all. So if you have 2 types, that have the same name in 2 different schemas, one of them will be taken practically randomly, and if you do not have luck, it will take the wrong one and postgres will throw a crazy exception when the driver will try to use the wrong OID when passing this type as a parameter for example. 

But it is very easy to patch the driver in case you will get such a problem. I suggested one quick-n-dirty patch once, and filed a bug report without a patch... (http://archives.postgresql.org/pgsql-jdbc/2011-03/msg00007.phphttp://archives.postgresql.org/pgsql-jdbc/2011-12/msg00083.phpbut both messages had been ignored unfortunately. 

You can have a look in wich case I am getting a problem there here: http://tech.valgog.com/2012/01/schema-based-versioning-and-deployment.html

Regards, 

-- Valentin



Dave Cramer

unread,
Jul 31, 2012, 4:18:13 PM7/31/12
to
Valentine,

Any chance you could recreate that patch against current sources ?

Dave Cramer

dave.cramer(at)credativ(dot)ca
http://www.credativ.ca
--
Sent via pgsql-jdbc mailing list (pgsql...@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc

Radim Kolar

unread,
Jul 31, 2012, 12:44:08 PM7/31/12
to
Dne 31.7.2012 16:03, Valentine Gogichashvili napsal(a):
> Note that JDBC driver for now does not support search_path at all, as
> the OID cache lookup is not taking it into an account. So prepare for
> some crazy problems when for example returning a type that exists in
> several schemas with the same name.
This most likely explains while hibernate is going wild if table exists
in multiple schemas, from my observation it seems that schema is picked
at random.

Valentine Gogichashvili

unread,
Apr 12, 2013, 11:36:43 AM4/12/13
to
Hello Dave,

I have added a pull request, that should fix the problem with the search_path when searching for type OID in TypeInfoCache. If you would have time to review it and give your feedback, that would be wonderful.

https://github.com/pgjdbc/pgjdbc/pull/52

Cheers,

-- Valentine
0 new messages