简体   繁体   中英

PgSQL taking too much time too respond

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM