更改用户的默认搜索路径

使用以下命令,可以设置用户的默认 search_path。

  1. 在设置默认架构之前检查搜索路径。
postgres=# \c postgres user1
You are now connected to database "postgres" as user "user1".
postgres=> show search_path;
  search_path    "$user",public
(1 row)
  1. 使用 alter user 命令设置 search_path 以附加新模式 my_schema
postgres=> \c postgres postgres
You are now connected to database "postgres" as user "postgres".
postgres=# alter user user1 set search_path='my_schema, "$user", public';
ALTER ROLE
  1. 执行后检查结果。
postgres=# \c postgres user1
Password for user user1: 
You are now connected to database "postgres" as user "user1".
postgres=> show search_path;
 search_path  my_schema, "$user", public
(1 row)

替代方案:

postgres=# set role user1;
postgres=# show search_path;
 search_path  my_schema, "$user", public
(1 row)