Initial connect is canceled, if it takes more that this.
Duplicated connstring setting (should be just added to connstr?)
- statement_timeout::
-
- If set, then SET statement_timeout = X command is sent to remote
- database.
-
query_timeout::
If query result does not appear in this time, the connection
test_part
(1 row)
--- test timeout
-create or replace function
-plproxy.get_cluster_config(cluster_name text, out key text, out val text)
-returns setof record as $$
-begin
- key := 'statement_timeout';
- val := 10; -- ms
- return next;
- return;
-end; $$ language plpgsql;
-create or replace function plproxy.get_cluster_version(cluster_name text)
-returns integer as $$
-begin
- if cluster_name = 'testcluster' then
- return 6;
- end if;
- raise exception 'no such cluster: %', cluster_name;
-end; $$ language plpgsql;
-create function test_timeout()
-returns text as $$
- cluster 'testcluster';
- run on 0;
- select 'asd' from pg_sleep(3);
-$$ language plproxy;
-select * from test_timeout();
-ERROR: PL/Proxy function public.test_timeout(0): remote error: ERROR: canceling statement due to statement timeout
-
-create or replace function
-plproxy.get_cluster_config(cluster_name text, out key text, out val text)
-returns setof record as $$
-begin
- key := 'statement_timeout';
- val := 0;
- return next;
- return;
-end; $$ language plpgsql;
-create or replace function plproxy.get_cluster_version(cluster_name text)
-returns integer as $$
-begin
- if cluster_name = 'testcluster' then
- return 7;
- end if;
- raise exception 'no such cluster: %', cluster_name;
-end; $$ language plpgsql;
-- test quoting function
create type "RetWeird" as (
"ColId" int4,
as $$ connect 'dbname=test_part'; select current_database(); $$ language plproxy;
select * from test_connect1();
--- test timeout
-create or replace function
-plproxy.get_cluster_config(cluster_name text, out key text, out val text)
-returns setof record as $$
-begin
- key := 'statement_timeout';
- val := 10; -- ms
- return next;
- return;
-end; $$ language plpgsql;
-
-create or replace function plproxy.get_cluster_version(cluster_name text)
-returns integer as $$
-begin
- if cluster_name = 'testcluster' then
- return 6;
- end if;
- raise exception 'no such cluster: %', cluster_name;
-end; $$ language plpgsql;
-
-create function test_timeout()
-returns text as $$
- cluster 'testcluster';
- run on 0;
- select 'asd' from pg_sleep(3);
-$$ language plproxy;
-select * from test_timeout();
-
-create or replace function
-plproxy.get_cluster_config(cluster_name text, out key text, out val text)
-returns setof record as $$
-begin
- key := 'statement_timeout';
- val := 0;
- return next;
- return;
-end; $$ language plpgsql;
-
-create or replace function plproxy.get_cluster_version(cluster_name text)
-returns integer as $$
-begin
- if cluster_name = 'testcluster' then
- return 7;
- end if;
- raise exception 'no such cluster: %', cluster_name;
-end; $$ language plpgsql;
-
-- test quoting function
create type "RetWeird" as (
plproxy_error(func, "val must not be NULL");
if (strcasecmp(key, "statement_timeout") == 0)
- cf->statement_timeout = atoi(val);
+ /* ignore */ ;
else if (strcasecmp("connection_lifetime", key) == 0)
cf->connection_lifetime = atoi(val);
else if (strcasecmp("query_timeout", key) == 0)
cluster = palloc0(sizeof(*cluster));
cluster->name = pstrdup(name);
- cluster->config.statement_timeout = -1;
-
MemoryContextSwitchTo(old_ctx);
return cluster;
conn->connstr = pstrdup(cluster->name);
conn->state = C_NONE;
- cluster->config.statement_timeout = -1;
-
MemoryContextSwitchTo(old_ctx);
cluster->next = fake_cluster_list;
static int
tune_connection(ProxyFunction *func, ProxyConnection *conn)
{
- ProxyConfig *cf = &func->cur_cluster->config;
const char *this_enc, *dst_enc;
const char *dst_ver;
StringInfo sql = NULL;
conn_error(func, conn, sql->data);
}
- /* add statement_timeout to query */
- if (cf->statement_timeout >= 0 && !conn->tuning)
- {
- if (!sql)
- sql = makeStringInfo();
- appendStringInfo(sql, "set statement_timeout = %d; ",
- cf->statement_timeout);
- }
-
/*
* send tuning query
*/
int connect_timeout; /* How long connect may take (secs) */
int query_timeout; /* How long query may take (secs) */
int connection_lifetime; /* How long the connection may live (secs) */
- int statement_timeout; /* Do remotely: SET statement_timeout */
int disable_binary; /* Avoid binary I/O */
} ProxyConfig;