pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Charles Clavadetscher <clavadetscher@swisspug.org>
To: Durgamahesh Manne <maheshpostgres9@gmail.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: About to know the info of foreign table reference used in any of call ,views,functions
Date: Tue, 27 Apr 2021 09:31:25 +0200
Message-ID: <382c97616fb6583d408204cc01639a05@swisspug.org> (raw)
In-Reply-To: <CAJCZkoJqp7uhGggcpHx-dEc0pY_KumeyQwkLNGOnsBib+8cTaw@mail.gmail.com>
References: <CAJCZkoJqp7uhGggcpHx-dEc0pY_KumeyQwkLNGOnsBib+8cTaw@mail.gmail.com>

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      |
+------------------------+





view thread (2+ messages)

Message-ID: <382c97616fb6583d408204cc01639a05@swisspug.org>
Permalink:  ../382c97616fb6583d408204cc01639a05@swisspug.org/
Also on:    postgresql.org/message-id/382c97616fb6583d408204cc01639a05@swisspug.org

 · 

reply

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: clavadetscher@swisspug.org, maheshpostgres9@gmail.com
  Subject: Re: About to know the info of foreign table reference used in any of call ,views,functions
  In-Reply-To: <382c97616fb6583d408204cc01639a05@swisspug.org>
  References: <CAJCZkoJqp7uhGggcpHx-dEc0pY_KumeyQwkLNGOnsBib+8cTaw@mail.gmail.com> <382c97616fb6583d408204cc01639a05@swisspug.org>

* 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