Query in PostgreSQL became slow and then got better on its own - why?












0















I want to better understand how to debug and fix performance issues in PostgreSQL.



I have a query that usually costs 1 second to run. However, for some reason, it started taking 30 seconds to run for a period of time! After some minutes and some explain analyze invocations, it went back to normal. I didn't do anything to fix it, nor did I understand why it got better all of a sudden.



How do I debug a problem like this? What kind of logging and instrumentation should I have in place to understand what caused this and how to fix it?










share|improve this question
















bumped to the homepage by Community 14 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.











  • 1





    System busy overall? Table(s) undergoing a large update? Large analytic type query being run? The Gods not appreciating your invocations? :-) On a more serious note, this is the reason you should have monitoring software installed before problems arise! Do you have anything like sysstat or nagios or similar?

    – Vérace
    Apr 19 '18 at 3:14











  • No. Just some simple logs in pg. Was considering using the ELK stack to get all kinds of verbose logs

    – ivarec
    Apr 19 '18 at 3:15






  • 1





    Have you considered the excellent (and Open Source) sysstat tools?

    – Vérace
    Apr 19 '18 at 3:34











  • Go this link. It may help you..! dbrnd.com/2016/02/…

    – Ramanna Gunde
    Apr 19 '18 at 5:41
















0















I want to better understand how to debug and fix performance issues in PostgreSQL.



I have a query that usually costs 1 second to run. However, for some reason, it started taking 30 seconds to run for a period of time! After some minutes and some explain analyze invocations, it went back to normal. I didn't do anything to fix it, nor did I understand why it got better all of a sudden.



How do I debug a problem like this? What kind of logging and instrumentation should I have in place to understand what caused this and how to fix it?










share|improve this question
















bumped to the homepage by Community 14 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.











  • 1





    System busy overall? Table(s) undergoing a large update? Large analytic type query being run? The Gods not appreciating your invocations? :-) On a more serious note, this is the reason you should have monitoring software installed before problems arise! Do you have anything like sysstat or nagios or similar?

    – Vérace
    Apr 19 '18 at 3:14











  • No. Just some simple logs in pg. Was considering using the ELK stack to get all kinds of verbose logs

    – ivarec
    Apr 19 '18 at 3:15






  • 1





    Have you considered the excellent (and Open Source) sysstat tools?

    – Vérace
    Apr 19 '18 at 3:34











  • Go this link. It may help you..! dbrnd.com/2016/02/…

    – Ramanna Gunde
    Apr 19 '18 at 5:41














0












0








0








I want to better understand how to debug and fix performance issues in PostgreSQL.



I have a query that usually costs 1 second to run. However, for some reason, it started taking 30 seconds to run for a period of time! After some minutes and some explain analyze invocations, it went back to normal. I didn't do anything to fix it, nor did I understand why it got better all of a sudden.



How do I debug a problem like this? What kind of logging and instrumentation should I have in place to understand what caused this and how to fix it?










share|improve this question
















I want to better understand how to debug and fix performance issues in PostgreSQL.



I have a query that usually costs 1 second to run. However, for some reason, it started taking 30 seconds to run for a period of time! After some minutes and some explain analyze invocations, it went back to normal. I didn't do anything to fix it, nor did I understand why it got better all of a sudden.



How do I debug a problem like this? What kind of logging and instrumentation should I have in place to understand what caused this and how to fix it?







postgresql postgresql-performance postgresql-10






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 19 '18 at 2:04







ivarec

















asked Apr 19 '18 at 1:46









ivarecivarec

948




948





bumped to the homepage by Community 14 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 14 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.










  • 1





    System busy overall? Table(s) undergoing a large update? Large analytic type query being run? The Gods not appreciating your invocations? :-) On a more serious note, this is the reason you should have monitoring software installed before problems arise! Do you have anything like sysstat or nagios or similar?

    – Vérace
    Apr 19 '18 at 3:14











  • No. Just some simple logs in pg. Was considering using the ELK stack to get all kinds of verbose logs

    – ivarec
    Apr 19 '18 at 3:15






  • 1





    Have you considered the excellent (and Open Source) sysstat tools?

    – Vérace
    Apr 19 '18 at 3:34











  • Go this link. It may help you..! dbrnd.com/2016/02/…

    – Ramanna Gunde
    Apr 19 '18 at 5:41














  • 1





    System busy overall? Table(s) undergoing a large update? Large analytic type query being run? The Gods not appreciating your invocations? :-) On a more serious note, this is the reason you should have monitoring software installed before problems arise! Do you have anything like sysstat or nagios or similar?

    – Vérace
    Apr 19 '18 at 3:14











  • No. Just some simple logs in pg. Was considering using the ELK stack to get all kinds of verbose logs

    – ivarec
    Apr 19 '18 at 3:15






  • 1





    Have you considered the excellent (and Open Source) sysstat tools?

    – Vérace
    Apr 19 '18 at 3:34











  • Go this link. It may help you..! dbrnd.com/2016/02/…

    – Ramanna Gunde
    Apr 19 '18 at 5:41








1




1





System busy overall? Table(s) undergoing a large update? Large analytic type query being run? The Gods not appreciating your invocations? :-) On a more serious note, this is the reason you should have monitoring software installed before problems arise! Do you have anything like sysstat or nagios or similar?

– Vérace
Apr 19 '18 at 3:14





System busy overall? Table(s) undergoing a large update? Large analytic type query being run? The Gods not appreciating your invocations? :-) On a more serious note, this is the reason you should have monitoring software installed before problems arise! Do you have anything like sysstat or nagios or similar?

– Vérace
Apr 19 '18 at 3:14













No. Just some simple logs in pg. Was considering using the ELK stack to get all kinds of verbose logs

– ivarec
Apr 19 '18 at 3:15





No. Just some simple logs in pg. Was considering using the ELK stack to get all kinds of verbose logs

– ivarec
Apr 19 '18 at 3:15




1




1





Have you considered the excellent (and Open Source) sysstat tools?

– Vérace
Apr 19 '18 at 3:34





Have you considered the excellent (and Open Source) sysstat tools?

– Vérace
Apr 19 '18 at 3:34













Go this link. It may help you..! dbrnd.com/2016/02/…

– Ramanna Gunde
Apr 19 '18 at 5:41





Go this link. It may help you..! dbrnd.com/2016/02/…

– Ramanna Gunde
Apr 19 '18 at 5:41










1 Answer
1






active

oldest

votes


















0














It is a very broad question, even more so as you give absolutely no details about your setup and kind of database (volume, type of queries, active connections, size of RAM, dedicated server or not, etc.)



You can start by enabling PostgreSQL to log slow queries, see the log_min_duration_statement in the configuration. That will give you historical data that you would then be able to analyze and maybe correlate with other things (like from the list of @Vérace)



You will then have various tools to help, as described on https://wiki.postgresql.org/wiki/Logging_Difficult_Queries :




  • pgFouine

  • PQA

  • EPQA

  • pgsi






share|improve this answer























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "182"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f204388%2fquery-in-postgresql-became-slow-and-then-got-better-on-its-own-why%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    It is a very broad question, even more so as you give absolutely no details about your setup and kind of database (volume, type of queries, active connections, size of RAM, dedicated server or not, etc.)



    You can start by enabling PostgreSQL to log slow queries, see the log_min_duration_statement in the configuration. That will give you historical data that you would then be able to analyze and maybe correlate with other things (like from the list of @Vérace)



    You will then have various tools to help, as described on https://wiki.postgresql.org/wiki/Logging_Difficult_Queries :




    • pgFouine

    • PQA

    • EPQA

    • pgsi






    share|improve this answer




























      0














      It is a very broad question, even more so as you give absolutely no details about your setup and kind of database (volume, type of queries, active connections, size of RAM, dedicated server or not, etc.)



      You can start by enabling PostgreSQL to log slow queries, see the log_min_duration_statement in the configuration. That will give you historical data that you would then be able to analyze and maybe correlate with other things (like from the list of @Vérace)



      You will then have various tools to help, as described on https://wiki.postgresql.org/wiki/Logging_Difficult_Queries :




      • pgFouine

      • PQA

      • EPQA

      • pgsi






      share|improve this answer


























        0












        0








        0







        It is a very broad question, even more so as you give absolutely no details about your setup and kind of database (volume, type of queries, active connections, size of RAM, dedicated server or not, etc.)



        You can start by enabling PostgreSQL to log slow queries, see the log_min_duration_statement in the configuration. That will give you historical data that you would then be able to analyze and maybe correlate with other things (like from the list of @Vérace)



        You will then have various tools to help, as described on https://wiki.postgresql.org/wiki/Logging_Difficult_Queries :




        • pgFouine

        • PQA

        • EPQA

        • pgsi






        share|improve this answer













        It is a very broad question, even more so as you give absolutely no details about your setup and kind of database (volume, type of queries, active connections, size of RAM, dedicated server or not, etc.)



        You can start by enabling PostgreSQL to log slow queries, see the log_min_duration_statement in the configuration. That will give you historical data that you would then be able to analyze and maybe correlate with other things (like from the list of @Vérace)



        You will then have various tools to help, as described on https://wiki.postgresql.org/wiki/Logging_Difficult_Queries :




        • pgFouine

        • PQA

        • EPQA

        • pgsi







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered May 2 '18 at 15:56









        Patrick MevzekPatrick Mevzek

        6641416




        6641416






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Database Administrators Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f204388%2fquery-in-postgresql-became-slow-and-then-got-better-on-its-own-why%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            SQL Server 17 - Attemping to backup to remote NAS but Access is denied

            Always On Availability groups resolving state after failover - Remote harden of transaction...

            Restoring from pg_dump with foreign key constraints