diff contrib/pg_stat_statements/pg_stat_statements.c index 8f5c9b0..d8b829d *** a/contrib/pg_stat_statements/pg_stat_statements.c --- b/contrib/pg_stat_statements/pg_stat_statements.c *************** pgss_store(const char *query, uint32 que *** 964,975 **** * strings are normalized on a best effort basis, though it would be * difficult to demonstrate this even under artificial conditions.) * But if we found the entry already present, don't let this call ! * increment its usage. */ if (!entry) usage = pgss->cur_median_usage; else ! usage = 0; } else { --- 964,978 ---- * strings are normalized on a best effort basis, though it would be * difficult to demonstrate this even under artificial conditions.) * But if we found the entry already present, don't let this call ! * increment its usage - just fastpath out of here without even ! * acquiring a spinlock for the entry, since the only reason we'll need ! * to do so in a call from pgss_post_parse_analyze() is to initially set ! * usage to the median to make the entry sticky. */ if (!entry) usage = pgss->cur_median_usage; else ! goto done; } else { *************** pgss_store(const char *query, uint32 que *** 1060,1065 **** --- 1063,1069 ---- SpinLockRelease(&e->mutex); } + done: LWLockRelease(pgss->lock); /* We postpone this pfree until we're out of the lock */