|
| 1 | +{# ========================== Fetch Materialized View Properties ========================= #} |
| 2 | +{% if (vid and datlastsysoid) or scid %} |
| 3 | +SELECT |
| 4 | + c.oid, |
| 5 | + c.xmin, |
| 6 | + c.relname AS name, |
| 7 | + c.reltablespace AS spcoid, |
| 8 | + c.relispopulated AS with_data, |
| 9 | + CASE WHEN length(spcname::text) > 0 THEN spcname ELSE |
| 10 | + (SELECT sp.spcname FROM pg_catalog.pg_database dtb |
| 11 | + JOIN pg_catalog.pg_tablespace sp ON dtb.dattablespace=sp.oid |
| 12 | + WHERE dtb.oid = {{ did }}::oid) |
| 13 | + END as spcname, |
| 14 | + (SELECT st.setting from pg_catalog.pg_show_all_settings() st |
| 15 | + WHERE st.name = 'default_table_access_method') as default_amname, |
| 16 | + c.relacl, |
| 17 | + nsp.nspname as schema, |
| 18 | + pg_catalog.pg_get_userbyid(c.relowner) AS owner, |
| 19 | + description AS comment, |
| 20 | + ( |
| 21 | + SELECT array_agg(DISTINCT e.extname) |
| 22 | + FROM pg_depend d |
| 23 | + JOIN pg_extension e ON d.refobjid = e.oid |
| 24 | + WHERE d.objid = c.oid |
| 25 | + ) AS dependsonextensions, |
| 26 | + pg_catalog.pg_get_viewdef(c.oid, true) AS definition, |
| 27 | + {# ============= Checks if it is system view ================ #} |
| 28 | + {% if vid and datlastsysoid %} |
| 29 | + CASE WHEN {{vid}} <= {{datlastsysoid}} THEN True ELSE False END AS system_view, |
| 30 | + {% endif %} |
| 31 | + pg_catalog.array_to_string(c.relacl::text[], ', ') AS acl, |
| 32 | + (SELECT pg_catalog.array_agg(provider || '=' || label) FROM pg_catalog.pg_seclabels sl1 WHERE sl1.objoid=c.oid AND sl1.objsubid=0) AS seclabels, |
| 33 | + substring(pg_catalog.array_to_string(c.reloptions, ',') |
| 34 | + FROM 'fillfactor=([0-9]*)') AS fillfactor, |
| 35 | + (substring(pg_catalog.array_to_string(c.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)'))::BOOL AS autovacuum_enabled, |
| 36 | + substring(pg_catalog.array_to_string(c.reloptions, ',') |
| 37 | + FROM 'autovacuum_vacuum_threshold=([0-9]*)') AS autovacuum_vacuum_threshold, |
| 38 | + substring(pg_catalog.array_to_string(c.reloptions, ',') |
| 39 | + FROM 'autovacuum_vacuum_scale_factor=([0-9]*[.]?[0-9]*)') AS autovacuum_vacuum_scale_factor, |
| 40 | + substring(pg_catalog.array_to_string(c.reloptions, ',') |
| 41 | + FROM 'autovacuum_analyze_threshold=([0-9]*)') AS autovacuum_analyze_threshold, |
| 42 | + substring(pg_catalog.array_to_string(c.reloptions, ',') |
| 43 | + FROM 'autovacuum_analyze_scale_factor=([0-9]*[.]?[0-9]*)') AS autovacuum_analyze_scale_factor, |
| 44 | + substring(pg_catalog.array_to_string(c.reloptions, ',') |
| 45 | + FROM 'autovacuum_vacuum_cost_delay=([0-9]*)') AS autovacuum_vacuum_cost_delay, |
| 46 | + substring(pg_catalog.array_to_string(c.reloptions, ',') |
| 47 | + FROM 'autovacuum_vacuum_cost_limit=([0-9]*)') AS autovacuum_vacuum_cost_limit, |
| 48 | + substring(pg_catalog.array_to_string(c.reloptions, ',') |
| 49 | + FROM 'autovacuum_freeze_min_age=([0-9]*)') AS autovacuum_freeze_min_age, |
| 50 | + substring(pg_catalog.array_to_string(c.reloptions, ',') |
| 51 | + FROM 'autovacuum_freeze_max_age=([0-9]*)') AS autovacuum_freeze_max_age, |
| 52 | + substring(pg_catalog.array_to_string(c.reloptions, ',') |
| 53 | + FROM 'autovacuum_freeze_table_age=([0-9]*)') AS autovacuum_freeze_table_age, |
| 54 | + (substring(pg_catalog.array_to_string(tst.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)'))::BOOL AS toast_autovacuum_enabled, |
| 55 | + substring(pg_catalog.array_to_string(tst.reloptions, ',') |
| 56 | + FROM 'autovacuum_vacuum_threshold=([0-9]*)') AS toast_autovacuum_vacuum_threshold, |
| 57 | + substring(pg_catalog.array_to_string(tst.reloptions, ',') |
| 58 | + FROM 'autovacuum_vacuum_scale_factor=([0-9]*[.]?[0-9]*)') AS toast_autovacuum_vacuum_scale_factor, |
| 59 | + substring(pg_catalog.array_to_string(tst.reloptions, ',') |
| 60 | + FROM 'autovacuum_analyze_threshold=([0-9]*)') AS toast_autovacuum_analyze_threshold, |
| 61 | + substring(pg_catalog.array_to_string(tst.reloptions, ',') |
| 62 | + FROM 'autovacuum_analyze_scale_factor=([0-9]*[.]?[0-9]*)') AS toast_autovacuum_analyze_scale_factor, |
| 63 | + substring(pg_catalog.array_to_string(tst.reloptions, ',') |
| 64 | + FROM 'autovacuum_vacuum_cost_delay=([0-9]*)') AS toast_autovacuum_vacuum_cost_delay, |
| 65 | + substring(pg_catalog.array_to_string(tst.reloptions, ',') |
| 66 | + FROM 'autovacuum_vacuum_cost_limit=([0-9]*)') AS toast_autovacuum_vacuum_cost_limit, |
| 67 | + substring(pg_catalog.array_to_string(tst.reloptions, ',') |
| 68 | + FROM 'autovacuum_freeze_min_age=([0-9]*)') AS toast_autovacuum_freeze_min_age, |
| 69 | + substring(pg_catalog.array_to_string(tst.reloptions, ',') |
| 70 | + FROM 'autovacuum_freeze_max_age=([0-9]*)') AS toast_autovacuum_freeze_max_age, |
| 71 | + substring(pg_catalog.array_to_string(tst.reloptions, ',') |
| 72 | + FROM 'autovacuum_freeze_table_age=([0-9]*)') AS toast_autovacuum_freeze_table_age, |
| 73 | + c.reloptions AS reloptions, tst.reloptions AS toast_reloptions, am.amname, |
| 74 | + (CASE WHEN c.reltoastrelid = 0 THEN false ELSE true END) AS hastoasttable |
| 75 | +FROM |
| 76 | + pg_catalog.pg_class c |
| 77 | +LEFT OUTER JOIN pg_catalog.pg_namespace nsp on nsp.oid = c.relnamespace |
| 78 | +LEFT OUTER JOIN pg_catalog.pg_tablespace spc on spc.oid=c.reltablespace |
| 79 | +LEFT OUTER JOIN pg_catalog.pg_description des ON (des.objoid=c.oid and des.objsubid=0 AND des.classoid='pg_class'::regclass) |
| 80 | +LEFT OUTER JOIN pg_catalog.pg_class tst ON tst.oid = c.reltoastrelid |
| 81 | +LEFT OUTER JOIN pg_catalog.pg_am am ON am.oid = c.relam |
| 82 | + WHERE ((c.relhasrules AND (EXISTS ( |
| 83 | + SELECT |
| 84 | + r.rulename |
| 85 | + FROM |
| 86 | + pg_catalog.pg_rewrite r |
| 87 | + WHERE |
| 88 | + ((r.ev_class = c.oid) |
| 89 | + AND (pg_catalog.bpchar(r.ev_type) = '1'::bpchar)) ))) |
| 90 | + AND (c.relkind = 'm'::char) |
| 91 | + ) |
| 92 | +{% if (vid and datlastsysoid) %} |
| 93 | + AND c.oid = {{vid}}::oid |
| 94 | +{% elif scid %} |
| 95 | + AND c.relnamespace = {{scid}}::oid |
| 96 | +ORDER BY |
| 97 | + c.relname |
| 98 | +{% endif %} |
| 99 | + |
| 100 | +{% elif type == 'roles' %} |
| 101 | +SELECT |
| 102 | + pr.rolname |
| 103 | +FROM |
| 104 | + pg_catalog.pg_roles pr |
| 105 | +WHERE |
| 106 | + pr.rolcanlogin |
| 107 | +ORDER BY |
| 108 | + pr.rolname |
| 109 | + |
| 110 | +{% elif type == 'schemas' %} |
| 111 | +SELECT |
| 112 | + nsp.nspname |
| 113 | +FROM |
| 114 | + pg_catalog.pg_namespace nsp |
| 115 | +WHERE |
| 116 | + (nsp.nspname NOT LIKE E'pg\\_%' |
| 117 | + AND nsp.nspname != 'information_schema') |
| 118 | +{% endif %} |
0 commit comments