I have created a new schema in my PostgreSQl database with psql:
CREATE SCHEMA my_schema;
But when I issue the \dt
command, I see only the tables that are in the public
schema. However, I can access all the tables in my_schema
with my_schema.table_name
.
How can I see all the tables from all the schemas in psql?
In PostgreSQL, by default, every database owns a default Schema named public. If you do not mention schema_name while creating or accessing the object then PostgreSQL will consider the schema_name as public.
Public schema and public roleWhen a new database is created, PostgreSQL by default creates a schema named public and grants access on this schema to a backend role named public . All new users and roles are by default granted this public role, and therefore can create objects in the public schema.
How to Use Schema With PostgreSQL. To access an object of a database schema, we must specify the schema's name before the name of a given database object that we want to use. For example, to query table product within schema store, we need to use the qualified name of the table: SELECT * FROM store.
For your schema (note the period after the schema name):
\dt my_schema.
Or:
SET search_path TO my_schema, public; \dt
For all schemas:
\dt *.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With