Antworten:
Sie sollten in der Lage sein, nur select * from information_schema.tables
eine Liste aller von Postgres verwalteten Tabellen für eine bestimmte Datenbank abzurufen.
Sie können auch ein hinzufügen where table_schema = 'information_schema'
, um nur die Tabellen im Informationsschema anzuzeigen.
Verwenden Sie zum Auflisten Ihrer Tabellen:
SELECT table_name FROM information_schema.tables WHERE table_schema='public'
Es werden nur Tabellen aufgelistet, die Sie erstellen.
\dt information_schema.
aus psql heraus sollte in Ordnung sein.
Der Befehl "\ z" ist auch eine gute Möglichkeit, Tabellen in der interaktiven psql-Sitzung aufzulisten.
z.B.
# 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)
Für ein privates Schema 'xxx'
in postgresql:
SELECT table_name FROM information_schema.tables
WHERE table_schema = 'xxx' AND table_type = 'BASE TABLE'
Ohne table_type = 'BASE TABLE'
werden Sie Tabellen und Ansichten auflisten
1. Holen Sie sich alle Tabellen und Ansichten aus information_schema.tables, einschließlich der von information_schema und pg_catalog.
select * from information_schema.tables
2.get Tabellen und Ansichten gehören zu bestimmten Schema
select * from information_schema.tables
where table_schema not in ('information_schema', 'pg_catalog')
3.get Tabellen nur (fast \ dt)
select * from information_schema.tables
where table_schema not in ('information_schema', 'pg_catalog') and
table_type = 'BASE TABLE'
where table_schema not in ('information_schema', 'pg_catalog')
ist?
Wenn Sie eine schnelle und schmutzige Einzeiler-Abfrage wünschen:
select * from information_schema.tables
Sie können es direkt im Abfrage-Tool ausführen, ohne psql öffnen zu müssen.
(Andere Beiträge schlagen nette, spezifischere Abfragen zu information_schema vor, aber als Neuzugang finde ich, dass diese einzeilige Abfrage mir hilft, die Tabelle in den Griff zu bekommen.)