PostgreSQL系統相關查詢[1]

來源:互聯網
上載者:User

標籤:postgresql

PG 系統查詢指令碼--查詢使用者進程及文本SELECT a.pid AS Id, a.usename AS User, a.client_addr AS Host, a.client_port AS Port, datname AS db, query AS Command, a.state AS Idle, l.mode as State, query_start AS Time, CASE WHEN c.relname IS NOT NULL THEN 'Locked Object: ' || c.relname ELSE 'Locked Transaction:' || l.virtualtransaction END AS Info FROM pg_stat_activity a LEFT JOIN pg_locks l ON a.pid = l.pid LEFT JOIN pg_class c ON l.relation = c.oid ORDER BY a.pid ASC, c.relname ASC--查詢表[2015-03-03 17:38:35.668] [002232] [localhost] [PGSQL]SELECT tablename, schemaname FROM pg_tables WHERE schemaname='public' ORDER BY schemaname, tablename--查詢檢視[2015-03-03 17:38:35.731] [002232] [localhost] [PGSQL]SELECT viewname, schemaname FROM pg_views WHERE schemaname='public' ORDER BY schemaname, viewname--查詢所屬視圖及其定義SELECT c.oid, c.relname, c.relacl, pg_get_userbyid(c.relowner) AS viewowner, pg_get_viewdef(c.oid) AS definition, obj_description(c.oid), n.nspname FROM pg_class c LEFT JOIN pg_namespace n ON n.oid = c.relnamespace WHERE c.relkind = 'v'::"char" AND n.nspname = 'public' --查詢架構名下表、表注釋及表行數SELECT c.oid, obj_description(c.oid),  c.relhasoids AS hasoids, n.nspname AS schemaname, c.relname AS tablename, pg_get_userbyid(c.relowner) AS tableowner, t.spcname AS "tablespace", c.relhasindex AS hasindexes, c.relhasrules AS hasrules, c.relhastriggers AS hastriggers, c.relacl, c.reltuples, ((SELECT count(*) FROM pg_inherits WHERE inhparent = c.oid) > 0) AS inhtable, i2.relname AS inhtablename, c.reloptions AS param FROM pg_class c LEFT JOIN pg_namespace n ON n.oid = c.relnamespace LEFT JOIN pg_tablespace t ON t.oid = c.reltablespace LEFT JOIN (pg_inherits i INNER JOIN pg_class c2 ON i.inhparent = c2.oid) i2 ON i2.inhrelid = c.oid WHERE (c.relkind = 'r'::"char") AND n.nspname = 'public'order by reltuples--查詢資料庫及所屬使用者和字元集SELECT d.datname, d.oid, pg_get_userbyid(d.datdba) AS owner, shobj_description(d.oid, 'pg_database') AS comment, t.spcname, d.datacl, d.datlastsysoid, d.encoding, pg_encoding_to_char(d.encoding) AS encodingname FROM pg_database d LEFT JOIN pg_tablespace t ON d.dattablespace=t.oid 


--EOF

PostgreSQL系統相關查詢[1]

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.