連接數據庫服務器,切換至postgres(或其他數據庫用戶)下,
psql--進入數據庫命令行終端,執行如下相關查詢操作:
顯示數據庫:
\l
連接指定的數據庫:
\c 數據庫名
查看當前實例下的表:
\dt
用sql語句方式查詢:
SELECT tablename FROM pg_tables;
查詢某張表的表結構及字段信息
\d tablename--實際表名
用sql語句方式查詢:
SELECT a.attnum, a.attname AS field, t.typname AS type, a.attlen AS length, a.atttypmod AS lengthvar , a.attnotnull AS notnull, b.description AS comment FROM pg_class c, pg_attribute a LEFT JOIN pg_description b ON a.attrelid = b.objoid AND a.attnum = b.objsubid, pg_type t WHERE c.relname = '實際的表名' AND a.attnum > 0 AND a.attrelid = c.oid AND a.atttypid = t.oid ORDER BY a.attnum;
