Hi Tom, Thanks for your reply. As you said, the weirdest part is the the SP ran fine in primary server and hot standby server. I did another test over the weekend: (1) restore the production DB dump to an internal server with replication set up. (2) ran the SP in internal hot standy DB (3) surprisingly the SP ran fast in internal hot standby DB So what is the possible explanations to these test results? Is there a way to tell if the SP scans through all children event_startstop tables as you said? Thanks a lot, Pius -- View this message in context: http://postgresql.1045698.n5.nabble.com/stored-procedure-suddenly-runs-slowly-in-HOT-STANDBY-but-fast-in-primary-tp5810599p5810779.html Sent from the PostgreSQL - performance mailing list archive at Nabble.com.