Spring Boot jdbc模板在自定义模式下的postgres中找不到表

Posted

技术标签:

【中文标题】Spring Boot jdbc模板在自定义模式下的postgres中找不到表【英文标题】:Spring boot jdbc template not finding table in postgres under custom schema 【发布时间】:2017-11-27 15:52:14 【问题描述】:

我的数据库有一些模式,我创建了一个名为应用程序的应用程序来保存我的应用程序特定的表。我将此模式添加到 postgres 的 search_path,但是当我使用 jdbc 模板进行查询时,它找不到表。如何让 jdbc 使用 search_path 来查找正在查询的表?

【问题讨论】:

【参考方案1】:

有几种选择:

1) 您可以在每个会话开始时set search_path to ..;,或

2) 你可以alter database yourdatabase set search_path to ...;,或者

3) 你可以alter role yourdbuser set search_path to ...;

选项 2 和 3 仅适用于新连接(不要忘记重新连接)。

另外,你可以在 postgresql.conf 中设置search_path,但是如果你有超过 1 个数据库,这个选项就不那么灵活了。

【讨论】:

以上是关于Spring Boot jdbc模板在自定义模式下的postgres中找不到表的主要内容,如果未能解决你的问题,请参考以下文章