jdbc驱动依赖

  1. <dependency>
  2. <groupId>org.postgresql</groupId>
  3. <artifactId>postgresql</artifactId>
  4. <scope>runtime</scope>
  5. </dependency>

yml配置

在url里使用currentSchema参数指定schema
9.3版本以前使用searchpath参数
不能直接用spring.datasource.schema配置

spring:
  datasource:
    driver-class-name: org.postgresql.Driver
    url: jdbc:postgresql://localhost:5432/postgres?currentSchema=${spring.datasource.schema-name}
    schema-name: test
    username: mogdb
    password: 1234
    platform: postgres
    hikari:
      connection-timeout: 30000
      minimum-idle: 5
      maximum-pool-size: 30
      idle-timeout: 30000
      max-lifetime: 120000
      auto-commit: true
      connection-test-query: SELECT 1

然后就和mysql用法差不多了,要注意和mysql的差异