ALTER USER MAPPING 是一个 DDL 命令,用于修改 PostgreSQL 数据库用户与外部服务器的映射关系。
ALTER USER MAPPING 命令添加于 PostgreSQL 8.4。
变更历史
- PostgreSQL 14
- 添加了
ALTER USER MAPPING ... OWNER TO CURRENT_ROLE语法(提交 45b98057)
- 添加了
- PostgreSQL 8.4
- 添加 (提交 cae565e5)
示例
ALTER USER MAPPING 的使用示例
postgres=# CREATE USER MAPPING FOR CURRENT_USER SERVER fdw_test OPTIONS (user 'foo', password 'bar'); CREATE USER MAPPING postgres=# ALTER USER MAPPING FOR postgres SERVER fdw_test OPTIONS (SET password 'baz'); ALTER USER MAPPING
请注意,如果一个选项在没有明确指定 ADD、SET 或 DROP 中的一个时提供,则会假定为 ADD。如果该选项先前已设置,这将导致错误,例如:
postgres=# ALTER USER MAPPING FOR postgres SERVER fdw_test OPTIONS (password 'zoo); ERROR: option "password" provided more than once
在这种情况下,必须明确提供 SET。
反之,如果为先前未添加的选项提供了 SET,也会发生错误。
postgres=# CREATE USER MAPPING FOR foo SERVER fbw_test options(username 'bar'); CREATE USER MAPPING postgres=# ALTER USER MAPPING FOR foo SERVER fdw_test OPTIONS (SET password 'baz'); ERROR: option "password" not found
参考资料
- PostgreSQL 文档: ALTER USER MAPPING
