(1 row)
select * from test_encoding3('クライアント側のデータ');
-NOTICE: public.test_encoding3(1): REMOTE NOTICE: got: クライアント側のデータ
+NOTICE: public.test_encoding3(1): [test_enc_part] REMOTE NOTICE: got: クライアント側のデータ
id | コラム
----+------------------------
3 | クライアント側のデータ
(1 row)
select * from test_encoding3('クライアント側のデータ');
-NOTICE: public.test_encoding3(1): REMOTE NOTICE: got: クライアント側のデータ
+NOTICE: public.test_encoding3(1): [test_enc_part] REMOTE NOTICE: got: クライアント側のデータ
id | コラム
----+------------------------
3 | クライアント側のデータ
run on 0;
$$ language plproxy;
select * from test_error1();
-ERROR: public.test_error1(0): REMOTE ERROR: column "line2err" does not exist
+ERROR: public.test_error1(0): [test_part] REMOTE ERROR: column "line2err" does not exist
LINE 1: select line2err
^
QUERY: select line2err
$$ language plproxy;
select * from test_error2();
NOTICE: PL/Proxy: dropping stale conn
-ERROR: public.test_error2(0): REMOTE ERROR: column "err" does not exist
+ERROR: public.test_error2(0): [test_part] REMOTE ERROR: column "err" does not exist
LINE 1: select * from test_error2();
^
+create function test_error3() returns int4
+as $$
+ connect 'dbname=test_part';
+$$ language plproxy;
+select * from test_error3();
+ERROR: public.test_error3(0): [test_part] REMOTE ERROR: function public.test_error3() does not exist
+LINE 1: select * from test_error3();
+ ^
+HINT: Remote hint: No function matches the given name and argument types. You might need to add explicit type casts.
+-- test invalid db
+create function test_bad_db() returns int4
+as $$
+ cluster 'badcluster';
+$$ language plproxy;
+select * from test_bad_db();
+ERROR: PL/Proxy function public.test_bad_db(0): [nonex_db] PQconnectPoll: FATAL: database "nonex_db" does not exist
+
+create function test_bad_db2() returns int4
+as $$
+ connect 'dbname=wrong_name_db';
+$$ language plproxy;
+select * from test_bad_db2();
+ERROR: PL/Proxy function public.test_bad_db2(0): [wrong_name_db] PQconnectPoll: FATAL: database "wrong_name_db" does not exist
+
if cluster_name = 'testcluster' then
return 5;
end if;
+ if cluster_name = 'badcluster' then
+ return 5;
+ end if;
raise exception 'no such cluster: %', cluster_name;
end; $$ language plpgsql;
return next 'host=127.0.0.1 dbname=test_part';
return;
end if;
+ if cluster_name = 'badcluster' then
+ return next 'host=127.0.0.1 dbname=nonex_db';
+ return;
+ end if;
raise exception 'no such cluster: %', cluster_name;
end; $$ language plpgsql;
$$ language plproxy;
select * from test_error2();
+create function test_error3() returns int4
+as $$
+ connect 'dbname=test_part';
+$$ language plproxy;
+select * from test_error3();
+
+-- test invalid db
+create function test_bad_db() returns int4
+as $$
+ cluster 'badcluster';
+$$ language plproxy;
+select * from test_bad_db();
+
+create function test_bad_db2() returns int4
+as $$
+ connect 'dbname=wrong_name_db';
+$$ language plproxy;
+select * from test_bad_db2();
+
{
conn = &cluster->conn_list[cluster->conn_count++];
conn->connstr = MemoryContextStrdup(cluster_mem, final->data);
+ conn->cluster = cluster;
}
cluster->part_map[part_num] = conn;
cluster->part_map = palloc(sizeof(ProxyConnection *));
cluster->conn_list = palloc0(sizeof(ProxyConnection));
conn = &cluster->conn_list[0];
+ conn->cluster = cluster;
cluster->part_map[0] = conn;
conn->connstr = pstrdup(cluster->name);
static void
conn_error(ProxyFunction *func, ProxyConnection *conn, const char *desc)
{
- plproxy_error(func, "%s: %s",
- desc, PQerrorMessage(conn->db));
+ plproxy_error(func, "[%s] %s: %s",
+ PQdb(conn->db), desc, PQerrorMessage(conn->db));
}
/* Compare if major/minor match. Works on "MAJ.MIN.*" */
static void
handle_notice(void *arg, const PGresult *res)
{
- ProxyCluster *cluster = arg;
- plproxy_remote_error(cluster->cur_func, res, false);
+ ProxyConnection *conn = arg;
+ ProxyCluster *cluster = conn->cluster;
+ plproxy_remote_error(cluster->cur_func, conn, res, false);
}
/* check existing conn status or launch new conn */
conn_error(func, conn, "PQconnectStart");
/* override default notice handler */
- PQsetNoticeReceiver(conn->db, handle_notice, func->cur_cluster);
+ PQsetNoticeReceiver(conn->db, handle_notice, conn);
}
/*
PQclear(conn->res);
conn->res = res;
- plproxy_remote_error(func, res, true);
+ plproxy_remote_error(func, conn, res, true);
break;
default:
if (conn->res)
* Pass remote error/notice/warning through.
*/
void
-plproxy_remote_error(ProxyFunction *func, const PGresult *res, bool iserr)
+plproxy_remote_error(ProxyFunction *func, ProxyConnection *conn, const PGresult *res, bool iserr)
{
const char *ss = PQresultErrorField(res, PG_DIAG_SQLSTATE);
const char *sev = PQresultErrorField(res, PG_DIAG_SEVERITY);
ereport(elevel, (
errcode(MAKE_SQLSTATE(ss[0], ss[1], ss[2], ss[3], ss[4])),
- errmsg("%s(%d): REMOTE %s: %s", func->name, func->arg_count, sev, msg),
+ errmsg("%s(%d): [%s] REMOTE %s: %s", func->name, func->arg_count, PQdb(conn->db), sev, msg),
det ? errdetail("Remote detail: %s", det) : 0,
hint ? errhint("Remote hint: %s", hint) : 0,
spos ? errposition(atoi(spos)) : 0,
/* Single database connection */
typedef struct
{
+ struct ProxyCluster *cluster;
const char *connstr; /* Connection string for libpq */
/* state */
/* main.c */
Datum plproxy_call_handler(PG_FUNCTION_ARGS);
void plproxy_error(ProxyFunction *func, const char *fmt,...);
-void plproxy_remote_error(ProxyFunction *func, const PGresult *res, bool iserr);
+void plproxy_remote_error(ProxyFunction *func, ProxyConnection *conn, const PGresult *res, bool iserr);
/* function.c */
void plproxy_function_cache_init(void);