I have a postgres database with multiple schemas. When I connect to the database from a shell with psql
and I run \dt
it uses the default connection schema which is public. Is there a flag I can specify or how can I change the schema?
Postgresql – How to select a schema in postgres when using psql
postgresqlpsql
Related Topic
- Postgresql – How to exit from PostgreSQL command line utility: psql
- Postgresql – Run a PostgreSQL .sql file using command line arguments
- Postgresql – “use database_name” command in PostgreSQL
- Ruby-on-rails – Postgres could not connect to server
- Postgresql – List tables in a PostgreSQL schema
- Postgresql – psql: FATAL: database “
” does not exist - Sql – How to check if a table exists in a given schema
- Postgresql – How to create User/Database in script for Docker Postgres
Best Answer
In PostgreSQL the system determines which table is meant by following a search path, which is a list of schemas to look in.
The first matching table in the search path is taken to be the one wanted, otherwise, if there is no match a error is raised, even if matching table names exist in other schemas in the database.
To show the current search path you can use the following command:
And to put the new schema in the path, you could use:
Or if you want multiple schemas:
Reference: https://www.postgresql.org/docs/current/static/ddl-schemas.html