From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Tim Uckun <timuckun(at)gmail(dot)com> |
Cc: | David Johnston <polobo(at)yahoo(dot)com>, pgsql-general <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: invisible dependencies on a table? |
Date: | 2013-12-14 17:00:54 |
Message-ID: | 12812.1387040454@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Tim Uckun <timuckun(at)gmail(dot)com> writes:
> BTW is there a way to get a list of dependencies for a object? I was some
> scripts when I was googling but none of them seem to work with later
> versions of postgres.
Don't know why that would be; the pg_depend data structure hasn't really
changed since it was invented (in 7.3, if memory serves). If anything,
it's gotten easier to work with, as a result of invention of helper
functions such as pg_describe_object().
regression=# create table foo (f1 serial);
CREATE TABLE
regression=# -- things foo depends on:
regression=# select pg_describe_object(refclassid,refobjid,refobjsubid), deptype from pg_depend where classid='pg_class'::regclass and objid = 'foo'::regclass;
pg_describe_object | deptype
--------------------+---------
schema public | n
(1 row)
regression=# -- things that depend on foo:
regression=# select pg_describe_object(classid,objid,objsubid), deptype from pg_depend where refclassid='pg_class'::regclass and refobjid = 'foo'::regclass;
pg_describe_object | deptype
---------------------------------+---------
type foo | i
sequence foo_f1_seq | a
default for table foo column f1 | a
(3 rows)
It's that automatic dependency of the sequence on the table (or, if you
drill down a little further by looking at refobjsubid, you'll find out
it's really depending specifically on the f1 column) that represents
the owned-by relationship.
This is a nice way to look at the contents of pg_depend:
regression=# select pg_describe_object(classid,objid,objsubid) as obj, pg_describe_object(refclassid,refobjid,refobjsubid) as refobj, deptype from pg_depend order by objid desc limit 10;
obj | refobj | deptype
---------------------------------+---------------------+---------
default for table foo column f1 | sequence foo_f1_seq | n
default for table foo column f1 | table foo column f1 | a
type foo | table foo | i
type foo[] | type foo | i
table foo | schema public | n
type foo_f1_seq | sequence foo_f1_seq | i
sequence foo_f1_seq | schema public | n
sequence foo_f1_seq | table foo column f1 | a
function wait_for_stats() | language plpgsql | n
function wait_for_stats() | schema public | n
(10 rows)
See
http://www.postgresql.org/docs/9.3/static/catalog-pg-depend.html
for some documentation about what the deptype means.
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Adrian Klaver | 2013-12-14 18:36:57 | Re: invisible dependencies on a table? |
Previous Message | Tim Uckun | 2013-12-14 09:27:27 | Re: invisible dependencies on a table? |