What is the best way to list all of the tables within PostgreSQL's information_schema?
To clarify: I am working with an empty DB (I have not added any of my own tables), but I want to see every table in the information_schema structure.
The "\z" COMMAND is also a good way to list tables when inside the interactive psql session.
eg.
# psql -d mcdb -U admin -p 5555
mcdb=# /z
Access privileges for database "mcdb"
Schema | Name | Type | Access privileges
--------+--------------------------------+----------+---------------------------------------
public | activities | table |
public | activities_id_seq | sequence |
public | activities_users_mapping | table |
[..]
public | v_schedules_2 | view | {admin=arwdxt/admin,viewuser=r/admin}
public | v_systems | view |
public | vapp_backups | table |
public | vm_client | table |
public | vm_datastore | table |
public | vmentity_hle_map | table |
(148 rows)
1.get all tables and views from information_schema.tables, include those of information_schema and pg_catalog.
select * from information_schema.tables
2.get tables and views belong certain schema
select * from information_schema.tables
where table_schema not in ('information_schema', 'pg_catalog')
3.get tables only(almost \dt)
select * from information_schema.tables
where table_schema not in ('information_schema', 'pg_catalog') and
table_type = 'BASE TABLE'
If you want a quick and dirty one-liner query:
select * from information_schema.tables
You can run it directly in the Query tool without having to open psql.
(Other posts suggest nice more specific information_schema queries but as a newby, I am finding this one-liner query helps me get to grips with the table)