--查询所有非系统库的database名称 SELECT ss.datname FROM ( SELECT d.datname, d.oid, pg_get_userbyid(d.datdba) AS owner, shobj_description(d.oid, 'pg_database') AScomment, 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 ) ss WHERE ss.datname notin ('hcatalog','template1','template0','postgres','gpadmin')
1 2 3 4 5 6 7 8
--查询所有非系统schema SELECT ss.Name from ( SELECT n.nspname ASName,pg_catalog.pg_get_userbyid(n.nspowner) AS Owner FROM pg_catalog.pg_namespace n WHERE (n.nspname !~ '^pg_temp_'OR n.nspname = (pg_catalog.current_schemas(true))[1]) ORDERBY1 ) ss WHERE ss.Name !='hawq_toolkit'and ss.Name !='information_schema'and ss.Name!~ '^pg_'and ss.Owner!='guest'
--查询当前库所有schema下的用户表和用户视图 SELECT ss.schema || '.' || ss.name as tableName,owner,type FROM( SELECT n.nspname asschema, c.relname asname, CASE c.relkind WHEN'r'THEN'table'WHEN'v'THEN'view'WHEN'i'THEN'index'WHEN'S'THEN'sequence'WHEN's'THEN'special'ENDastype, pg_catalog.pg_get_userbyid(c.relowner) as owner FROM pg_catalog.pg_class c LEFTJOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace WHERE c.relkind IN ('r','v','S','') AND c.relstorage IN ('h', 'a', 'c', 'p','x','f','v','') AND n.nspname <> 'pg_catalog' AND n.nspname <> 'information_schema' AND n.nspname <> 'hawq_toolkit' AND n.nspname !~ '^pg_toast' --AND pg_catalog.pg_table_is_visible(c.oid) --当前模式 ORDERBY1,2 ) ss WHERE ss.owner!='guest'; -- 排除掉已经授权过的表 and ss.schema || '.' || ss.name not in ( select table_schema|| '.' || table_name as tableName from information_schema.role_table_grants where grantee='guest'and privilege_type='SELECT' );