Alter default search path of user

suggest change

With the commands below, you can set a user’s default search_path.

  1. 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)
  1. Set search_path with ALTER USER so my_schema is searched first. ALTER USER is the same as ALTER 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
  1. Check the result after reconnecting. Role settings from ALTER ROLE ... SET apply 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)

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents