change postgresql schema on the fly

I am developing a multi-tenancy app with Spring Boot. Recently, I am trying to switch to PostgreSQL over MySQL. I want to use same database but different schema. However, I couldn't find a way to change schema on Spring Boot. On MySQL, it is possible via jdbc url by replacing the database name. On Postgre, I tried using currentSchema but it doesn't work. What could be the issue or how else can I solve it?

Upvotes: 0

Views: 488

Answers (1)

Mohamed Elgazar
Mohamed Elgazar

Reputation: 794

The search_path setting in PostgreSQL controls the order in which schemas are searched when resolving names. By default, it is set to "$user", meaning that names will be resolved in the current user's schema first, followed by the public schema.

You can override the default search_path by setting it in your application.properties file. The example above sets it to "my_schema". This will cause names to be resolved in the "my_schema"

You can try using the search_path setting in PostgreSQL. You can set it in your application.properties file like this:

spring.jpa.properties.hibernate.default_schema=my_schema

Upvotes: 1

Related Questions