2

Postgres extensions are installed in public schema. Set the search path for the app-specific schema on the DBCP datasource the following way:

  <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" primary="true">
    <property name="driverClassName" value="org.postgresql.Driver"/>
    <property name="url" value="jdbc:postgresql://myhost:myport/${db.gos_app.database}?searchpath=mySchema,public;?ApplicationName=${app.name}"/>
    <property name="connectionProperties" value="currentSchema=mySchema;"/>
    <property name="username" value="user"/>
    <property name="password" value="pw"/>
    <property name="defaultAutoCommit" value="false"/>
    <property name="maxActive" value="6" />
</bean>

But somehow I cannot use extensions installed in this public schema without qualifying them like "public.hstore".

1 Answer 1

2

Found the solution - JDBC driver does not know the searchpath property in the URL. But this has been nowhere reported :-( Instead currentSchema is given to driver which is then mapped to native Postgres searchpath (thus probably overwriting the default one there with public included). Not intuitive!

So the solution looks like this:

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" primary="true">
<property name="driverClassName" value="org.postgresql.Driver"/>
<property name="url" value="jdbc:postgresql://myhost:myport/${db.gos_app.database}?ApplicationName=${app.name}"/>
<property name="connectionProperties" value="currentSchema=mySchema,public;"/>
<property name="username" value="user"/>
<property name="password" value="pw"/>
<property name="defaultAutoCommit" value="false"/>
<property name="maxActive" value="6" />

Sign up to request clarification or add additional context in comments.

1 Comment

Why don't you just change the search path for the database user? alter user set search_path = ...?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.