美文网首页
【Postgres】Postgres schema名 跟 use

【Postgres】Postgres schema名 跟 use

作者: Bogon | 来源:发表于2024-12-06 12:25 被阅读0次

最佳实践:schema名 跟 user名 保持一致

psql  --command "create schema ${schema}"

psql  --command "create user ${schema} password 'XXX'"

psql  --command "alter schema ${schema} owner to ${schema}"

psql  --command "alter user ${schema} set search_path to ${schema}"

schema与user一致,并让schema归属对应的schema,且把默认schema设置成对应的schema

spring.datasource.druid.url=jdbc:postgresql://ip:port/${db}?currentSchema=${schema}

Postgres跨库关联表,类似MySQL跨实例关联,要么是做PG的外部表或者DBLINK(网络层有消耗),才能关联。

如 A库 和 B库 ,不能 select xxx from A.xxx join B.xxx , 只能依赖应用调取到对应的数据后去应用层做单独计算,或者把有业务关联的放到同一个DB里面。

如果将所有DB的表放到该DB的public下,可能表名有冲突风险!
如果将表放在public 这个 schema 下,那么能连这个库的所有用户都能看到 public 下的表,有安全风险!

相关文章

网友评论

      本文标题:【Postgres】Postgres schema名 跟 use

      本文链接:https://www.haomeiwen.com/subject/tvkbsjtx.html