Skip to content

Commit

Permalink
set idle_in_transaction_session_timeout to 0
Browse files Browse the repository at this point in the history
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
```
  • Loading branch information
NikolayS committed Dec 28, 2018
1 parent 923fa2f commit 62a0277
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
14 changes: 13 additions & 1 deletion bin/pg_repack.c
Original file line number Diff line number Diff line change
Expand Up @@ -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" */
Expand All @@ -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
{
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion regress/expected/nosuper.out
Original file line number Diff line number Diff line change
Expand Up @@ -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;
2 changes: 2 additions & 0 deletions regress/expected/nosuper_1.out
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit 62a0277

Please sign in to comment.