EDIT: It seems to have been fixed thanks to @graycube@lemmy.world. Running analyze verbose; in postgres.

After updating to 0.19.5 from 0.19.3 my postgres is often using up 500%+ of CPU according to docker stats and often going to 100% CPU on most cores according to htop. Also noticed in the uptime monitor:

htop shows one of the 5 postgres processes constantly on UPDATE. I think this might be part of the problem.

I’m not comfortable with postgres and am honestly completely in the dark how or where to mitigate or even pinpoint this issue.

Any help would be appreciated.

      • graycube@lemmy.world
        link
        fedilink
        arrow-up
        9
        ·
        5 days ago

        Sometimes after upgrades, even minor ones, I find it useful to run analyze on all of the tables. I usually do analyze verbose; so I can see which tables are getting analyzed. This will assess every table so the query planner can make better decisions about how to resolve queries. If the query planner is making bad decisions I/O and CPU will be high and query performance will be poor.

        • DosDude👾OPA
          link
          fedilink
          arrow-up
          5
          ·
          edit-2
          5 days ago

          Thanks. I ran it. Hopefully it’ll make a difference.

          Edit: It looks like this did the trick. I’ll keep monitoring to see if it sticks. Thanks again!

    • DosDude👾OPA
      link
      fedilink
      arrow-up
      2
      ·
      5 days ago
      ERROR:  extension "pg_stats_statements" is not available
      

      Even though it’s added in the customPostgresql.conf shared_preload_libraries = 'auto_explain,pg_stat_statements'

      • static09@lemmy.world
        link
        fedilink
        arrow-up
        4
        ·
        5 days ago

        I know you already found a solution, but fwiw, it seems you have a typo in calling the extension. You have “stats” plural instead of “stat” singular.

    • mlg@lemmy.world
      link
      fedilink
      English
      arrow-up
      3
      ·
      5 days ago

      commit “fixed stuff”

      2.8k blob of crypto mining code

      Would be hilarious

    • DosDude👾OPA
      link
      fedilink
      arrow-up
      2
      ·
      5 days ago

      I have. And I tried to tweak it with no avail. But it was working within acceptable levels before the update.

      • taaz@biglemmowski.win
        link
        fedilink
        English
        arrow-up
        2
        ·
        edit-2
        5 days ago

        hmm, how many connections are used SELECT count(*) FROM pg_stat_activity; ?
        I am not a master postgres admin but my intuition has been that the amount of connections is a big factor in how pg behaves with cpu and mem.

        • DosDude👾OPA
          link
          fedilink
          arrow-up
          1
          ·
          5 days ago
          ERROR:  extension "pg_stats_statements" is not available
          

          Even though it’s added in the customPostgresql.conf shared_preload_libraries = 'auto_explain,pg_stat_statements'

            • DosDude👾OPA
              link
              fedilink
              arrow-up
              2
              ·
              5 days ago

              I added pg_stat_statements, and ran it. This was the result:

              # SELECT count(*) FROM pg_stat_activity;
               count
              -------
                  11
              (1 row)
              
              
              • taaz@biglemmowski.win
                link
                fedilink
                English
                arrow-up
                3
                ·
                5 days ago

                do you also have pict-rs connected to this postgres instance? that is surprisingly low number to me, I would have expected anywhere between 20-50 active connections (I use 50 for lemmy and 20 for pict-rs, configured in their respective conf files)