Spring Boot - 如何为 PostgreSQL 设置默认架构?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30848854/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 01:55:53  来源:igfitidea点击:

Spring Boot - How to set the default schema for PostgreSQL?

javaspringhibernatepostgresql

提问by Incognito

What I am currently doing in my application.propertiesfile is:

我目前在我的application.properties文件中做的是:

spring.datasource.url=jdbc:postgresql://localhost:5432/myDB?currentSchema=mySchema

Isn't there another property for this? Since it looks hacky and according to a post (still finding the link sorry, will update later), it is only applicable to PostgreSQL 9.4.

没有其他属性可以用于此吗?由于它看起来很 hacky 并且根据帖子(仍然找到链接抱歉,稍后会更新),它仅适用于 PostgreSQL 9.4。

回答by Veluria

Since this is quite old and has no proper answer yet, the right property to set is the following:

由于这已经很老了并且还没有正确的答案,因此要设置的正确属性如下:

spring.jpa.properties.hibernate.default_schema=yourschema

回答by jcalloway

You can try setting the default schema for the jdbc user.

您可以尝试为 jdbc 用户设置默认架构。

1) ALTER USER user_name SET search_path to 'schema'

1) ALTER USER user_name SET search_path to 'schema'

2) Did you try this property? spring.datasource.schema

2)你试过这个属性吗?spring.datasource.schema

http://docs.spring.io/spring-boot/docs/current/reference/html/howto-database-initialization.html

http://docs.spring.io/spring-boot/docs/current/reference/html/howto-database-initialization.html