springboot 連接 postgresql 指定模式Schema
一般的連接方式,我們創建數據庫之後,在public 的Schema(模式)下建表,這時使用連接方式
jdbc:postgresql://localhost:5432/postgresql
在這種連接方式下,默認連接使用的是postgresql數據庫的public 模式
在業務場景中有時允許多個用戶使用一個數據庫並且不會互相干擾。這時需要在使用同一個數據庫 新建其他模式進行連接。這時在springboot的數據源jdbc配置時注意。
postgresql-> 9.3 及以前的版本指定方式
spring.datasource.url=jdbc:postgresql://localhost:5432/postgresql?searchpath=newschema
postgresql-> 9.4 及以後的版本指定方式
spring.datasource.url=jdbc:postgresql://localhost:5432/postgresql?currentSchema=newschema