Is there any query available to list all tables in my Postgres DB.
I tried out one query like:
SELECT table_name FROM information_schema.tables
WHERE table_schema='public'
But this query returns views also.
How can i get only table names only, not views?
What bout this query (based on the description from manual)?
SELECT table_name
FROM information_schema.tables
WHERE table_schema='public'
AND table_type='BASE TABLE';
If you want list of database
SELECT datname FROM pg_database WHERE datistemplate = false;
If you want list of tables from current pg installation of all databases
SELECT table_schema,table_name FROM information_schema.tables
ORDER BY table_schema,table_name;
Open up the postgres terminal with the databse you would like:
psql dbname (run this line in a terminal)
then, run this command in the postgres environment
\d
This will describe all tables by name. Basically a list of tables by name ascending.
Then you can try this to describe a table by fields:
\d tablename.
Hope this helps.
select
relname as table
from
pg_stat_user_tables
where schemaname = 'public'
- This will not work if track_activities is disabled
select
tablename as table
from
pg_tables
where schemaname = 'public'
- Read more about pg_tables
How about giving just \dt
in psql
? See https://www.postgresql.org/docs/current/static/app-psql.html.
Try this:
SELECT table_name
FROM information_schema.tables
WHERE table_schema='public' AND table_type='BASE TABLE'
this one works!
来源:https://stackoverflow.com/questions/14730228/postgresql-query-to-list-all-table-names