Question

Postgresql low throughput, high server CPU after changes, CDN latency spike

I made a lot of changes on my server, database, and the queries my server makes to that database (too many to know where the issue is). The changes have brought my DO app’s performance to a crawl. The server’s CPU is through the roof. I suspect the issue is because the connected Postgresql throughput has plummeted.

I’ve tried to setup 3rd party tools like datadog before but I couldn’t get them to work after a week so I gave up.

Server App CPU
Server App CPU
Server Latency Spike
Server Latency Spike
DB Throughput
DB Throughput

My queries are very fast locally, so I’m not sure what these metrics mean. My DB cache his rate is between 99% - 100%, load average is ~0.5, CPU is 22%, and Index vs Sequential Scans is 98.9%. I’m struggling to find resources to explain these metrics in-depth.

  1. What is Rows Fetched vs Rows Read?
  2. Is it better to have a higher amount of Rows Fetched : Rows Read ratio?
  3. What are some best practices to ensure my database is fetching enough data?
  4. How can I confirm if the problem is coming from my server or my database?

Thanks.

Show comments

Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
August 7, 2024

Hey there!

First, let’s tackle your specific questions:

  1. Rows Fetched vs Rows Read: Think of Rows Read as all the data your database looks at, while Rows Fetched is what it actually sends back to your app. It’s like scanning a whole book (Rows Read) but only copying a few pages (Rows Fetched).

  2. Is a higher Rows Fetched to Rows Read ratio better? Generally, yes! It means your queries are more efficient, like finding exactly what you need in that book without flipping through every page.

  3. Best practices for database fetching:

    • Use indexes wisely (like a book’s table of contents)
    • Only ask for the data you need (avoid SELECT *)
    • Use LIMIT to keep result sets manageable
    • Try pagination for large data sets
    • Keep optimizing those queries!
  4. Is it the server or the database? Good question! To figure this out:

    • Keep an eye on both server and database metrics
    • Use query logging to spot slow queries
    • Check database wait events for bottlenecks
    • Monitor the network between your server and database

Now, looking at your metrics, that high cache hit rate and low load average suggest your database might not be the main culprit. The high server CPU usage points more towards an application issue.

Here’s what I’d suggest:

  1. Take a close look at your recent changes, especially around database queries.
  2. Hunt for any queries that might be running too often or inefficiently.
  3. Check for new CPU-hungry tasks on your server.
  4. Scan your app logs for anything unusual.
  5. Give DigitalOcean’s built-in monitoring tools a shot, or try something simple like Prometheus with node_exporter:

https://docs.digitalocean.com/products/databases/postgresql/how-to/monitor-databases/

If you’re still stuck, don’t be afraid to roll back some changes temporarily. It might help you pinpoint what’s causing the slowdown.

- Bobby

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.