forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit82ebc70
committed
Be more wary about 32-bit integer overflow in pg_stat_statements.
We've heard a couple of reports of people having trouble withmulti-gigabyte-sized query-texts files. It occurred to me that on32-bit platforms, there could be an issue with integer overflowof calculations associated with the total query text size.Address that with several changes:1. Limit pg_stat_statements.max to INT_MAX / 2 not INT_MAX.The hashtable code will bound it to that anyway unless "long"is 64 bits. We still need overflow guards on its use, butthis helps.2. Add a check to prevent extending the query-texts file tomore than MaxAllocHugeSize. If it got that big, qtext_load_filewould certainly fail, so there's not much point in allowing it.Without this, we'd need to consider whether extent, query_offset,and related variables shouldn't be off_t not size_t.3. Adjust the comparisons in need_gc_qtexts() to be done in 64-bitarithmetic on all platforms. It appears possible that under duressthose multiplications could overflow 32 bits, yielding a falseconclusion that we need to garbage-collect the texts file, whichcould lead to repeatedly garbage-collecting after every hash tableinsertion.Per report from Bruno da Silva. I'm not convinced that theseissues fully explain his problem; there may be some other bug that'scontributing to the query-texts file becoming so large in the firstplace. But it did get that big, so#2 is a reasonable defense,and#3 could explain the reported performance difficulties.(See also commit8bbe4cb, which addressed some related bugs.The second Discussion: link is the thread that led up to that.)This issue is old, and is primarily a problem for old platforms,so back-patch.Discussion:https://postgr.es/m/CAB+Nuk93fL1Q9eLOCotvLP07g7RAv4vbdrkm0cVQohDVMpAb9A@mail.gmail.comDiscussion:https://postgr.es/m/5601D354.5000703@BlueTreble.com1 parentc034b62 commit82ebc70
1 file changed
+22
-4
lines changedLines changed: 22 additions & 4 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
399 | 399 |
| |
400 | 400 |
| |
401 | 401 |
| |
402 |
| - | |
| 402 | + | |
403 | 403 |
| |
404 | 404 |
| |
405 | 405 |
| |
| |||
2094 | 2094 |
| |
2095 | 2095 |
| |
2096 | 2096 |
| |
| 2097 | + | |
| 2098 | + | |
| 2099 | + | |
| 2100 | + | |
| 2101 | + | |
| 2102 | + | |
| 2103 | + | |
| 2104 | + | |
| 2105 | + | |
| 2106 | + | |
| 2107 | + | |
| 2108 | + | |
2097 | 2109 |
| |
2098 | 2110 |
| |
2099 | 2111 |
| |
| |||
2279 | 2291 |
| |
2280 | 2292 |
| |
2281 | 2293 |
| |
2282 |
| - | |
2283 |
| - | |
| 2294 | + | |
| 2295 | + | |
| 2296 | + | |
| 2297 | + | |
| 2298 | + | |
| 2299 | + | |
| 2300 | + | |
| 2301 | + | |
2284 | 2302 |
| |
2285 | 2303 |
| |
2286 | 2304 |
| |
| |||
2290 | 2308 |
| |
2291 | 2309 |
| |
2292 | 2310 |
| |
2293 |
| - | |
| 2311 | + | |
2294 | 2312 |
| |
2295 | 2313 |
| |
2296 | 2314 |
| |
|
0 commit comments
Comments
(0)