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 1lbIC5-0001lJ-BZ for pgsql-general@arkaria.postgresql.org; Tue, 27 Apr 2021 07:31:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lbIC4-0001u6-4w for pgsql-general@arkaria.postgresql.org; Tue, 27 Apr 2021 07:31:40 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lbIC3-0001tz-TR for pgsql-general@lists.postgresql.org; Tue, 27 Apr 2021 07:31:39 +0000 Received: from gandalf.net-wizard.org ([2a01:4f8:172:2a5c::5]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lbIC1-0001Em-2M for pgsql-general@lists.postgresql.org; Tue, 27 Apr 2021 07:31:38 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.net-wizard.org (Postfix) with ESMTP id 4954282E50; Tue, 27 Apr 2021 09:31:33 +0200 (CEST) X-Virus-Scanned: Gentoo amavisd-new at aragorn Received: from aragorn.net-wizard.org ([127.0.0.1]) by localhost (aragorn.net-wizard.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ueOn74KJpo5p; Tue, 27 Apr 2021 09:31:25 +0200 (CEST) Received: from webmail.net-wizard.org (localhost [IPv6:::1]) by gandalf.net-wizard.org (Postfix) with ESMTP id 2087C82E4E; Tue, 27 Apr 2021 09:31:25 +0200 (CEST) MIME-Version: 1.0 Date: Tue, 27 Apr 2021 09:31:25 +0200 From: Charles Clavadetscher To: Durgamahesh Manne Cc: pgsql-general@lists.postgresql.org Subject: Re: About to know the info of foreign table reference used in any of call ,views,functions In-Reply-To: References: User-Agent: Roundcube Webmail/1.4.11 Message-ID: <382c97616fb6583d408204cc01639a05@swisspug.org> X-Sender: clavadetscher@swisspug.org Organization: Swiss PostgreSQL Users Group Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi On 2021-04-27 09:15, Durgamahesh Manne wrote: > Hi Team > > By using the system view and function > > "I need to get the info of foreign table reference used in any of call > ,views,functions" > > I found info of views and functions and sprocs that are executed > frequently through application using pg_stat_user_functions view > > Please help for the info i need > > Thanks & Regards > Durgamahesh Manne I am not sure how reliable that is, but as you mention you could query the system catalogs. The definition of views and the code of functions are stored in pg_views and pg_proc. So you can check if those contain the name of the tables you are interested in. You can find a list of the foreign tables using: SELECT relnamespace::regnamespace AS schema_name, relname AS table_name FROM pg_class WHERE relkind = 'f'; You can then use this information to query views defintions and function bodies: SELECT schemaname, viewname FROM pg_views WHERE definition ~ '(schema_name\.)?table_name'; SELECT pronamespace::regnamespace, proname FROM pg_proc WHERE prosrc ~ '(schema_name\.)?table_name'; schema_name and table_name refer to the result of the first query. If you have overloaded functions you may need to extract more information to identify them correctly, such as the list of parameters. The documentation is very helpful in this context. Hope this helps. Regards Charles -- Charles Clavadetscher Spitzackerstrasse 9 CH - 8057 Zürich https://www.swisspug.org +------------------------+ | ____ ______ ___ | | / )/ \/ \ | | ( / __ _\ ) | | \ (/ o) ( o) ) | | \_ (_ ) \ ) _/ | | \ /\_/ \)/ | | \/ | | _| | | | \|_/ | | | | Swiss PostgreSQL | | Users Group | +------------------------+