How to set permanent schema path to user in PostgreSQL

In this article, we will see how to set permanent schema path to user in PostgreSQL with examples. We can set it by using ALTER ROLE command.

Syntax to set permanent schema path to user in PostgreSQL:

ALTER ROLE your_role_name SET search_path TO schema_name;

Examples:

1. Go to the database in which you want to set the schema path.

\c r2schools

2. Then, run the command to set ‘sales’ schema as permanent or default schema to user ‘james’ in PostgreSQL.

ALTER ROLE james SET search_path TO sales;

How to set permanent schema path to user in PostgreSQL

3. Now, login with the role and verify the default schema name.

psql -U james -d r2schools show search_path;

So, in this article, we have seen how to set default or permanent schema path to user/role in PostgreSQL.