Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1flbR8-0006re-BU for pgsql-general@arkaria.postgresql.org; Fri, 03 Aug 2018 14:52:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1flbR5-0005JA-BS for pgsql-general@arkaria.postgresql.org; Fri, 03 Aug 2018 14:52:11 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1flbR5-0005I3-3M for pgsql-general@lists.postgresql.org; Fri, 03 Aug 2018 14:52:11 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1flbR2-0007HG-1L for pgsql-general@postgresql.org; Fri, 03 Aug 2018 14:52:10 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id w73Eq4ms014402; Fri, 3 Aug 2018 10:52:04 -0400 From: Tom Lane To: Tiffany Thang cc: Forums postgresql Subject: Re: List of objects owned by a schema/owner In-reply-to: References: Comments: In-reply-to Tiffany Thang message dated "Fri, 03 Aug 2018 08:33:48 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <14400.1533307924.1@sss.pgh.pa.us> Date: Fri, 03 Aug 2018 10:52:04 -0400 Message-ID: <14401.1533307924@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Tiffany Thang writes: > Does anyone have a query that will list all the objects (composite types, > sequences, tables, triggers, functions, indices, etc) owned by a schema or > owner? I find fragments of information here and there that query on > pg_tables, pg_views, etc. Well, you could attack it the hard way: select relname from pg_class where relowner = [oid of role of interest] union all ... similar select from every other catalog that has an owner column ... I don't know if anyone's built such a query before, but a little quality time with the system catalog documentation would get you there: https://www.postgresql.org/docs/current/static/catalogs.html Another idea is to rely on owner dependencies recorded in pg_shdepend, along the lines of select pg_describe_object(classid,objid,objsubid) from pg_shdepend where deptype = 'o' and refobjid = [oid of role of interest] and dbid = [oid of current database]; That won't work for objects owned by the bootstrap superuser, and I think there are some other omissions --- for instance, it looks like we only record an owner dependency for a table, not for its indexes. Or, if you're feeling truly lazy, you can do begin; drop user joe; -- read the error message whining about what joe owns rollback; That's largely a hacky way to get the same info as the pg_shdepend query I sketched before, since the error message is derived from exactly that info. You have the same three options for schemas, though the details of each are a bit different (in particular, schema dependencies would be found in pg_depend not pg_shdepend). regards, tom lane