patternsqlMinor
PostgreSQL schemas and search_path
Viewed 0 times
postgresqlandsearch_pathschemas
Problem
I'm reading Oreilly's PostgreSQL: Up and Running, and in the section Organizing Your Database Using Schemas it says the
For example, if we wanted all objects in contrib to be accessible without schema qualification, we would change our database as follows:
However, after typing the command above, I still can't refer to tables in schemas other then
Gives:
But if I use
Gives:
Does the default
search_path may be set at the database level:For example, if we wanted all objects in contrib to be accessible without schema qualification, we would change our database as follows:
ALTER DATABASE mydb SET search_path="$user",public,contrib;However, after typing the command above, I still can't refer to tables in schemas other then
public without qualifying them:ALTER DATABASE auth SET search_path="$user",public,staging;`
\d usersGives:
Did not find any relation named "users".But if I use
\d staging.users, it works.SHOW search_path;Gives:
search_path
----------------
"$user",publicDoes the default
search_path from postgresql.conf override the per-database value set with ALTER DATABASE ... SET search_path ? If that's the case, what's the use of the per-database value?Solution
The citation from the
SET related paragraph of the ALTER DATABASE documentation section is "Whenever a new session is subsequently started in that database, the specified value becomes the session default value". So the changes will take effect for new sessions only. You just need to reconnect.Context
StackExchange Database Administrators Q#22301, answer score: 6
Revisions (0)
No revisions yet.