From 62a0277b5d6eefeaae38c3eadcd57a0d8b008c1b Mon Sep 17 00:00:00 2001 From: Nikolay Date: Thu, 27 Dec 2018 17:43:21 -0500 Subject: [PATCH 1/3] set idle_in_transaction_session_timeout to 0 statement_timeout is being set to 0 in session preventing failures when this parameter is non-zero. This change is to prevent failures due to idle-in-transaction timeout, which look like this: ``` FATAL: terminating connection due to idle-in-transaction timeout ERROR: query failed: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. DETAIL: query was: SAVEPOINT repack_sp1 ``` --- bin/pg_repack.c | 14 +++++++++++++- regress/expected/nosuper.out | 2 +- regress/expected/nosuper_1.out | 2 ++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/bin/pg_repack.c b/bin/pg_repack.c index 9002fafb..766e210e 100644 --- a/bin/pg_repack.c +++ b/bin/pg_repack.c @@ -487,11 +487,12 @@ preliminary_checks(char *errbuf, size_t errsize){ } /* Query the extension version. Exit if no match */ - res = execute_elevel("select repack.version(), repack.version_sql()", + res = execute_elevel("select repack.version(), repack.version_sql(), current_setting('server_version_num')::int >= 90600", 0, NULL, DEBUG2); if (PQresultStatus(res) == PGRES_TUPLES_OK) { const char *libver; + const char *has_iitst; char buf[64]; /* the string is something like "pg_repack 1.1.7" */ @@ -518,6 +519,13 @@ preliminary_checks(char *errbuf, size_t errsize){ buf, libver); goto cleanup; } + + /* If Postgres version is 9.6 or newer, disable idle-in-transaction timeout */ + has_iitst = getstr(res, 0, 2); + if (0 == strcmp("t", has_iitst)) + { + command("SET idle_in_transaction_session_timeout = 0", 0, NULL); + } } else { @@ -1703,6 +1711,10 @@ lock_access_share(PGconn *conn, Oid relid, const char *target_name) termStringInfo(&sql); pgut_command(conn, "RESET statement_timeout", 0, NULL); + if (PQserverVersion(conn) >= 90600) + { + pgut_command(conn, "RESET idle_in_transaction_session_timeout", 0, NULL); + } return ret; } diff --git a/regress/expected/nosuper.out b/regress/expected/nosuper.out index 1d2fad2d..ace7ecb8 100644 --- a/regress/expected/nosuper.out +++ b/regress/expected/nosuper.out @@ -14,6 +14,6 @@ ERROR: pg_repack failed with error: You must be a superuser to use pg_repack -- => ERROR \! pg_repack --dbname=contrib_regression --table=tbl_cluster --username=nosuper --no-superuser-check ERROR: pg_repack failed with error: ERROR: permission denied for schema repack -LINE 1: select repack.version(), repack.version_sql() +LINE 1: select repack.version(), repack.version_sql(), current_setti... ^ DROP ROLE IF EXISTS nosuper; diff --git a/regress/expected/nosuper_1.out b/regress/expected/nosuper_1.out index 973ab293..55a6d556 100644 --- a/regress/expected/nosuper_1.out +++ b/regress/expected/nosuper_1.out @@ -14,4 +14,6 @@ ERROR: pg_repack failed with error: You must be a superuser to use pg_repack -- => ERROR \! pg_repack --dbname=contrib_regression --table=tbl_cluster --username=nosuper --no-superuser-check ERROR: pg_repack failed with error: ERROR: permission denied for schema repack +LINE 1: select repack.version(), repack.version_sql(), current_setting('server_version_num')::int >= 90600 + ^ DROP ROLE IF EXISTS nosuper; From 60d1332b03bb7518763df74f35651f893584ed1d Mon Sep 17 00:00:00 2001 From: Nikolay Date: Thu, 27 Dec 2018 19:42:41 -0500 Subject: [PATCH 2/3] adjust tests --- regress/expected/nosuper.out | 2 -- 1 file changed, 2 deletions(-) diff --git a/regress/expected/nosuper.out b/regress/expected/nosuper.out index ace7ecb8..973ab293 100644 --- a/regress/expected/nosuper.out +++ b/regress/expected/nosuper.out @@ -14,6 +14,4 @@ ERROR: pg_repack failed with error: You must be a superuser to use pg_repack -- => ERROR \! pg_repack --dbname=contrib_regression --table=tbl_cluster --username=nosuper --no-superuser-check ERROR: pg_repack failed with error: ERROR: permission denied for schema repack -LINE 1: select repack.version(), repack.version_sql(), current_setti... - ^ DROP ROLE IF EXISTS nosuper; From 51016c31b8791ba536f704939b94de93080de3fb Mon Sep 17 00:00:00 2001 From: Nikolay Samokhvalov Date: Thu, 10 Jan 2019 02:02:32 -0800 Subject: [PATCH 3/3] grant usage on schema repack to nosuper --- regress/expected/nosuper.out | 1 + regress/expected/nosuper_1.out | 1 + regress/sql/nosuper.sql | 1 + 3 files changed, 3 insertions(+) diff --git a/regress/expected/nosuper.out b/regress/expected/nosuper.out index 973ab293..cc15f3b9 100644 --- a/regress/expected/nosuper.out +++ b/regress/expected/nosuper.out @@ -5,6 +5,7 @@ SET client_min_messages = error; DROP ROLE IF EXISTS nosuper; SET client_min_messages = warning; CREATE ROLE nosuper WITH LOGIN; +GRANT USAGE ON SCHEMA repack TO nosuper; -- => OK \! pg_repack --dbname=contrib_regression --table=tbl_cluster --no-superuser-check INFO: repacking table "public.tbl_cluster" diff --git a/regress/expected/nosuper_1.out b/regress/expected/nosuper_1.out index 55a6d556..c2f8dc6d 100644 --- a/regress/expected/nosuper_1.out +++ b/regress/expected/nosuper_1.out @@ -5,6 +5,7 @@ SET client_min_messages = error; DROP ROLE IF EXISTS nosuper; SET client_min_messages = warning; CREATE ROLE nosuper WITH LOGIN; +GRANT USAGE ON SCHEMA repack TO nosuper; -- => OK \! pg_repack --dbname=contrib_regression --table=tbl_cluster --no-superuser-check INFO: repacking table "public.tbl_cluster" diff --git a/regress/sql/nosuper.sql b/regress/sql/nosuper.sql index 198f3458..216be59b 100644 --- a/regress/sql/nosuper.sql +++ b/regress/sql/nosuper.sql @@ -5,6 +5,7 @@ SET client_min_messages = error; DROP ROLE IF EXISTS nosuper; SET client_min_messages = warning; CREATE ROLE nosuper WITH LOGIN; +GRANT USAGE ON SCHEMA repack TO nosuper; -- => OK \! pg_repack --dbname=contrib_regression --table=tbl_cluster --no-superuser-check -- => ERROR