forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit17fd203
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 parentd947a8b commit17fd203
1 file changed
+22
-4
lines changedLines changed: 22 additions & 4 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
385 | 385 |
| |
386 | 386 |
| |
387 | 387 |
| |
388 |
| - | |
| 388 | + | |
389 | 389 |
| |
390 | 390 |
| |
391 | 391 |
| |
| |||
2060 | 2060 |
| |
2061 | 2061 |
| |
2062 | 2062 |
| |
| 2063 | + | |
| 2064 | + | |
| 2065 | + | |
| 2066 | + | |
| 2067 | + | |
| 2068 | + | |
| 2069 | + | |
| 2070 | + | |
| 2071 | + | |
| 2072 | + | |
| 2073 | + | |
| 2074 | + | |
2063 | 2075 |
| |
2064 | 2076 |
| |
2065 | 2077 |
| |
| |||
2245 | 2257 |
| |
2246 | 2258 |
| |
2247 | 2259 |
| |
2248 |
| - | |
2249 |
| - | |
| 2260 | + | |
| 2261 | + | |
| 2262 | + | |
| 2263 | + | |
| 2264 | + | |
| 2265 | + | |
| 2266 | + | |
| 2267 | + | |
2250 | 2268 |
| |
2251 | 2269 |
| |
2252 | 2270 |
| |
| |||
2256 | 2274 |
| |
2257 | 2275 |
| |
2258 | 2276 |
| |
2259 |
| - | |
| 2277 | + | |
2260 | 2278 |
| |
2261 | 2279 |
| |
2262 | 2280 |
| |
|
0 commit comments
Comments
(0)