last few days i am facing a weird issue on db side. A simple query taking too much time and when i am trying to connect my aws rds with pgadmin it disconnect after some seconds. this issue didn't occur before. i don't know how to solve this issues
and here is the stats of my aws rds:
The execution plan:
Aggregate (cost=9315.62..9315.63 rows=1 width=8) (actual time=59379.535..59379.536 rows=1 loops=1)
Buffers: shared hit=32669 dirtied=5
-> Index Only Scan using users_pkey on users (cost=0.42..8758.99 rows=222652 width=0) (actual time=0.058..41652.438 rows=223966 loops=1)
Heap Fetches: 33168
Buffers: shared hit=32669 dirtied=5
Planning time: 0.653 ms
Execution time: 59439.600 ms
Here is the scenario. I am calling an api in which my code executing 2 or 3 queries. if simple query on db taking 15 secs then a normal query will take more than 30 secs and whenever my api takes more than 30 secs the Heroku server throws H12(503 service unavailable) error and nothing will render on my front side. so i am trying to figure out why the rds db taking too much time to respond a simple db query that should respond in milli seconds. for info i am sharing one of the breakdown table of an api. we can clearly see that database taking 90% of the time.
Counting is slow business – you have to scan all rows to count them.
That said, you could make your index-only scan faster by running VACUUM
on the table, so that the number of "heap fetches" (to check tuple visibility) goes down.
Apart from that, the only possibility for improvement is to rewrite the table with VACUUM (FULL)
to get rid of bloat. But don't forget to VACUUM
again after doing that.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.