I'm trying to detect a bad postgres PL/proxy shard connection through an exception in a plpgsql function. This works exactly as expected when the function is called directly (trying to access a bad shard throws an exception). However, the existing codebase calls the function indirectly through a plproxy function in the RUN ON statement, and in this case an exception gets thrown accessing any shard, good or bad. Has anyone else seen this and/or have a solution or workaround?
Here's a trimmed example of the problem:
A) FunctionA is a plproxy function, which has the line: RUN ON functionB($1, NULL);
B) functionB is a plpgsql function, which has the line: SELECT db_index FROM functionC();
C) functionC is also a plpgsql function, which has the code checking the connection: FOR db_id IN () LOOP BEGIN PERFORM check_shard(db_id); --This just calls a function that runs on the shard EXCEPTION WHEN internal_error THEN RAISE NOTICE 'CAUGHT EXCEPTION FOR ID %', db_id; END; END LOOP;
When functionB or functionC is called directly from in a SELECT, the good shards do NOT throw an exception. But when plproxy functionA is called with the function call in the RUN ON statement, all shards throw the exception. So it seems there's something going on with the plproxy function or the RUN ON statement that's causing this issue.
Any help would be greatly appreciated!