Looks like it's not sql issue, manually running still use prepared statements and use same sql plan. -----Original Message----- From: Andreas Kretschmer <andreas@xxxxxxxxxxxxxxx> Sent: Friday, November 17, 2023 5:17 PM To: pgsql-performance@xxxxxxxxxxxxxxxxxxxx Subject: Re: simple query running long time within a long transaction. Am 17.11.23 um 09:10 schrieb James Pang (chaolpan): > > Hi, > > We found one simple query manually run very fast(finished in > several milliseconds), but there are 2 sessions within long > transaction to run same sql with same bind variables took tens of seconds. > you try to set plan_cache_mode to force_custom_plan, default is auto and with that and bind variables pg will use a generic plan. Regards, Andreas -- Andreas Kretschmer - currently still (garden leave) Technical Account Manager (TAM) www.enterprisedb.com