pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feedSearch path in connection string
8+ messages / 6 participants
[nested] [flat]
* Search path in connection string
@ 2012-07-30 12:55 Julien Demoor <jdemoor@gmail.com>
0 siblings, 1 reply; 8+ messages in thread
From: Julien Demoor @ 2012-07-30 12:55 UTC (permalink / raw)
To: pgsql-jdbc
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.
The patch proposed in
http://postgresql.1045698.n5.nabble.com/Patch-to-allow-setting-schema-search-path-in-the-connectionU...
still applicable.
Regards,
Julien
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Search path in connection string
@ 2012-07-31 00:41 David Johnston <polobo@yahoo.com>
parent: Julien Demoor <jdemoor@gmail.com>
0 siblings, 1 reply; 8+ messages in thread
From: David Johnston @ 2012-07-31 00:41 UTC (permalink / raw)
To: 'Julien Demoor' <jdemoor@gmail.com>; pgsql-jdbc
From: pgsql-jdbc-owner@postgresql.org [mailto:pgsql-jdbc-owner@postgresql.org] On Behalf Of Julien Demoor
Sent: Monday, July 30, 2012 8:56 AM
To: pgsql-jdbc@postgresql.org
Subject: [JDBC] Search path in connection string
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.
The patch proposed in http://postgresql.1045698.n5.nabble.com/Patch-to-allow-setting-schema-search-path-in-the-connectionU... is still applicable.
Regards,
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.
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Search path in connection string
@ 2012-07-31 14:03 Valentine Gogichashvili <valgog@gmail.com>
parent: David Johnston <polobo@yahoo.com>
0 siblings, 2 replies; 8+ messages in thread
From: Valentine Gogichashvili @ 2012-07-31 14:03 UTC (permalink / raw)
To: Julien Demoor <jdemoor@gmail.com>; +Cc: pgsql-jdbc@postgresql.org, David Johnston <polobo@yahoo.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
On Tue, Jul 31, 2012 at 2:41 AM, David Johnston <polobo@yahoo.com> wrote:
> *From:* pgsql-jdbc-owner@postgresql.org [mailto:
> pgsql-jdbc-owner@postgresql.org] *On Behalf Of *Julien Demoor
> *Sent:* Monday, July 30, 2012 8:56 AM
> *To:* pgsql-jdbc@postgresql.org
> *Subject:* [JDBC] Search path in connection string****
>
> ** **
>
> 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.****
>
> ** **
>
> The patch proposed in
> http://postgresql.1045698.n5.nabble.com/Patch-to-allow-setting-schema-search-path-in-the-connectionU... still applicable.
> ****
>
> ** **
>
> Regards,****
>
> 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.****
>
> ** **
>
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Search path in connection string
@ 2012-07-31 16:44 Radim Kolar <hsn@filez.com>
parent: Valentine Gogichashvili <valgog@gmail.com>
1 sibling, 0 replies; 8+ messages in thread
From: Radim Kolar @ 2012-07-31 16:44 UTC (permalink / raw)
To: ; +Cc: pgsql-jdbc
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.
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Search path in connection string
@ 2012-07-31 19:40 Valentine Gogichashvili <valgog@gmail.com>
parent: Valentine Gogichashvili <valgog@gmail.com>
1 sibling, 1 reply; 8+ messages in thread
From: Valentine Gogichashvili @ 2012-07-31 19:40 UTC (permalink / raw)
To: Julien Demoor <jdemoor@gmail.com>; +Cc: pgsql-jdbc
On Tue, Jul 31, 2012 at 8:05 PM, Julien Demoor <jdemoor@gmail.com> wrote:
> 2012/7/31 Valentine Gogichashvili <valgog@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.php,
http://archives.postgresql.org/pgsql-jdbc/2011-12/msg00083.php) but 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
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Search path in connection string
@ 2012-07-31 20:18 Dave Cramer <pg@fastcrypt.com>
parent: Valentine Gogichashvili <valgog@gmail.com>
0 siblings, 1 reply; 8+ messages in thread
From: Dave Cramer @ 2012-07-31 20:18 UTC (permalink / raw)
To: Valentine Gogichashvili <valgog@gmail.com>; +Cc: Julien Demoor <jdemoor@gmail.com>; pgsql-jdbc
Valentine,
Any chance you could recreate that patch against current sources ?
Dave Cramer
dave.cramer(at)credativ(dot)ca
http://www.credativ.ca
On Tue, Jul 31, 2012 at 3:40 PM, Valentine Gogichashvili
<valgog@gmail.com> wrote:
> On Tue, Jul 31, 2012 at 8:05 PM, Julien Demoor <jdemoor@gmail.com> wrote:
>>
>> 2012/7/31 Valentine Gogichashvili <valgog@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.php,
> http://archives.postgresql.org/pgsql-jdbc/2011-12/msg00083.php) but 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
>
>
>
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Search path in connection string
@ 2012-08-16 15:29 Valentine Gogichashvili <valgog@gmail.com>
parent: Dave Cramer <pg@fastcrypt.com>
0 siblings, 1 reply; 8+ messages in thread
From: Valentine Gogichashvili @ 2012-08-16 15:29 UTC (permalink / raw)
To: Dave Cramer <pg@fastcrypt.com>; +Cc: Julien Demoor <jdemoor@gmail.com>; pgsql-jdbc
Hello Dave,
sorry, did not see your reply. I will try to write a patch.
There is one issue, with the patch implementation:
1. try to stay "backwards compatible", i.e. try to search in all existing
schemas but prefer the one from the search_path order (actually I do not
know if it really makes sense)
2. simply search according to search_path parameter, i.e. fail in case the
schema is not seen by the search_path logic
Regards,
-- Valentine Gogichashvili
On Tue, Jul 31, 2012 at 10:18 PM, Dave Cramer <pg@fastcrypt.com> wrote:
> Valentine,
>
> Any chance you could recreate that patch against current sources ?
>
> Dave Cramer
>
> dave.cramer(at)credativ(dot)ca
> http://www.credativ.ca
>
>
> On Tue, Jul 31, 2012 at 3:40 PM, Valentine Gogichashvili
> <valgog@gmail.com> wrote:
> > On Tue, Jul 31, 2012 at 8:05 PM, Julien Demoor <jdemoor@gmail.com>
> wrote:
> >>
> >> 2012/7/31 Valentine Gogichashvili <valgog@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.php
> ,
> > http://archives.postgresql.org/pgsql-jdbc/2011-12/msg00083.php) but 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
> >
> >
> >
>
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Search path in connection string
@ 2012-08-16 16:48 Luis Flores <luiscamposflores@gmail.com>
parent: Valentine Gogichashvili <valgog@gmail.com>
0 siblings, 0 replies; 8+ messages in thread
From: Luis Flores @ 2012-08-16 16:48 UTC (permalink / raw)
To: pgsql-jdbc
I would recommend to do the strict implementation (only honor
search_path), and define a new connection parameter
(search_all_schemas=true) which would be default for now, to maintain
the old behavior.
If one wants the strict behavior just add search_all_schemas=false to
the connection url, and in a later driver revision, change the default
to search_all_schemas=false.
You could also search only by search_path and, if that fails, search
all the rest, and output a warning about it.
In any case, I believe that it should be possible to have strict
behavior within the driver.
Luis Flores
On Thu, Aug 16, 2012 at 4:29 PM, Valentine Gogichashvili
<valgog@gmail.com> wrote:
> Hello Dave,
>
> sorry, did not see your reply. I will try to write a patch.
>
> There is one issue, with the patch implementation:
>
> 1. try to stay "backwards compatible", i.e. try to search in all existing
> schemas but prefer the one from the search_path order (actually I do not
> know if it really makes sense)
> 2. simply search according to search_path parameter, i.e. fail in case the
> schema is not seen by the search_path logic
>
> Regards,
>
> -- Valentine Gogichashvili
>
>
>
> On Tue, Jul 31, 2012 at 10:18 PM, Dave Cramer <pg@fastcrypt.com> wrote:
>>
>> Valentine,
>>
>> Any chance you could recreate that patch against current sources ?
>>
>> Dave Cramer
>>
>> dave.cramer(at)credativ(dot)ca
>> http://www.credativ.ca
>>
>>
>> On Tue, Jul 31, 2012 at 3:40 PM, Valentine Gogichashvili
>> <valgog@gmail.com> wrote:
>> > On Tue, Jul 31, 2012 at 8:05 PM, Julien Demoor <jdemoor@gmail.com>
>> > wrote:
>> >>
>> >> 2012/7/31 Valentine Gogichashvili <valgog@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.php,
>> > http://archives.postgresql.org/pgsql-jdbc/2011-12/msg00083.php) but 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
>> >
>> >
>> >
>
>
^ permalink raw reply [nested|flat] 8+ messages in thread
end of thread, other threads:[~2012-08-16 16:48 UTC | newest]
Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2012-07-30 12:55 Search path in connection string Julien Demoor <jdemoor@gmail.com>
2012-07-31 00:41 ` David Johnston <polobo@yahoo.com>
2012-07-31 14:03 ` Valentine Gogichashvili <valgog@gmail.com>
2012-07-31 16:44 ` Radim Kolar <hsn@filez.com>
2012-07-31 19:40 ` Valentine Gogichashvili <valgog@gmail.com>
2012-07-31 20:18 ` Dave Cramer <pg@fastcrypt.com>
2012-08-16 15:29 ` Valentine Gogichashvili <valgog@gmail.com>
2012-08-16 16:48 ` Luis Flores <luiscamposflores@gmail.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