Sami Imseih <samims...@gmail.com> writes: > I think the solution proposed by Frédéric seems reasonable: to switch > the debug_query_string > inside PortalDrop. However, I do not like the way the > debug_query_string changes values > after the CreatePortal call inside exec_bind_message; that seems incorrect. > So, I believe we should temporarily switch the debug_query_string > value only while > running PortalDrop. Attached is what I think could be safer to do. > What do you think?
I don't think this is safe at all. The portal's query string is potentially shorter-lived than the portal, see in particular exec_simple_query which just passes a pointer to the original string in MessageContext. I'm frankly inclined to do nothing, but if we must do something, the way to fix it here would be to transiently set debug_query_string to NULL so that the actions of PortalDrop aren't blamed on any particular query. (In my testing, the "temporary file:" message comes out without any attached STATEMENT most of the time already, so this isn't losing much as far as that's concerned.) The whole thing is just a band-aid, though. debug_query_string is not the only indicator of what the backend is currently doing. If somebody comes along and complains that the pg_stat_activity entry doesn't reflect what's happening, are we going to take that seriously? Perhaps a cleaner answer is to rearrange things in postgres.c so that if there's a pre-existing unnamed portal, we drop that before we ever set debug_query_string and friends at all. This would add an extra portal hashtable lookup, but I'm not sure if that would be measurable or not. (Possibly we could get that back by simplifying CreatePortal's API so that it doesn't need to perform an initial lookup.) regards, tom lane