Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overriding idle_in_transaction_session_timeout doesn't seem to work properly #366

Open
franciscoreinolds opened this issue Oct 16, 2023 · 5 comments

Comments

@franciscoreinolds
Copy link

franciscoreinolds commented Oct 16, 2023

Possibly related to #222

Today, I was trying to repack a table and I got the following warning: ERROR: query failed: FATAL: terminating connection due to idle-in-transaction timeout.

As I had an idle_in_transaction_session_timeout of "just" 2h, I thought I'd retry (since it could very well have been 2h since it had begun), this time setting it to 0, and the same behaviour was observed:

Details

$ sudo -u postgres PGOPTIONS="-c idle_in_transaction_session_timeout=0" PGOPTIONS="-c statement_timeout=0" pg_repack --no-kill-backend --wait-timeout=180 --table=<table> <database>
INFO: repacking table "public.<table>"
ERROR: query failed: FATAL:  terminating connection due to idle-in-transaction timeout
server closed the connection unexpectedly
        This probably means the server terminated abnormally
        before or while processing the request.
DETAIL: query was: SAVEPOINT repack_sp1

To check that it does indeed work, I tried running it again, but setting it to 5s so that it's obvious if PGOPTIONS is actually overriding the timeouts or not, and it worked as expected:

Details

$ time sudo -u postgres PGOPTIONS="-c idle_in_transaction_session_timeout=5s" PGOPTIONS="-c statement_timeout=5s" pg_repack --no-kill-backend --wait-timeout=180 --table=<table> <database>
INFO: repacking table "public.<table>"
ERROR: query failed: ERROR:  canceling statement due to statement timeout
DETAIL: query was: INSERT INTO repack.table_16480 SELECT <...> FROM ONLY public.<table>

real    0m5.169s
user    0m0.024s
sys     0m0.008s

So this seems to indicate that there's some kind of problem with the timeouts.

Looking forward to hear your perspective on this,

Francisco

@za-arthur
Copy link
Collaborator

pg_repack doesn't override idle_in_transaction_session_timeout. Maybe you have enabled idle_in_transaction_session_timeout globally for a user or a database?

@franciscoreinolds
Copy link
Author

pg_repack doesn't override idle_in_transaction_session_timeout.

Wasn't aware of that, thanks for clearing that up.

Maybe you have enabled idle_in_transaction_session_timeout globally for a user or a database?

I do, yes, but I'd like to avoid having to disable such timeouts during an operation like this.

Would now perhaps be a good occasion to rekindle the discussion regarding the overriding of this timeout in pg_repack itself, such as been suggested here? It appears that someone at a given point also opened a PR for this (#198).

Personally, I think this would be a great addition, but perhaps I'm missing some insight as to why not.

@za-arthur
Copy link
Collaborator

I'd say that pg_repack shouldn't disable idle_in_transaction_session_timeout by default. Although it is possible to add a new option which is 0 by default and we will think about it.

But on the other hand the issue is an environment related issue, because idle_in_transaction_session_timeout is disabled by default. If you set it on your database instance you have couple of options:

  • during running pg_repack disable it using PGOPTIONS environment variable
  • run pg_repack using a dedicated user for which you can disable idle_in_transaction_session_timeout by ALTER USER/ROLE

@franciscoreinolds
Copy link
Author

I'd say that pg_repack shouldn't disable idle_in_transaction_session_timeout by default. Although it is possible to add a new option which is 0 by default and we will think about it.

I'd say that's also a suitable solution, thanks for being open to it.

But on the other hand the issue is an environment related issue, because idle_in_transaction_session_timeout is disabled by default. If you set it on your database instance you have couple of options:

* during running pg_repack disable it using `PGOPTIONS` environment variable

But I think I did this correctly, didn't I? If you check the Details popups above, it did successfully override statement_timeout, so I don't see why the same wouldn't be true for the idle_in_transaction.

@ailecksandr
Copy link

Potentially could be the case that it did not react on your ENV because you wrote it twice. So the latest one re-wrote the first (exactly with idle_in_transaction_session_timeout)

PGOPTIONS="-c idle_in_transaction_session_timeout=0 -c statement_timeout=0" sudo -u postgres pg_repack --no-kill-backend --wait-timeout=180 --table=<table> <database>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants