dependency tracking

From: "Little, Douglas" <DOUGLAS(dot)LITTLE(at)orbitz(dot)com>
To: "pgsql-admin(at)postgresql(dot)org" <pgsql-admin(at)postgresql(dot)org>
Subject: dependency tracking
Date: 2010-11-08 19:21:29
Message-ID: 8585BA53443004458E0BAA6134C5A7FB479B1A81@EGEXCMB01.oww.root.lcl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Hi,
I have a deployment routine to deal with PG's requirement of having no dependencies in order to alter a table.
The routine basically navigates the dependency tree and saves off the ddl to a table and drops the dependent (always a view) along the way.
Once the alter table is completed, the views are recreated and permissions regranted.

Unfortunately, I'm missing some of the dependencies.
I've spent hours trying to understand how to do this, but considering I still don't have it correct. I thought I should ask the experts.

The views are complex views based on other views. They do show up in the PGAdmin dependency list.

This is my sql
SELECT (nsc.nspname::text || '.'::text) || cl.relname::text AS refobj_name, (rwns.nspname::text || '.'::text) || rwcl.relname::text AS depobj_name
, pg_get_viewdef((rwns.nspname::text || '.'::text) || rwcl.relname::text, true) AS depobj_ddl
, array_to_string(rwcl.relacl, ','::text) AS depobj_acl

FROM pg_namespace nsc
JOIN pg_class cl ON cl.relnamespace = nsc.oid --
JOIN pg_depend dep ON dep.refobjid = cl.oid
LEFT JOIN pg_rewrite rw ON dep.objid = rw.oid
LEFT JOIN pg_class rwcl ON rwcl.oid = rw.ev_class
LEFT JOIN pg_namespace rwns ON rwcl.relnamespace = rwns.oid
WHERE rw.rulename = '_RETURN'::name
AND ((nsc.nspname::text || '.'::text) || cl.relname::text) <> ((rwns.nspname::text || '.'::text) || rwcl.relname::text)

GROUP BY (nsc.nspname::text || '.'::text) || cl.relname::text, (rwns.nspname::text || '.'::text)
|| rwcl.relname::text, pg_get_viewdef((rwns.nspname::text || '.'::text)
|| rwcl.relname::text, true), array_to_string(rwcl.relacl, ','::text);

Thoughts?
I query with the name of the base table I'm trying to change.

Doug Little

Sr. Data Warehouse Architect | Enterprise Data Management | Orbitz Worldwide
500 W. Madison, Suite 1000 Chicago IL 60661| Office 312.260.2588 | Fax 312.894.5164 | Cell 847-997-5741
Douglas(dot)Little(at)orbitz(dot)com<mailto:Douglas(dot)Little(at)orbitz(dot)com>
[cid:image001(dot)jpg(at)01CB7F1F(dot)46C80B20] orbitz.com<http://www.orbitz.com/> | ebookers.com<http://www.ebookers.com/> | hotelclub.com<http://www.hotelclub.com/> | cheaptickets.com<http://www.cheaptickets.com/> | ratestogo.com<http://www.ratestogo.com/> | asiahotels.com<http://www.asiahotels.com/>

Browse pgsql-admin by date

  From Date Subject
Next Message Alvaro Herrera 2010-11-08 22:09:31 Re: autovacuum launcher process eating up 17G+ of ram?
Previous Message Tom Lane 2010-11-08 15:15:02 Re: autovacuum launcher process eating up 17G+ of ram?