Alter default search path of user
suggest changeWith the commands below, you can set a user’s default search_path.
- Check the search path before changing it.
postgres=# \c postgres user1
You are now connected to database "postgres" as user "user1".
postgres=> show search_path;
search_path
----------------
"$user",public
(1 row)
- Set
search_pathwithALTER USERsomy_schemais searched first.ALTER USERis the same asALTER ROLE.
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
- Check the result after reconnecting. Role settings from
ALTER ROLE ... SETapply at login, not in the current session.
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)
SET ROLE does not apply those settings. In the existing postgres session the path stays whatever that login set:
postgres=# set role user1;
SET
postgres=# show search_path;
search_path
----------------
"$user", public
(1 row)
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents