https://github.com/chobostar/demo-single-roundtrip-statement-timeout
This is a demo with how hack PostgreSQL `statement_timeout` with single round trip
https://github.com/chobostar/demo-single-roundtrip-statement-timeout
Last synced: about 2 months ago
JSON representation
This is a demo with how hack PostgreSQL `statement_timeout` with single round trip
- Host: GitHub
- URL: https://github.com/chobostar/demo-single-roundtrip-statement-timeout
- Owner: chobostar
- Created: 2019-07-26T14:31:53.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-07-26T14:36:06.000Z (almost 6 years ago)
- Last Synced: 2025-03-04T19:42:16.342Z (about 2 months ago)
- Language: Python
- Size: 3.91 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# demo-single-1rt-statement-timeout
This is a demo with how hack PostgreSQL `statement_timeout` with single round trip# Описание
Внутри simple query нельзя устанавливать `statement_timeout`:
```
$ psql -U postgres -c "set local statement_timeout = '100ms'; select pg_sleep(2);"
pg_sleep
----------
(1 row)
```Это потому, что любой simple query оборачивается в xact_command:
https://github.com/postgres/postgres/blob/REL9_6_STABLE/src/backend/tcop/postgres.c#L923Если `xact_started == true`, таймер StatementTimeout не взводиться
https://github.com/postgres/postgres/blob/REL9_6_STABLE/src/backend/tcop/postgres.c#L2443`xact_started = false` устанавливается в 2-х случаях:
- это transcation control statement - BEGIN, ROLLBACK, COMMIT
- это конец query
https://github.com/postgres/postgres/blob/REL9_6_STABLE/src/backend/tcop/postgres.c#L1120-L1141хак чтобы statement_timeout работал внутри simple query:
```
$ psql -U postgres -c "set local statement_timeout = '100ms'; BEGIN; select pg_sleep(2);"
ERROR: canceling statement due to statement timeout
```