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 1f1Auu-0007sN-MX for pgsql-general@arkaria.postgresql.org; Wed, 28 Mar 2018 13:15:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f1Aut-0004zD-NC for pgsql-general@arkaria.postgresql.org; Wed, 28 Mar 2018 13:15:03 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f1Aut-0004x9-Bs for pgsql-general@lists.postgresql.org; Wed, 28 Mar 2018 13:15:03 +0000 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1f1Auo-0005LX-MO for pgsql-general@lists.postgresql.org; Wed, 28 Mar 2018 13:15:02 +0000 Received: by mail-wm0-x244.google.com with SMTP id l16so5237042wmh.3 for ; Wed, 28 Mar 2018 06:14:58 -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=yFzS1R7x7/OPdinf89bcSdo8bk/3q8OEL7eQ8n7Mg/c=; b=GdcTAFHeHs3bsiEH57CB5031ij9ncxRoBAKEhxJYhDDG34IK1weijxODdTfmjBequ6 5ZY2dkVFIpqu1h6uEgDVkR+9VUf0RGFLVr9HTffim9rQKQuyUp39zkEgRTVzODhS0XUn 2NeoIPoTHRxhGUYlm2AgZynfr1O3o0Dl/NtFh9MaFDq6o1x0Zt2y2jjH54GsH6NfHQKd E+SXqt/M2JkryEcbdy2Ko3vsAPbgbLuTovoLUmqivCjugZ2l4wY8SlFAUiPl7BeklZgw QivaEawkMlHjPWLrhfqIwq9cxsIdYAOxqItWLAErvYSGGK1524btrMpc7HODWtYQOCka w8nQ== 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=yFzS1R7x7/OPdinf89bcSdo8bk/3q8OEL7eQ8n7Mg/c=; b=p9fhxzW94q20fgmfLogjb0wLOVqX5J4cvGBsMPJsm1M03H7QGGgEgIilP9mI0+ZIZF wg4EHM/7oUItuEA32WM4F0LDzEeROple6i2+6fMIqVhXlqBhsJkcUM1kb6u2INBQYobW OiK4udrNk1oCW8QTsnZ4bDUvboUmkO2woRABZ05ze8FimEyz+hTr8HwrNsQaUwiU/F+J 5gcaMnJIjoInXOe6okYll9L3sf5yEo17K/VteThkK2zRCn2eJVeZBNX/mL6elfaHrfBr gDUvwD3gyznJhFxZ6qCkOaSPrzEBclHNgIs2QrqvbCueea1rjE1RH/V+Egtpk95fKInh zpjQ== X-Gm-Message-State: AElRT7Gti1vnc72uWugjCbJol7UvOepr1T31iWOHOAlGc3IF3KgiDCd8 +/T5VdqDeQdHvf0reSEVBAKkWXBoji/QoJU7bxxp1uE8RicSfdqd6fXdKdlBij56EIQo/E8cDf3 bBPFw8YTzJOmWyJvp2QuXIlfe+ZkTUVa5A2cMhaYECP+F3ufCmT8MVvu/7e7Yf7wjgqmwJKoB5G amQzoWyRpiAApa6i8l X-Google-Smtp-Source: AIpwx4/SP6wqbVeoV6LYKhWIa1MGq5lPCAWU8gdY5nNh4UBfO7Go1Kn98SOxOQTzB6h/HdGvlHy8lQ== X-Received: by 10.80.154.195 with SMTP id p61mr3526766edb.68.1522242896493; Wed, 28 Mar 2018 06:14:56 -0700 (PDT) Received: from [10.137.2.19] (ip-78-102-97-226.net.upcbroadband.cz. [78.102.97.226]) by smtp.gmail.com with ESMTPSA id i61sm2278065edc.53.2018.03.28.06.14.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 28 Mar 2018 06:14:55 -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: <005f2752-7b3e-634b-484b-0a933ce27474@2ndquadrant.com> From: Tomas Vondra Message-ID: <36a5e21f-1d90-1d69-c6d9-9ec997ac486c@2ndquadrant.com> Date: Wed, 28 Mar 2018 15:14:53 +0200 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 Hi, the perf profiles look really weird - clearly, there's a lot of lock contention, because the top item is this 13.49% 13.40% postmaster postgres [.] LWLockAcquire | ---LWLockAcquire That's a sign of lock contention - not sure which one, though. And then there's heap_hot_search_buffer 12.65% 7.92% postmaster postgres [.] heap_hot_search_buffer | ---heap_hot_search_buffer So either there's a table with many HOT-updated rows (repeatedly), or we search the HOT chains very frequently for some reason. Considering it only affects the non-LIMIT case, I'd guess the latter. There also seems to be quite a few page faults, for some reason. Trying to reproduce this without the actual data is rather futile. We need some sort of reproducer (sample data to test the query on). regards On 03/28/2018 10:30 AM, Alessandro Aste wrote: > Hello,  any news ? > > Thank you, > > Alessandro. > > On Fri, Mar 23, 2018 at 8:22 PM, Alessandro Aste > > wrote: > > PS , in the meanwhile I discovered a 2nd workaround(beside disabling > parallel processing) . I added offset  0 to the subquery , and, > according to the documentation, “OFFSET 0 is the same as omitting > the OFFSET clause” > - https://www.postgresql.org/docs/current/static/queries-limit.html > > > cmd3dev=# show max_parallel_workers_per_gather ; > > *max_parallel_workers_per_gather* > > *---------------------------------* > > *8* > > (1 row) > >   > > cmd3dev=# \timing > > Timing is on. > > cmd3dev=#  SELECT * FROM (SELECT seg.circuit_id AS id, > vendor_gtt_pop.vendor_id, CASE WHEN vendor_gtt_pop.push_to_gaa = 1 > THEN 'Y' END as gaa, pop.gii_circuitid AS pop_name, cst.label AS > pop_status, seg.a_company_name AS pop_location, seg.vendor_id AS > pop_provider_id, seg.vendor_name AS pop_provider, cs.address1 AS > pop_street, cs.city AS pop_city, cs.postal_code AS pop_postal_code, > cs.state AS pop_state, csc.code AS pop_country, cs.country_id AS > pop_country_id FROM ( SELECT c.gii_circuitid, max(so.id > ) AS service_order_id FROM service_order so join > circuit c on c.product_id=so.product_id join master_service_order > mso on mso.id =so.master_service_order_id WHERE NOT > (so.ordertype_id = 2 AND so.status <> 999) AND NOT (so.ordertype_id > = 3 AND so.status <> 999) AND c.status >= 20 AND c.status not in > (160,999) AND mso.client_id=11615 AND c.service_description=28 AND > c.status!=160 GROUP BY c.gii_circuitid ) pop JOIN service_order so > ON so.id = pop.service_order_id left JOIN client_site > cs on cs.id =so.a_site_id left JOIN country csc on > csc.id =cs.country_id JOIN circuit c ON > so.product_id=c.product_id JOIN circuit_status cst ON cst.id > =c.status JOIN ( SELECT c.id AS > circuit_id, sg.id AS segment_id, > c.pop_support_vendor_id AS vendor_id, v.name AS > vendor_name, sg.a_company_name FROM segment sg JOIN circuit_layout > cl ON cl.segment_id = sg.id AND cl.ordinal = 1 JOIN > circuit c ON c.id = cl.circuit_id JOIN vendor v ON > v.id = c.pop_support_vendor_id ) seg ON seg.circuit_id > = c.id JOIN vendor_gtt_pop on > vendor_gtt_pop.gtt_pop_id = seg.circuit_id offset 0) foo where > vendor_id = 12346 AND (1=1) ORDER BY pop_name ASC,id desc LIMIT 10; > >    id   | vendor_id | gaa |   pop_name    | pop_status | > pop_location | pop_provider_id | pop_provider |     pop_street      > | pop_city | pop > > _postal_code | pop_state | pop_country | pop_country_id > > --------+-----------+-----+---------------+------------+--------------+-----------------+--------------+---------------------+----------+---- > > -------------+-----------+-------------+---------------- > > 684807 |     12346 | Y   | GTT/POP/LON1T | Active     | LON1T        > |           12288 | Telehouse UK | 14 Coriander Avenue | London   | E14 > > 2AA         |           | GB          |            219 > > (1 row) > >   > > *Time: 2245.073 ms (00:02.245)* > > > > > On Fri, Mar 23, 2018 at 9:31 AM, Alessandro Aste > > wrote: > > Tomas, I'm attaching a 4MB file with the perf report. Let me > know if it gets blocked, I'll shrink it to the first 1000 lines.  > > Thank you, > > Alessandro. > > On Thu, Mar 22, 2018 at 11:42 PM, Tomas Vondra > > wrote: > > On 03/22/2018 11:29 PM, Alessandro Aste wrote: > > Thanks Tomas. We're currently building postgres from source. In order to > > enable symbols, you want me to re-configure postres with  --enable-debug > > then run perf? > > > > Yes. > > regards > > -- > Tomas Vondra                  http://www.2ndQuadrant.com > PostgreSQL Development, 24x7 Support, Remote DBA, Training & > Services > > > > -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services