Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1q1A0m-0006Rw-Qc for pgsql-admin@arkaria.postgresql.org; Mon, 22 May 2023 18:12:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1q1A0l-0000dl-Ip for pgsql-admin@arkaria.postgresql.org; Mon, 22 May 2023 18:11:59 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1q1A0l-0000dc-8B for pgsql-admin@lists.postgresql.org; Mon, 22 May 2023 18:11:59 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1q1A0h-001RxE-Cx for pgsql-admin@postgresql.org; Mon, 22 May 2023 18:11:58 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 34MIBrvj710260; Mon, 22 May 2023 14:11:53 -0400 From: Tom Lane To: Wells Oliver cc: pgsql-admin Subject: Re: Querying dependencies In-reply-to: References: Comments: In-reply-to Wells Oliver message dated "Mon, 22 May 2023 11:01:12 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <710258.1684779113.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Mon, 22 May 2023 14:11:53 -0400 Message-ID: <710259.1684779113@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Wells Oliver 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=3D# create table mytable(a int primary key, b text unique); CREATE TABLE regression=3D# create table othertable (a int references mytable); CREATE TABLE regression=3D# select pg_describe_object(classid,objid,objsubid), deptype = from pg_depend where refclassid =3D 'pg_class'::regclass and refobjid =3D = '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