6

Besides manually searching for all the dblink() used in triggers/functions/stored procedures is there a way to query for this information?

Example: There is a dblink inside of a trigger, can I select something from the postgres schema that would identify this?

I'm thinking this is a manual effort but asking just to make sure I'm not missing something.

NOTE: I have some logging where I am also looking for dblink()

Phill Pafford
  • 1,415
  • 6
  • 19
  • 26

3 Answers3

4

I would draw a text backup and search it with vim or any tool of your choice.

As far as PL/pgSQL functions are concerned (there is one behind every trigger), you can query the system catalog pg_proc:

SELECT *
FROM   pg_catalog.pg_proc
WHERE  prosrc ILIKE '%dblink%';
Erwin Brandstetter
  • 185,527
  • 28
  • 463
  • 633
3
select * from information_schema._pg_foreign_servers;

OR

select * from pg_foreign_server;
Colin 't Hart
  • 9,455
  • 15
  • 36
  • 44
user115223
  • 85
  • 1
  • 5
1

You can get all open dblink connections using dblink_get_connections().

Those that are not used can only be found by examining your function code like Erwin suggests. I thought that with SQL functions one can query for the dblink functions it depends on, but it happens not to be the case (actually, you can even drop the extension while having functions using dblink_connect(), for example.)

András Váczi
  • 31,778
  • 13
  • 102
  • 151