In PostgreSQL, you can raise a notice over a dblink using a combination of dblink and plpgsql (a procedural language extension). Here's an example of how you can do it:

Let's assume you have two databases: "local_db" and "remote_db," and you want to raise a notice in "local_db" from a function running on "remote_db."

  1. First, make sure you have the dblink extension installed in your "remote_db." If not, you can install it by connecting to "remote_db" and running:
sql
CREATE EXTENSION IF NOT EXISTS dblink;
  1. On the "local_db," create a function that raises a notice:
sql
-- Function to raise a notice in the local_db CREATE OR REPLACE FUNCTION raise_notice_on_local() RETURNS void AS $$ BEGIN RAISE NOTICE 'This is a notice raised from remote_db'; END; $$ LANGUAGE plpgsql;
  1. On the "remote_db," use dblink to execute the function on "local_db" and raise the notice:
sql
-- Assuming you have already set up the dblink connection SELECT dblink_connect('local_connection', 'host=local_host dbname=local_db user=local_user password=local_password'); -- Call the function on local_db and raise the notice SELECT dblink_exec('local_connection', 'SELECT raise_notice_on_local()'); -- Close the dblink connection (optional) SELECT dblink_disconnect('local_connection');

When you run the above code on "remote_db," it will connect to "local_db," execute the raise_notice_on_local() function, and raise the notice, which you can see in the "local_db" logs.

Please note that this example assumes that you have already set up dblink connections between the two databases, and the function raise_notice_on_local() exists in "local_db." If you encounter any issues, ensure that dblink is properly installed and the connections are set up correctly. Also, make sure that the user connecting through dblink has the necessary permissions to execute the function on the "local_db."

Have questions or queries?
Get in Touch