After updating Discourse, the user bar10dr experiences intermittent 502 Bad Gateway errors when posting and accessing user profiles. Nginx logs show upstream connection timeouts, while PostgreSQL logs reveal extremely slow queries, such as a 600-second COUNT(*) on the posts table. The user suspects indexing issues and runs REINDEX DATABASE discourse and VACUUM on the database. The errors improve after vacuuming, but user profile pages still fail with 502s. The user is running PostgreSQL 15 in a shared Docker instance and is unsure if the upgrade was properly handled, referencing a guide for PostgreSQL 15 updates PostgreSQL 15 update. pfaffman suggests checking the PostgreSQL version and considering a command-line rebuild if the upgrade wasn’t fully completed. bar10dr confirms the version is 15 and notes improved performance but persistent profile-related 502s.
2025-04-29 18:48:24.709 UTC [1746] discourse@discourse LOG: duration: 606789.911 ms execute <unnamed>: SELECT COUNT(*) FROM "posts" WHERE "posts"."deleted_at" IS NULL
duration: 606789.911 ms
We do have a lot of posts, few users.. why is it using 600k ms on this?
You can check the postgres version at /var/discourse/shared/standalone/postgres_data/PG_VERSION – If you did a command line upgrade, it’s possible that it did the upgrade and you didn’t notice (but you’d have to have run the rebuild twice). If you upgraded from the web interface, you should probably go ahead and do a command line rebuild if your OS and docker are recent versions.