更改使用者的預設搜尋路徑
使用以下命令,可以設定使用者的預設 search_path。
- 在設定預設架構之前檢查搜尋路徑。
postgres=# \c postgres user1
You are now connected to database "postgres" as user "user1".
postgres=> show search_path;
search_path "$user",public
(1 row)
- 使用
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
- 執行後檢查結果。
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)