PG-2395 Fetch datname and username from syscache in pgsm_store()#658
PG-2395 Fetch datname and username from syscache in pgsm_store()#658AndersAstrand wants to merge 1 commit into
Conversation
Resolve them from the catalog in pgsm_store() rather than in pgsm_create_hash_entry(). We have a bug report we have not been able to reproduce where queryDesc->totaltime is freed mid-call in pgsm_ExecutorEnd(), most likely by cache invalidation processing during these syscache lookups when they ran inside pgsm_create_hash_entry(). The misbehaving callback is most likely from another extension or the RDS fork of PostgreSQL, since standard invalidation callbacks does not seem to touch the relevant memory context.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #658 +/- ##
==========================================
- Coverage 86.32% 86.17% -0.16%
==========================================
Files 3 3
Lines 1346 1345 -1
Branches 217 218 +1
==========================================
- Hits 1162 1159 -3
Misses 87 87
- Partials 97 99 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
jeltz
left a comment
There was a problem hiding this comment.
I don't feel the commit message actually explains why this fix makes sense. Is it because it is now allocated in another memory context? If so that was not clear from the commit message.
| extract_query_comments(query, comments, sizeof(comments)); | ||
| comments_len = strlen(comments); | ||
|
|
||
| if (IsTransactionState() && strlen(entry->datname) == 0) |
There was a problem hiding this comment.
I can't say I am a fan pf this kind of trying to set multiple times. When can it already be set? At least I think we should document that.
That's great feedback! It's hard to write with the right level of detail when you have all the context in your head that the reader probably doesn't :). Here is a full explanation of my reasoning. Do you think all of this should go in the commit message? The bug report #651 includes a stack trace that shows that by the time we read A lot of my analysis was based on what we do differently compared to Now the issue could also be present in One of the things we do, that I had no way of verifying this suspicion however since I was unable to reproduce the bug, so I simply moved the syscache lookups to somewhere after we're done with |
|
But if the issue is |
Resolve them from the catalog in pgsm_store() rather than in pgsm_create_hash_entry(). We have a bug report we have not been able to reproduce where queryDesc->totaltime is freed mid-call in pgsm_ExecutorEnd(), most likely by cache invalidation processing during these syscache lookups when they ran inside pgsm_create_hash_entry(). The misbehaving callback is most likely from another extension or the RDS fork of PostgreSQL, since standard invalidation callbacks does not seem to touch the relevant memory context.
I didn't change the undefined behavior of passing NULL to snprintf() in this PR, but we should fix it in the future (i believe glibc inserts a placeholder like
(null)for us which is the existing behavior before this PR.)