0

Please see screenshot below. The values highlighted jump between 80 and 95 percent.

enter image description here

As you can see, the postgres process is taking up all the CPU. However, the user processes percentage is only 5%. As a matter of fact, the majority of the CPU is considered idle. The dashboard on Google Cloud also says that the machine has most CPU idle.

I've collected information here Linux "top" command: What are us, sy, ni, id, wa, hi, si and st (for CPU usage)?

and here: https://scoutapm.com/blog/understanding-linuxs-cpu-stats

The latter source specifically says that databases are part of the 'user space' part. How can this discrepancy be explained? Does it have something to do with different CPU cores?

Update:

Pressing 1 after doing the top command displays cpu use per core:

enter image description here

There are 18 (!) CPU cores. As you can see, one of them is totally eaten up by postgres but the rest is empty. Am I to understand that the %CPU as listed in the top command only shows how much it takes of a single core? This was not clear to me from the sources I have found.

Taking a more solution oriented approach: Adding more cores won't do anything. Rather expanding the size of the CPU running the postgres process could potentially lower the CPU percentage it uses?

3

1 Answer 1

2

As you can see, the postgres process is taking up all the CPU.

No, it's taking up a single CPU core - that's what 100% under Unix/Linux means. And even that is not precise.

Your postgres process may have two active threads each taking 50% of two different CPU cores and top / ps will report 100%.

Does it have something to do with different CPU cores?

Yes.

As you can see, one of them is totally eaten up by postgres but the rest is empty.

On your screenshot there are two busy CPU cores, one 88%, another one 9%. Their sum is close to what your posgres is using.

Adding more cores won't do anything.

It depends however in your particular situation it seems like whatever workload you're running it's bounded by single-threaded CPU performance, so you're correct.

Rather expanding the size of the CPU running the postgres process could potentially lower the CPU percentage it uses?

I'm not sure what you mean.

3
  • 2
    In addition to that (or, in other words), 17 idle CPUs out of 18 available is 94.4% idle, and that's what the header shows. The postgres process is using 97+% of a single CPU.
    – Kusalananda
    Commented Nov 19, 2020 at 14:23
  • What is your reason for regarding high CPU usage as a bad thing? If it is properly cooled, it does no damage. The scheduler could process each timeslice on a different CPU (it may already be doing this: System Monitor would show you). Commented Nov 19, 2020 at 14:47
  • 1
    ... in fact, seeing postgrep (arithmetically) used 88% of cpu6 and 9% of cpu7 in the (1.5 second ?) top sample rate, indicates it is changing CPUs at least once. Commented Nov 19, 2020 at 15:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .