From: Tom Lane <tgl@sss.pgh.pa.us>
To: Wells Oliver <wells.oliver@gmail.com>
Cc: pgsql-admin <pgsql-admin@postgresql.org>
Subject: Re: Querying dependencies
Date: Mon, 22 May 2023 14:11:53 -0400
Message-ID: <710259.1684779113@sss.pgh.pa.us> (raw)
In-Reply-To: <CAOC+FBWnJNPkrLNHR8TcC1QmqGBMf7vW1Dd4PwqihSb6K0S4xw@mail.gmail.com>
References: <CAOC+FBWnJNPkrLNHR8TcC1QmqGBMf7vW1Dd4PwqihSb6K0S4xw@mail.gmail.com>
Wells Oliver <wells.oliver@gmail.com> writes:
> Sometimes I'll "drop table .." on a replica just to see the list of
> dependencies,.. This is quite dumb. What's the simple query I can run to
> get the same detail without the idiocy?
Not sure about "simple", but here's an example of looking at the
catalog data for this:
regression=# create table mytable(a int primary key, b text unique);
CREATE TABLE
regression=# create table othertable (a int references mytable);
CREATE TABLE
regression=# select pg_describe_object(classid,objid,objsubid), deptype from pg_depend where refclassid = 'pg_class'::regclass and refobjid = 'mytable'::regclass;
pg_describe_object | deptype
--------------------------------------------------+---------
type mytable | i
toast table pg_toast.pg_toast_40635 | i
constraint mytable_pkey on table mytable | a
constraint othertable_a_fkey on table othertable | n
constraint mytable_b_key on table mytable | a
(5 rows)
See https://www.postgresql.org/docs/current/catalog-pg-depend.html
In the general case you'd need to worry about indirect
dependencies, so you'd need to embed this in a recursive
CTE. But tables don't usually have indirect dependencies.
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-admin@postgresql.org
Cc: tgl@sss.pgh.pa.us, wells.oliver@gmail.com
Subject: Re: Querying dependencies
In-Reply-To: <710259.1684779113@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox