Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1ez2e3-0001AO-7w for pgsql-general@arkaria.postgresql.org; Thu, 22 Mar 2018 16:00:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ez2e2-0005uq-75 for pgsql-general@arkaria.postgresql.org; Thu, 22 Mar 2018 16:00:50 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1ez2e1-0005ug-VK for pgsql-general@lists.postgresql.org; Thu, 22 Mar 2018 16:00:50 +0000 Received: from mail-wr0-x243.google.com ([2a00:1450:400c:c0c::243]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ez2dx-00038F-CS for pgsql-general@lists.postgresql.org; Thu, 22 Mar 2018 16:00:49 +0000 Received: by mail-wr0-x243.google.com with SMTP id 80so8153690wrb.2 for ; Thu, 22 Mar 2018 09:00:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=GwOdgLrctUSJgthQgEuidJoBuPh9crMaqpbuWg6tU/E=; b=ntsfceP2+qje9oIIUonIst1BNVOsl4uBuK9Utg1hEVj/Wcykmtpk+XFDhfVICFuJAc qGEWpnlRvMsPAcBkilmPC3vbLgoE6R7r9aET2XeJMk33FhcByHtIZimb8od2Hivh4BNs dR9cCDO764w8myUz/kKhwidYGs2ZeFgOEg9DOdZLz4z/Yek4WvWVOCLy9FYi/gWICSr3 hLqeloFNamJPBloyZ68YaE9rLFL3hF86OpQZMyOscUN3YgE8H0IzVAJ6nF0iun04Qm5o Qf5p/2TNCIroX+fOYVINSEVqshUlDvug6TbxdKmVm+groDU+tFHpNKj1D2NPL81HCyiK H5fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=GwOdgLrctUSJgthQgEuidJoBuPh9crMaqpbuWg6tU/E=; b=OeQlDeJgO9XT/YdK1sCvQLtVSmkH4o8hUJiQPvHEgKoz58r321hv42o27v747HLGI7 kk1QKduIilcB+Z3VTgvuI7SS6HEIa4CjlDrdoRnqpwsELWzlZMy12cOtLl8SjvBgJHHl eYWLJe8AyCl1H6B4dQj4MzDMYuzmkh2t4Cmpryu4JaIQbnhNSJ55gMmyGO0hMNdZ8Oy0 LlEXtKNpQlABNWic+gtdfbBpDmKkz6rgfufE83b8o3fUyyPYg3DTWPWW/1xp2p/JAJQD 1YgJhQgo6fzUDI9ENrBnAU/TbZfzkT+RLTQpt33utPs7JDRkizVH38jFXUhF839OR6aI Sgdg== X-Gm-Message-State: AElRT7ExJE0oOZ16Mf6FWyF2yx6E7XDwGmIJcVqlFuebcYeIZZvW1cRW Kg46GCyqsWrNorjgf2CUfveNn2ix4/KcYMSaksTWDMNwO68W0Rz9zwP7kZPmoDPUt7HQEvsISNO xAeY4U1vhbG9haM+9PA1moeSOEQsJJnLon2TVpOaJuqgNhlu21LLb/jAG0I6W1BUxWfPiK/KDoY NvpVqqhOAZyRZ2mmrArHc= X-Google-Smtp-Source: AG47ELsejRI/Z4wcOlFIlzwW5FMyMAy5QMEC9/zlToE1dSR/znChsaOWcnuZuVeouXOAkCU6mb3bGg== X-Received: by 10.223.128.98 with SMTP id 89mr19974103wrk.141.1521734441910; Thu, 22 Mar 2018 09:00:41 -0700 (PDT) Received: from [10.137.2.17] ([212.24.157.174]) by smtp.gmail.com with ESMTPSA id n47sm7931721wrf.41.2018.03.22.09.00.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Mar 2018 09:00:40 -0700 (PDT) Subject: Re: Postgresql 10.3 , query never completes if LIMIT clause is specified and paralle processing is on To: Alessandro Aste Cc: pgsql-general@lists.postgresql.org References: From: Tomas Vondra Message-ID: Date: Thu, 22 Mar 2018 17:00:37 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 03/22/2018 11:33 AM, Alessandro Aste wrote: > Tomas, thank you. This machine  is abare metal server running only a > staging postgresql 10.3  instance. Nobody is using it beside me.  > > I'm attaching 4 files.   > > every_30_seconds_top_stats_during_query.txt    - this is a caputure of > the top command every 30 seconds(more or less) for 10+ minutes while I'm > running the query. Let me know if this helps to answere your question. > EXPLAIN_WITH_LIMIT_AND_max_parallel_workers_per_gather_SET_TO_0.txt   -  > query plan  with full query and  max_parallel_workers_per_gather  force > to 0. Full output. > EXPLAIN_WITH_LIMIT_AND_DEFAULT_PARALLEL_PROCESSING_SETTINGS.txt  -  >  query plan with full query and  default parellel processing settings.  > Full output. > EXPLAIN_WITHOUT_LIMIT_AND_DEFAULT_PARALLEL_PROCESSING_SETTINGS.tx  - > query plan of the query omitting the LIMIT clause and default parellel > processing settings. Full output. > OK. Looking at the top output, I see this: PID USER VIRT RES SHR S %CPU %MEM TIME+ COMMAND 104880 postgres 30.8g 1.9g 1.9g R 92.0 1.5 15:15.60 postmaster 111732 postgres 30.8g 476m 473m R 88.2 0.4 0:00.47 postmaster 111730 postgres 30.8g 473m 470m R 86.4 0.4 0:00.46 postmaster 111731 postgres 30.8g 476m 473m R 86.4 0.4 0:00.46 postmaster 111733 postgres 30.8g 476m 473m R 86.4 0.4 0:00.46 postmaster 111734 postgres 30.8g 476m 473m R 86.4 0.4 0:00.46 postmaster 111728 root 15824 1912 828 R 3.8 0.0 0:00.04 top That means it certainly is not stuck, it's simply doing a lot of work on CPU. The question is why and what it's doing ... Can you collect some CPU profiles using perf? There's a howto here: https://wiki.postgresql.org/wiki/Profiling_with_perf But in short - install perf, install debuginfo packages for postgres, and then do perf record -a -g -s sleep 60 while running the query. Once the profile data is collected, do perf report > report.txt and share the report.txt with us (well, if it's very large you may need to only cut the first 1000 lines or so). That should tell us in which functions most of the time is spent. That will give us some hints, hopefully. > > For what concerns the  self-contained test case - I'll do my best to > prepare it. > Yeah, that would be helpful. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services