pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Postgresql 10.3 , query never completes if LIMIT clause is specified and paralle processing is on
12+ messages / 2 participants
[nested] [flat]

* Postgresql 10.3 , query never completes if LIMIT clause is specified and paralle processing is on
@ 2018-03-21 16:09  Alessandro Aste <alessandro.aste@gmail.com>
  0 siblings, 1 reply; 12+ messages in thread

From: Alessandro Aste @ 2018-03-21 16:09 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

Hi there, we are using postgresql 10.3 and we're facing an issue with a
query. The query (full query below)  completes only  when:

1 - LIMIT 10 is removed
or
2 -  show max_parallel_workers_per_gather  is set to 0, so parallel
processing is disabled.

With  max_parallel_workers_per_gather   set to the default value (8) I'm
not even able to get the query plan.

Notes:


   - We're experiencing the issue in any server of ours but I've reproduced
   the issue in a fresh restored database with full vacuum/reindex of the
   tables.
   - We didn't touch any parameter concering the parallel processing, we're
   running the defaults:


cmdstaging=# show max_parallel_workers_per_gather ;
 max_parallel_workers_per_gather
---------------------------------
 8
(1 row)

cmdstaging=# show max_worker_processes ;
 max_worker_processes
----------------------
 8
(1 row)

cmdstaging=# show max_parallel_workers;
 max_parallel_workers
----------------------
 8
(1 row)




The query completes only omitting the LIMIT clause or when I disable
parallel processing:

 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 |     | GTT/POP/LON1T | Active     | LON1T        |
       12288 | Telehouse UK | 14 Coriander Avenue | London   | E14
 2AA         |           | GB          |            219
(1 row)

Time: 4374.759 ms (00:04.375)
cmdstaging=# show max_parallel_workers_per_gather ;
 max_parallel_workers_per_gather
---------------------------------
 0
(1 row)

Time: 0.097 ms


Otherwise it just keep running for forever.






This is the full query:



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
) foo where vendor_id = 12346 AND (1=1) ORDER BY pop_name ASC,id LIMIT 10



Execution plan with  max_parallel_workers_per_gather =0 ,
max_parallel_workers_per_gather =8 and no LIMIT clause :



=== QUERY PLAN WITH  max_parallel_workers_per_gather  = 0 ===

 Limit  (cost=433508.77..433508.77 rows=1 width=176) (actual
time=2992.875..2992.875 rows=1 loops=1)
   ->  Sort  (cost=433508.77..433508.77 rows=1 width=176) (actual
time=2992.874..2992.874 rows=1 loops=1)
         Sort Key: c_2.gii_circuitid, c_1.id
         Sort Method: quicksort  Memory: 25kB
         ->  Nested Loop  (cost=168438.04..433508.76 rows=1 width=176)
(actual time=1747.038..2992.864 rows=1 loops=1)
               Join Filter: (c_1.id = vendor_gtt_pop.gtt_pop_id)
               Rows Removed by Join Filter: 662
               ->  Hash Join  (cost=168438.04..433486.80 rows=1 width=148)
(actual time=1540.484..2952.522 rows=663 loops=1)
                     Hash Cond: (c_1.id = c.id)
                     ->  Hash Join  (cost=125957.20..388048.64 rows=788618
width=63) (actual time=1335.406..2746.835 rows=1582 loops=1)
                           Hash Cond: (c_1.pop_support_vendor_id = v.id)
                           ->  Hash Join  (cost=125518.15..377653.28
rows=788618 width=40) (actual time=1330.727..2711.206 rows=778564 loops=
1)
                                 Hash Cond: (sg.id = cl.segment_id)
                                 ->  Seq Scan on segment sg
(cost=0.00..231189.42 rows=3482542 width=32) (actual time=0.004..472.967
rows=34
83328 loops=1)
                                 ->  Hash  (cost=115660.43..115660.43
rows=788618 width=16) (actual time=1328.852..1328.852 rows=778564 loops
=1)
                                       Buckets: 1048576  Batches: 1  Memory
Usage: 41653kB
                                       ->  Merge Join
(cost=4.59..115660.43 rows=788618 width=16) (actual time=0.034..1179.131
rows=778564 l
oops=1)
                                             Merge Cond: (cl.circuit_id =
c_1.id)
                                             ->  Index Only Scan using
circuit_layout_idx on circuit_layout cl  (cost=0.43..61739.87 rows=788
618 width=8) (actual time=0.016..348.350 rows=778564 loops=1)
                                                   Index Cond: (ordinal = 1)
                                                   Heap Fetches: 778564
                                             ->  Index Scan using
circuit_id_key on circuit c_1  (cost=0.42..41790.58 rows=909014 width=8) (a
ctual time=0.011..326.429 rows=909014 loops=1)
                           ->  Hash  (cost=325.69..325.69 rows=9069
width=27) (actual time=2.753..2.753 rows=9069 loops=1)
                                 Buckets: 16384  Batches: 1  Memory Usage:
669kB
                                 ->  Seq Scan on vendor v
(cost=0.00..325.69 rows=9069 width=27) (actual time=0.006..1.489 rows=9069
loops=1
)
                     ->  Hash  (cost=42480.82..42480.82 rows=1 width=85)
(actual time=205.073..205.073 rows=882 loops=1)
                           Buckets: 1024  Batches: 1  Memory Usage: 102kB
                           ->  Nested Loop  (cost=42469.41..42480.82 rows=1
width=85) (actual time=184.020..204.776 rows=882 loops=1)
                                 Join Filter: (c.status = cst.id)
Time: 3016.688 ms (00:03.017)



=== QUERY PLAN WITH  max_parallel_workers_per_gather  = 8 and NO LIMIT
clause ===


-
-----------------------------------------------------------------------------------
 Sort  (cost=253514.80..253514.81 rows=1 width=176) (actual
time=1121.737..1121.737 rows=1 loops=1)
   Sort Key: c_2.gii_circuitid, c_1.id
   Sort Method: quicksort  Memory: 25kB
   ->  Hash Join  (cost=33193.56..253514.79 rows=1 width=176) (actual
time=1121.723..1121.726 rows=1 loops=1)
         Hash Cond: (c_1.id = c.id)
         ->  Gather  (cost=1466.02..221787.23 rows=3 width=75) (actual
time=1027.012..1027.015 rows=1 loops=1)
               Workers Planned: 5
               Workers Launched: 5
               ->  Hash Join  (cost=466.02..220786.93 rows=1 width=75)
(actual time=964.279..1020.204 rows=0 loops=6)
                     Hash Cond: (c_1.id = vendor_gtt_pop.gtt_pop_id)
                     ->  Hash Join  (cost=444.07..219779.19 rows=157724
width=63) (actual time=122.728..1019.934 rows=264 loops=6)
                           Hash Cond: (c_1.pop_support_vendor_id = v.id)
                           ->  Merge Join  (cost=5.02..217348.87
rows=157724 width=40) (actual time=1.089..1007.302 rows=129761 loops=6)
                                 Merge Cond: (cl.circuit_id = c_1.id)
                                 ->  Nested Loop  (cost=0.86..171314.49
rows=157724 width=32) (actual time=0.056..477.965 rows=129761 loops=6
)
                                       ->  Parallel Index Only Scan using
circuit_layout_idx on circuit_layout cl  (cost=0.43..55430.93 rows=
157724 width=8) (actual time=0.031..96.328 rows=129761 loops=6)
                                             Index Cond: (ordinal = 1)
                                             Heap Fetches: 163021
                                       ->  Index Scan using uniqid on
segment sg  (cost=0.43..0.73 rows=1 width=32) (actual time=0.002..0.002
 rows=1 loops=778564)
                                             Index Cond: (id =
cl.segment_id)
                                 ->  Index Scan using circuit_id_key on
circuit c_1  (cost=0.42..41790.58 rows=909014 width=8) (actual time=0
.018..377.993 rows=908914 loops=6)
                           ->  Hash  (cost=325.69..325.69 rows=9069
width=27) (actual time=3.441..3.441 rows=9069 loops=6)
                                 Buckets: 16384  Batches: 1  Memory Usage:
669kB
                                 ->  Seq Scan on vendor v
(cost=0.00..325.69 rows=9069 width=27) (actual time=0.013..1.850 rows=9069
loops=6
)
                     ->  Hash  (cost=21.91..21.91 rows=3 width=12) (actual
time=0.118..0.118 rows=1 loops=6)
                           Buckets: 1024  Batches: 1  Memory Usage: 9kB
                           ->  Seq Scan on vendor_gtt_pop
(cost=0.00..21.91 rows=3 width=12) (actual time=0.113..0.113 rows=1 loops=6)
                                 Filter: (vendor_id = 12346)
                                 Rows Removed by Filter: 1192
         ->  Hash  (cost=31727.53..31727.53 rows=1 width=85) (actual
time=94.693..94.693 rows=882 loops=1)
               Buckets: 1024  Batches: 1  Memory Usage: 102kB
               ->  Nested Loop  (cost=31725.15..31727.53 rows=1 width=85)
(actual time=83.507..94.344 rows=882 loops=1)
                     ->  Nested Loop  (cost=31725.02..31727.38 rows=1
width=74) (actual time=83.496..93.575 rows=882 loops=1)
                           ->  Nested Loop Left Join
(cost=31724.59..31726.89 rows=1 width=70) (actual time=83.484..90.885
rows=882 loops=1)
                                 ->  Nested Loop Left Join
(cost=31724.45..31726.73 rows=1 width=68) (actual time=83.475..90.067
rows=882 lo
ops=1)
                                       ->  Nested Loop
(cost=31724.02..31726.27 rows=1 width=30) (actual time=83.461..87.442
rows=882 loops=
1)
                                             ->  GroupAggregate
(cost=31723.60..31723.62 rows=1 width=26) (actual time=83.446..83.812 rows=8
82 loops=1)
                                                   Group Key:
c_2.gii_circuitid
                                                   ->  Sort
(cost=31723.60..31723.60 rows=1 width=26) (actual time=83.441..83.515
rows=884 l
oops=1)
                                                         Sort Key:
c_2.gii_circuitid
                                                         Sort Method:
quicksort  Memory: 94kB
                                                         ->  Gather
(cost=1000.85..31723.59 rows=1 width=26) (actual time=2.159..81.342 rows
=884 loops=1)
                                                               Workers
Planned: 3
                                                               Workers
Launched: 2
                                                               ->  Nested
Loop  (cost=0.85..30723.49 rows=1 width=26) (actual time=8.509..75.
845 rows=295 loops=3)
                                                                     ->
Nested Loop  (cost=0.42..30722.56 rows=2 width=30) (actual time=8.48
3..74.283 rows=295 loops=3)

 ->  Parallel Seq Scan on circuit c_2  (cost=0.00..30714.61 rows=3
width=26) (actual time=5.992..72.563 rows=316 loops=3)

     Filter: ((status >= 20) AND (status <> ALL ('{160,999}'::int
eger[])) AND (status <> 160) AND (service_description = 28))

     Rows Removed by Filter: 302689

 ->  Index Scan using so_pid_idx on service_order so_1  (cost=0.42.
.2.65 rows=1 width=12) (actual time=0.005..0.005 rows=1 loops=948)

     Index Cond: (product_id = c_2.product_id)

     Filter: (((ordertype_id <> 2) OR (status = 999)) AND ((order
type_id <> 3) OR (status = 999)))

     Rows Removed by Filter: 0
                                                                     ->
Index Scan using master_service_order_id_key on master_service_order
 mso  (cost=0.42..0.46 rows=1 width=4) (actual time=0.005..0.005 rows=1
loops=884)

 Index Cond: (id = so_1.master_service_order_id)

 Filter: (client_id = 11615)
                                             ->  Index Scan using
service_order_id_key on service_order so  (cost=0.42..2.64 rows=1 width=12)
 (actual time=0.003..0.003 rows=1 loops=882)
                                                   Index Cond: (id = (max(
so_1.id)))
                                       ->  Index Scan using
client_site_pkey on client_site cs  (cost=0.42..0.46 rows=1 width=46)
(actual tim
e=0.003..0.003 rows=1 loops=882)
                                             Index Cond: (id = so.a_site_id)
                                 ->  Index Scan using country_pkey on
country csc  (cost=0.14..0.16 rows=1 width=6) (actual time=0.001..0.001
 rows=1 loops=882)
                                       Index Cond: (id = cs.country_id)
                           ->  Index Scan using circuit_product_id_idx on
circuit c  (cost=0.42..0.49 rows=1 width=12) (actual time=0.003..0.
003 rows=1 loops=882)
                                 Index Cond: (product_id = so.product_id)
                     ->  Index Scan using cs_id_c on circuit_status cst
(cost=0.14..0.16 rows=1 width=19) (actual time=0.001..0.001 rows=1 l
oops=882)
                           Index Cond: (id = c.status)
 Planning time: 3.889 ms
 Execution time: 1122.357 ms
(68 rows)



Thank you very much for your help,

Kind regards,


Alessandro Aste.

^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: Postgresql 10.3 , query never completes if LIMIT clause is specified and paralle processing is on
@ 2018-03-21 19:01  Tomas Vondra <tomas.vondra@2ndquadrant.com>
  parent: Alessandro Aste <alessandro.aste@gmail.com>
  0 siblings, 1 reply; 12+ messages in thread

From: Tomas Vondra @ 2018-03-21 19:01 UTC (permalink / raw)
  To: Alessandro Aste <alessandro.aste@gmail.com>; pgsql-general@lists.postgresql.org



On 03/21/2018 05:09 PM, Alessandro Aste wrote:
> Hi there, we are using postgresql 10.3 and we're facing an issue with a
> query. The query (full query below)  completes only  when: 
> 
> 1 - LIMIT 10 is removed
> or
> 2 -  show max_parallel_workers_per_gather  is set to 0, so parallel
> processing is disabled.
> 
> With  max_parallel_workers_per_gather   set to the default value (8) I'm
> not even able to get the query plan.
> 
> Notes: 
> 
>   * We're experiencing the issue in any server of ours but I've
>     reproduced the issue in a fresh restored database with full
>     vacuum/reindex of the tables.
>   * We didn't touch any parameter concering the parallel processing,
>     we're running the defaults: 
> 
> 
> cmdstaging=# show max_parallel_workers_per_gather ;
>  max_parallel_workers_per_gather
> ---------------------------------
>  8
> (1 row)
> 
> cmdstaging=# show max_worker_processes ;
>  max_worker_processes
> ----------------------
>  8
> (1 row)
> 
> cmdstaging=# show max_parallel_workers;
>  max_parallel_workers
> ----------------------
>  8
> (1 row)
> 
> 
> 
> 
> The query completes only omitting the LIMIT clause or when I disable
> parallel processing: 
> 
>  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 |     | GTT/POP/LON1T | Active     | LON1T        | 
>          12288 | Telehouse UK | 14 Coriander Avenue | London   | E14
>  2AA         |           | GB          |            219
> (1 row)
> 
> Time: 4374.759 ms (00:04.375)
> cmdstaging=# show max_parallel_workers_per_gather ;
>  max_parallel_workers_per_gather
> ---------------------------------
>  0
> (1 row)
> 
> Time: 0.097 ms
> 
> 
> Otherwise it just keep running for forever. 
> 

When you say "running forever" is it actually using CPU, or does it get
stuck on something?

> 
> This is the full query: 
> 
> 
> 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 <http://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 <http://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 <http://so.id; = pop.service_order_id
> left JOIN client_site cs on cs.id <http://cs.id>=so.a_site_id
> left JOIN country csc on csc.id <http://csc.id>=cs.country_id
> JOIN circuit c ON so.product_id=c.product_id
> JOIN circuit_status cst ON cst.id <http://cst.id>=c.status
> JOIN (
> SELECT c.id <http://c.id; AS circuit_id, sg.id <http://sg.id; AS segment_id, c.pop_support_vendor_id AS vendor_id,
> v.name <http://v.name; AS vendor_name, sg.a_company_name
> FROM segment sg
> JOIN circuit_layout cl ON cl.segment_id = sg.id <http://sg.id; AND cl.ordinal = 1
> JOIN circuit c ON c.id <http://c.id; = cl.circuit_id
> JOIN vendor v ON v.id <http://v.id; = c.pop_support_vendor_id
> ) seg ON seg.circuit_id = c.id <http://c.id;
> JOIN vendor_gtt_pop on vendor_gtt_pop.gtt_pop_id = seg.circuit_id
> ) foo where vendor_id = 12346 AND (1=1) ORDER BY pop_name ASC,id LIMIT 10
> 
> 
> 
> Execution plan with  max_parallel_workers_per_gather =0 , 
> max_parallel_workers_per_gather =8 and no LIMIT clause : 
> 
> 
We really need to see the execution plan that causes issues, i.e.
max_parallel_workers_per_gather=8 with LIMIT clause. Plain explain
(without analyze), at least.

regards

-- 
Tomas Vondra                  http://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services




^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: Postgresql 10.3 , query never completes if LIMIT clause is specified and paralle processing is on
@ 2018-03-21 19:44  Alessandro Aste <alessandro.aste@gmail.com>
  parent: Tomas Vondra <tomas.vondra@2ndquadrant.com>
  0 siblings, 1 reply; 12+ messages in thread

From: Alessandro Aste @ 2018-03-21 19:44 UTC (permalink / raw)
  To: Tomas Vondra <tomas.vondra@2ndquadrant.com>; +Cc: pgsql-general@lists.postgresql.org

Thanks for your reply Tomas.  The query just got stuck for forever.  I
observed no CPU spikes, it is currently running and I see 89 of the CPU
idle. I'm using a relative powerfull machine (120 GB ram, 56 CPU).


Plain analyze as requested. :



                    QUERY PLAN

------------------------------------------------------------
------------------------------------------------------------
---------------------
-------------------------------------------------------------
 Limit  (cost=253523.56..253523.57 rows=1 width=176)
   ->  Sort  (cost=253523.56..253523.57 rows=1 width=176)
         Sort Key: c_2.gii_circuitid, c_1.id
         ->  Nested Loop  (cost=33190.89..253523.55 rows=1 width=176)
               Join Filter: (c_1.id = c.id)
               ->  Nested Loop  (cost=31724.87..31736.29 rows=1 width=85)
                     Join Filter: (c.status = cst.id)
                     ->  Nested Loop  (cost=31724.87..31734.84 rows=1
width=74)
                           ->  Nested Loop Left Join
(cost=31724.45..31734.35 rows=1 width=70)
                                 Join Filter: (csc.id = cs.country_id)
                                 ->  Nested Loop Left Join
(cost=31724.45..31726.73 rows=1 width=68)
                                       ->  Nested Loop
(cost=31724.02..31726.27 rows=1 width=30)
                                             ->  GroupAggregate
(cost=31723.60..31723.62 rows=1 width=26)
                                                   Group Key:
c_2.gii_circuitid
                                                   ->  Sort
(cost=31723.60..31723.60 rows=1 width=26)
                                                         Sort Key:
c_2.gii_circuitid
                                                         ->  Gather
(cost=1000.85..31723.59 rows=1 width=26)
                                                               Workers
Planned: 3
                                                               ->  Nested
Loop  (cost=0.85..30723.49 rows=1 width=26)
                                                                     ->
Nested Loop  (cost=0.42..30722.56 rows=2 width=30)

 ->  Parallel Seq Scan on circuit c_2  (cost=0.00..30714.61 rows=3
width=26)

     Filter: ((status >= 20) AND (status <> ALL ('{160,999}'::int
eger[])) AND (status <> 160) AND (service_description = 28))

 ->  Index Scan using so_pid_idx on service_order so_1  (cost=0.42.
.2.65 rows=1 width=12)

     Index Cond: (product_id = c_2.product_id)

     Filter: (((ordertype_id <> 2) OR (status = 999)) AND ((order
type_id <> 3) OR (status = 999)))
                                                                     ->
Index Scan using master_service_order_id_key on master_service_order
 mso  (cost=0.42..0.46 rows=1 width=4)

 Index Cond: (id = so_1.master_service_order_id)

 Filter: (client_id = 11615)
                                             ->  Index Scan using
service_order_id_key on service_order so  (cost=0.42..2.64 rows=1 width=12)
                                                   Index Cond: (id = (max(
so_1.id)))
                                       ->  Index Scan using
client_site_pkey on client_site cs  (cost=0.42..0.46 rows=1 width=46)
                                             Index Cond: (id = so.a_site_id)
                                 ->  Seq Scan on country csc
(cost=0.00..4.50 rows=250 width=6)
                           ->  Index Scan using circuit_product_id_idx on
circuit c  (cost=0.42..0.49 rows=1 width=12)
                                 Index Cond: (product_id = so.product_id)
                     ->  Seq Scan on circuit_status cst  (cost=0.00..1.20
rows=20 width=19)
               ->  Gather  (cost=1466.02..221787.23 rows=3 width=75)
                     Workers Planned: 5
                     ->  Hash Join  (cost=466.02..220786.93 rows=1 width=75)
                           Hash Cond: (c_1.id = vendor_gtt_pop.gtt_pop_id)
                           ->  Hash Join  (cost=444.07..219779.19
rows=157724 width=63)
                                 Hash Cond: (c_1.pop_support_vendor_id =
v.id)
                                 ->  Merge Join  (cost=5.02..217348.87
rows=157724 width=40)
                                       Merge Cond: (cl.circuit_id = c_1.id)
                                       ->  Nested Loop
(cost=0.86..171314.49 rows=157724 width=32)
                                             ->  Parallel Index Only Scan
using circuit_layout_idx on circuit_layout cl  (cost=0.43..55430.93
 rows=157724 width=8)
                                                   Index Cond: (ordinal = 1)
                                             ->  Index Scan using uniqid on
segment sg  (cost=0.43..0.73 rows=1 width=32)
                                                   Index Cond: (id =
cl.segment_id)
                                       ->  Index Scan using circuit_id_key
on circuit c_1  (cost=0.42..41790.58 rows=909014 width=8)
                                 ->  Hash  (cost=325.69..325.69 rows=9069
width=27)
                                       ->  Seq Scan on vendor v
(cost=0.00..325.69 rows=9069 width=27)
                           ->  Hash  (cost=21.91..21.91 rows=3 width=12)
                                 ->  Seq Scan on vendor_gtt_pop
(cost=0.00..21.91 rows=3 width=12)
                                       Filter: (vendor_id = 12346)
(55 rows)





On Wed, Mar 21, 2018 at 8:01 PM, Tomas Vondra <tomas.vondra@2ndquadrant.com>
wrote:

>
>
> On 03/21/2018 05:09 PM, Alessandro Aste wrote:
> > Hi there, we are using postgresql 10.3 and we're facing an issue with a
> > query. The query (full query below)  completes only  when:
> >
> > 1 - LIMIT 10 is removed
> > or
> > 2 -  show max_parallel_workers_per_gather  is set to 0, so parallel
> > processing is disabled.
> >
> > With  max_parallel_workers_per_gather   set to the default value (8) I'm
> > not even able to get the query plan.
> >
> > Notes:
> >
> >   * We're experiencing the issue in any server of ours but I've
> >     reproduced the issue in a fresh restored database with full
> >     vacuum/reindex of the tables.
> >   * We didn't touch any parameter concering the parallel processing,
> >     we're running the defaults:
> >
> >
> > cmdstaging=# show max_parallel_workers_per_gather ;
> >  max_parallel_workers_per_gather
> > ---------------------------------
> >  8
> > (1 row)
> >
> > cmdstaging=# show max_worker_processes ;
> >  max_worker_processes
> > ----------------------
> >  8
> > (1 row)
> >
> > cmdstaging=# show max_parallel_workers;
> >  max_parallel_workers
> > ----------------------
> >  8
> > (1 row)
> >
> >
> >
> >
> > The query completes only omitting the LIMIT clause or when I disable
> > parallel processing:
> >
> >  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 |     | GTT/POP/LON1T | Active     | LON1T        |
> >          12288 | Telehouse UK | 14 Coriander Avenue | London   | E14
> >  2AA         |           | GB          |            219
> > (1 row)
> >
> > Time: 4374.759 ms (00:04.375)
> > cmdstaging=# show max_parallel_workers_per_gather ;
> >  max_parallel_workers_per_gather
> > ---------------------------------
> >  0
> > (1 row)
> >
> > Time: 0.097 ms
> >
> >
> > Otherwise it just keep running for forever.
> >
>
> When you say "running forever" is it actually using CPU, or does it get
> stuck on something?
>
> >
> > This is the full query:
> >
> >
> > 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 <http://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 <http://mso.id>=so.master_serv
> ice_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 <http://so.id; = pop.service_order_id
> > left JOIN client_site cs on cs.id <http://cs.id>=so.a_site_id
> > left JOIN country csc on csc.id <http://csc.id>=cs.country_id
> > JOIN circuit c ON so.product_id=c.product_id
> > JOIN circuit_status cst ON cst.id <http://cst.id>=c.status
> > JOIN (
> > SELECT c.id <http://c.id; AS circuit_id, sg.id <http://sg.id; AS
> segment_id, c.pop_support_vendor_id AS vendor_id,
> > v.name <http://v.name; AS vendor_name, sg.a_company_name
> > FROM segment sg
> > JOIN circuit_layout cl ON cl.segment_id = sg.id <http://sg.id; AND
> cl.ordinal = 1
> > JOIN circuit c ON c.id <http://c.id; = cl.circuit_id
> > JOIN vendor v ON v.id <http://v.id; = c.pop_support_vendor_id
> > ) seg ON seg.circuit_id = c.id <http://c.id;
> > JOIN vendor_gtt_pop on vendor_gtt_pop.gtt_pop_id = seg.circuit_id
> > ) foo where vendor_id = 12346 AND (1=1) ORDER BY pop_name ASC,id LIMIT 10
> >
> >
> >
> > Execution plan with  max_parallel_workers_per_gather =0 ,
> > max_parallel_workers_per_gather =8 and no LIMIT clause :
> >
> >
> We really need to see the execution plan that causes issues, i.e.
> max_parallel_workers_per_gather=8 with LIMIT clause. Plain explain
> (without analyze), at least.
>
> regards
>
> --
> Tomas Vondra                  http://www.2ndQuadrant.com
> PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
>

^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: Postgresql 10.3 , query never completes if LIMIT clause is specified and paralle processing is on
@ 2018-03-22 02:04  Tomas Vondra <tomas.vondra@2ndquadrant.com>
  parent: Alessandro Aste <alessandro.aste@gmail.com>
  0 siblings, 1 reply; 12+ messages in thread

From: Tomas Vondra @ 2018-03-22 02:04 UTC (permalink / raw)
  To: Alessandro Aste <alessandro.aste@gmail.com>; +Cc: pgsql-general@lists.postgresql.org


On 03/21/2018 08:44 PM, Alessandro Aste wrote:
> Thanks for your reply Tomas.  The query just got stuck for forever.  I
> observed no CPU spikes, it is currently running and I see 89 of the CPU
> idle. I'm using a relative powerfull machine (120 GB ram, 56 CPU).  
> 

That doesn't really answer the question, I'm afraid. I suppose "89 of
CPU" means that 89% idle in total, but 11% with 56 CPUs still means
about 6 cores 100% busy. But maybe you meant something else?

Is there something else running on the machine? If you look at "top" are
the processes (the one you're connected to and the parallel workers)
doing something on the CPU?

> 
> Plain analyze as requested. : 
> 

I don't see anything obviously broken with the query plan, and it's
difficult to compare with the other plans because they are quite different.

But there's one part of the plan interesting:

 Limit  (cost=253523.56..253523.57 rows=1 width=176)
   ->  Sort  (cost=253523.56..253523.57 rows=1 width=176)
         Sort Key: c_2.gii_circuitid, c_1.id
         ->  Nested Loop  (cost=33190.89..253523.55 rows=1 width=176)
               Join Filter: (c_1.id = c.id)
               ->  Nested Loop  (cost=31724.87..31736.29 rows=1 ...)
                     ...
               ->  Gather  (cost=1466.02..221787.23 rows=3 width=75)
                     Workers Planned: 5
                     ->  Hash Join  (cost=466.02..220786.93 rows=1 ...)
                         ...

That is, there's a Gather on the inner side of a Nested Loop. I wonder
if that might cause issues in case of under-estimate (in which case we'd
be restarting the Gather many times) ...


BTW one of the plans you sent earlier is incomplete, because it ends
like this:

    ->  Nested Loop  (cost=42469.41..42480.82 rows=1 width=85) (...)
        Join Filter: (c.status = cst.id)
    Time: 3016.688 ms (00:03.017)

That is, it's missing the part below the join.


That being said, I'm not sure what's the issue here. Can you prepare a
self-contained test case that we might use to reproduce the issue? For
example by dumping the relevant part of the tables?


regards

-- 
Tomas Vondra                  http://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services




^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: Postgresql 10.3 , query never completes if LIMIT clause is specified and paralle processing is on
@ 2018-03-22 10:33  Alessandro Aste <alessandro.aste@gmail.com>
  parent: Tomas Vondra <tomas.vondra@2ndquadrant.com>
  0 siblings, 1 reply; 12+ messages in thread

From: Alessandro Aste @ 2018-03-22 10:33 UTC (permalink / raw)
  To: Tomas Vondra <tomas.vondra@2ndquadrant.com>; +Cc: pgsql-general@lists.postgresql.org

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.


For what concerns the  self-contained test case - I'll do my best to
prepare it.

Thank you very much, please let me know if this answer your questions.






Il 22 mar 2018 3:04 AM, "Tomas Vondra" <tomas.vondra@2ndquadrant.com> ha
scritto:

>
> On 03/21/2018 08:44 PM, Alessandro Aste wrote:
> > Thanks for your reply Tomas.  The query just got stuck for forever.  I
> > observed no CPU spikes, it is currently running and I see 89 of the CPU
> > idle. I'm using a relative powerfull machine (120 GB ram, 56 CPU).
> >
>
> That doesn't really answer the question, I'm afraid. I suppose "89 of
> CPU" means that 89% idle in total, but 11% with 56 CPUs still means
> about 6 cores 100% busy. But maybe you meant something else?
>
> Is there something else running on the machine? If you look at "top" are
> the processes (the one you're connected to and the parallel workers)
> doing something on the CPU?
>
> >
> > Plain analyze as requested. :
> >
>
> I don't see anything obviously broken with the query plan, and it's
> difficult to compare with the other plans because they are quite different.
>
> But there's one part of the plan interesting:
>
>  Limit  (cost=253523.56..253523.57 rows=1 width=176)
>    ->  Sort  (cost=253523.56..253523.57 rows=1 width=176)
>          Sort Key: c_2.gii_circuitid, c_1.id
>          ->  Nested Loop  (cost=33190.89..253523.55 rows=1 width=176)
>                Join Filter: (c_1.id = c.id)
>                ->  Nested Loop  (cost=31724.87..31736.29 rows=1 ...)
>                      ...
>                ->  Gather  (cost=1466.02..221787.23 rows=3 width=75)
>                      Workers Planned: 5
>                      ->  Hash Join  (cost=466.02..220786.93 rows=1 ...)
>                          ...
>
> That is, there's a Gather on the inner side of a Nested Loop. I wonder
> if that might cause issues in case of under-estimate (in which case we'd
> be restarting the Gather many times) ...
>
>
> BTW one of the plans you sent earlier is incomplete, because it ends
> like this:
>
>     ->  Nested Loop  (cost=42469.41..42480.82 rows=1 width=85) (...)
>         Join Filter: (c.status = cst.id)
>     Time: 3016.688 ms (00:03.017)
>
> That is, it's missing the part below the join.
>
>
> That being said, I'm not sure what's the issue here. Can you prepare a
> self-contained test case that we might use to reproduce the issue? For
> example by dumping the relevant part of the tables?
>
>
> regards
>
> --
> Tomas Vondra                  http://www.2ndQuadrant.com
> PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
>

Attachments:

EXPLAIN_WITHOUT_LIMIT_AND_DEFAULT_PARALLEL_PROCESSING_SETTINGS.txt (text/plain, 5.2K) download QUERY PLAN Sort (cost=253514.80..253514.81 rows=1 width=176) Sort Key: c_2.gii_circuitid, c_1.id -> Hash Join (cost=33193.56..253514.79 rows=1 width=176) Hash Cond: (c_1.id = c.id) -> Gather (cost=1466.02..221787.23 rows=3 width=75) Workers Planned: 5 -> Hash Join (cost=466.02..220786.93 rows=1 width=75) Hash Cond: (c_1.id = vendor_gtt_pop.gtt_pop_id) -> Hash Join (cost=444.07..219779.19 rows=157724 width=63) Hash Cond: (c_1.pop_support_vendor_id = v.id) -> Merge Join (cost=5.02..217348.87 rows=157724 width=40) Merge Cond: (cl.circuit_id = c_1.id) -> Nested Loop (cost=0.86..171314.49 rows=157724 width=32) -> Parallel Index Only Scan using circuit_layout_idx on circuit_layout cl (cost=0.43..55430.93 rows=157724 width=8) Index Cond: (ordinal = 1) -> Index Scan using uniqid on segment sg (cost=0.43..0.73 rows=1 width=32) Index Cond: (id = cl.segment_id) -> Index Scan using circuit_id_key on circuit c_1 (cost=0.42..41790.58 rows=909014 width=8) -> Hash (cost=325.69..325.69 rows=9069 width=27) -> Seq Scan on vendor v (cost=0.00..325.69 rows=9069 width=27) -> Hash (cost=21.91..21.91 rows=3 width=12) -> Seq Scan on vendor_gtt_pop (cost=0.00..21.91 rows=3 width=12) Filter: (vendor_id = 12346) -> Hash (cost=31727.53..31727.53 rows=1 width=85) -> Nested Loop (cost=31725.15..31727.53 rows=1 width=85) -> Nested Loop (cost=31725.02..31727.38 rows=1 width=74) -> Nested Loop Left Join (cost=31724.59..31726.89 rows=1 width=70) -> Nested Loop Left Join (cost=31724.45..31726.73 rows=1 width=68) -> Nested Loop (cost=31724.02..31726.27 rows=1 width=30) -> GroupAggregate (cost=31723.60..31723.62 rows=1 width=26) Group Key: c_2.gii_circuitid -> Sort (cost=31723.60..31723.60 rows=1 width=26) Sort Key: c_2.gii_circuitid -> Gather (cost=1000.85..31723.59 rows=1 width=26) Workers Planned: 3 -> Nested Loop (cost=0.85..30723.49 rows=1 width=26) -> Nested Loop (cost=0.42..30722.56 rows=2 width=30) -> Parallel Seq Scan on circuit c_2 (cost=0.00..30714.61 rows=3 width=26) Filter: ((status >= 20) AND (status <> ALL ('{160,999}'::integer[])) AND (status <> 160) AND (service_description = 28)) -> Index Scan using so_pid_idx on service_order so_1 (cost=0.42..2.65 rows=1 width=12) Index Cond: (product_id = c_2.product_id) Filter: (((ordertype_id <> 2) OR (status = 999)) AND ((ordertype_id <> 3) OR (status = 999))) -> Index Scan using master_service_order_id_key on master_service_order mso (cost=0.42..0.46 rows=1 width=4) Index Cond: (id = so_1.master_service_order_id) Filter: (client_id = 11615) -> Index Scan using service_order_id_key on service_order so (cost=0.42..2.64 rows=1 width=12) Index Cond: (id = (max(so_1.id))) -> Index Scan using client_site_pkey on client_site cs (cost=0.42..0.46 rows=1 width=46) Index Cond: (id = so.a_site_id) -> Index Scan using country_pkey on country csc (cost=0.14..0.16 rows=1 width=6) Index Cond: (id = cs.country_id) -> Index Scan using circuit_product_id_idx on circuit c (cost=0.42..0.49 rows=1 width=12) Index Cond: (product_id = so.product_id) -> Index Scan using cs_id_c on circuit_status cst (cost=0.14..0.16 rows=1 width=19) Index Cond: (id = c.status)
EXPLAIN_WITH_LIMIT_AND_max_parallel_workers_per_gather_SET_TO_0.txt (text/plain, 5.6K) download Limit (cost=433508.77..433508.77 rows=1 width=176) -> Sort (cost=433508.77..433508.77 rows=1 width=176) Sort Key: c_2.gii_circuitid, c_1.id -> Nested Loop (cost=168438.04..433508.76 rows=1 width=176) Join Filter: (c_1.id = vendor_gtt_pop.gtt_pop_id) -> Hash Join (cost=168438.04..433486.80 rows=1 width=148) Hash Cond: (c_1.id = c.id) -> Hash Join (cost=125957.20..388048.64 rows=788618 width=63) Hash Cond: (c_1.pop_support_vendor_id = v.id) -> Hash Join (cost=125518.15..377653.28 rows=788618 width=40) Hash Cond: (sg.id = cl.segment_id) -> Seq Scan on segment sg (cost=0.00..231189.42 rows=3482542 width=32) -> Hash (cost=115660.43..115660.43 rows=788618 width=16) -> Merge Join (cost=4.59..115660.43 rows=788618 width=16) Merge Cond: (cl.circuit_id = c_1.id) -> Index Only Scan using circuit_layout_idx on circuit_layout cl (cost=0.43..61739.87 rows=788618 width=8) Index Cond: (ordinal = 1) -> Index Scan using circuit_id_key on circuit c_1 (cost=0.42..41790.58 rows=909014 width=8) -> Hash (cost=325.69..325.69 rows=9069 width=27) -> Seq Scan on vendor v (cost=0.00..325.69 rows=9069 width=27) -> Hash (cost=42480.82..42480.82 rows=1 width=85) -> Nested Loop (cost=42469.41..42480.82 rows=1 width=85) Join Filter: (c.status = cst.id) -> Nested Loop (cost=42469.41..42479.37 rows=1 width=74) -> Nested Loop Left Join (cost=42468.98..42478.89 rows=1 width=70) Join Filter: (csc.id = cs.country_id) -> Nested Loop Left Join (cost=42468.98..42471.26 rows=1 width=68) -> Nested Loop (cost=42468.56..42470.81 rows=1 width=30) -> GroupAggregate (cost=42468.13..42468.15 rows=1 width=26) Group Key: c_2.gii_circuitid -> Sort (cost=42468.13..42468.14 rows=1 width=26) Sort Key: c_2.gii_circuitid -> Nested Loop (cost=6063.84..42468.12 rows=1 width=26) -> Nested Loop (cost=6063.41..42465.82 rows=5 width=30) -> Bitmap Heap Scan on circuit c_2 (cost=6062.99..42439.29 rows=10 width=26) Recheck Cond: (status >= 20) Filter: ((status <> ALL ('{160,999}'::integer[])) AND (status <> 160) AND (service_description = 28)) -> Bitmap Index Scan on ckt_stat_idx (cost=0.00..6062.99 rows=576315 width=0) Index Cond: (status >= 20) -> Index Scan using so_pid_idx on service_order so_1 (cost=0.42..2.65 rows=1 width=12) Index Cond: (product_id = c_2.product_id) Filter: (((ordertype_id <> 2) OR (status = 999)) AND ((ordertype_id <> 3) OR (status = 999))) -> Index Scan using master_service_order_id_key on master_service_order mso (cost=0.42..0.46 rows=1 width=4) Index Cond: (id = so_1.master_service_order_id) Filter: (client_id = 11615) -> Index Scan using service_order_id_key on service_order so (cost=0.42..2.64 rows=1 width=12) Index Cond: (id = (max(so_1.id))) -> Index Scan using client_site_pkey on client_site cs (cost=0.42..0.46 rows=1 width=46) Index Cond: (id = so.a_site_id) -> Seq Scan on country csc (cost=0.00..4.50 rows=250 width=6) -> Index Scan using circuit_product_id_idx on circuit c (cost=0.42..0.49 rows=1 width=12) Index Cond: (product_id = so.product_id) -> Seq Scan on circuit_status cst (cost=0.00..1.20 rows=20 width=19) -> Seq Scan on vendor_gtt_pop (cost=0.00..21.91 rows=3 width=12) Filter: (vendor_id = 12346)
EXPLAIN_WITH_LIMIT_AND_DEFAULT_PARALLEL_PROCESSING_SETTINGS.txt (text/plain, 5.3K) download QUERY PLAN Limit (cost=253523.56..253523.57 rows=1 width=176) -> Sort (cost=253523.56..253523.57 rows=1 width=176) Sort Key: c_2.gii_circuitid, c_1.id -> Nested Loop (cost=33190.89..253523.55 rows=1 width=176) Join Filter: (c_1.id = c.id) -> Nested Loop (cost=31724.87..31736.29 rows=1 width=85) Join Filter: (c.status = cst.id) -> Nested Loop (cost=31724.87..31734.84 rows=1 width=74) -> Nested Loop Left Join (cost=31724.45..31734.35 rows=1 width=70) Join Filter: (csc.id = cs.country_id) -> Nested Loop Left Join (cost=31724.45..31726.73 rows=1 width=68) -> Nested Loop (cost=31724.02..31726.27 rows=1 width=30) -> GroupAggregate (cost=31723.60..31723.62 rows=1 width=26) Group Key: c_2.gii_circuitid -> Sort (cost=31723.60..31723.60 rows=1 width=26) Sort Key: c_2.gii_circuitid -> Gather (cost=1000.85..31723.59 rows=1 width=26) Workers Planned: 3 -> Nested Loop (cost=0.85..30723.49 rows=1 width=26) -> Nested Loop (cost=0.42..30722.56 rows=2 width=30) -> Parallel Seq Scan on circuit c_2 (cost=0.00..30714.61 rows=3 width=26) Filter: ((status >= 20) AND (status <> ALL ('{160,999}'::integer[])) AND (status <> 160) AND (service_description = 28)) -> Index Scan using so_pid_idx on service_order so_1 (cost=0.42..2.65 rows=1 width=12) Index Cond: (product_id = c_2.product_id) Filter: (((ordertype_id <> 2) OR (status = 999)) AND ((ordertype_id <> 3) OR (status = 999))) -> Index Scan using master_service_order_id_key on master_service_order mso (cost=0.42..0.46 rows=1 width=4) Index Cond: (id = so_1.master_service_order_id) Filter: (client_id = 11615) -> Index Scan using service_order_id_key on service_order so (cost=0.42..2.64 rows=1 width=12) Index Cond: (id = (max(so_1.id))) -> Index Scan using client_site_pkey on client_site cs (cost=0.42..0.46 rows=1 width=46) Index Cond: (id = so.a_site_id) -> Seq Scan on country csc (cost=0.00..4.50 rows=250 width=6) -> Index Scan using circuit_product_id_idx on circuit c (cost=0.42..0.49 rows=1 width=12) Index Cond: (product_id = so.product_id) -> Seq Scan on circuit_status cst (cost=0.00..1.20 rows=20 width=19) -> Gather (cost=1466.02..221787.23 rows=3 width=75) Workers Planned: 5 -> Hash Join (cost=466.02..220786.93 rows=1 width=75) Hash Cond: (c_1.id = vendor_gtt_pop.gtt_pop_id) -> Hash Join (cost=444.07..219779.19 rows=157724 width=63) Hash Cond: (c_1.pop_support_vendor_id = v.id) -> Merge Join (cost=5.02..217348.87 rows=157724 width=40) Merge Cond: (cl.circuit_id = c_1.id) -> Nested Loop (cost=0.86..171314.49 rows=157724 width=32) -> Parallel Index Only Scan using circuit_layout_idx on circuit_layout cl (cost=0.43..55430.93 rows=157724 width=8) Index Cond: (ordinal = 1) -> Index Scan using uniqid on segment sg (cost=0.43..0.73 rows=1 width=32) Index Cond: (id = cl.segment_id) -> Index Scan using circuit_id_key on circuit c_1 (cost=0.42..41790.58 rows=909014 width=8) -> Hash (cost=325.69..325.69 rows=9069 width=27) -> Seq Scan on vendor v (cost=0.00..325.69 rows=9069 width=27) -> Hash (cost=21.91..21.91 rows=3 width=12) -> Seq Scan on vendor_gtt_pop (cost=0.00..21.91 rows=3 width=12) Filter: (vendor_id = 12346)
every_30_seconds_top_stats_during_query.txt (text/plain, 53.5K) download top - 08:39:32 up 10 days, 1:20, 5 users, load average: 3.76, 1.71, 1.52 Tasks: 1093 total, 7 running, 1086 sleeping, 0 stopped, 0 zombie Cpu(s): 0.3%us, 0.3%sy, 0.0%ni, 99.3%id, 0.2%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 132045392k total, 104390972k used, 27654420k free, 183748k buffers Swap: 131071996k total, 78604k used, 130993392k free, 47292232k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 104880 postgres 20 0 30.8g 1.9g 1.9g R 92.0 1.5 15:15.60 postmaster 111732 postgres 20 0 30.8g 476m 473m R 88.2 0.4 0:00.47 postmaster 111730 postgres 20 0 30.8g 473m 470m R 86.4 0.4 0:00.46 postmaster 111731 postgres 20 0 30.8g 476m 473m R 86.4 0.4 0:00.46 postmaster 111733 postgres 20 0 30.8g 476m 473m R 86.4 0.4 0:00.46 postmaster 111734 postgres 20 0 30.8g 476m 473m R 86.4 0.4 0:00.46 postmaster 111728 root 20 0 15824 1912 828 R 3.8 0.0 0:00.04 top 1 root 20 0 21452 968 716 S 0.0 0.0 0:04.81 init 2 root 20 0 0 0 0 S 0.0 0.0 0:02.32 kthreadd 3 root RT 0 0 0 0 S 0.0 0.0 0:08.69 migration/0 4 root 20 0 0 0 0 S 0.0 0.0 0:03.83 ksoftirqd/0 5 root RT 0 0 0 0 S 0.0 0.0 0:00.00 stopper/0 6 root RT 0 0 0 0 S 0.0 0.0 0:00.60 watchdog/0 top - 08:40:06 up 10 days, 1:21, 5 users, load average: 3.93, 1.94, 1.60 Tasks: 1094 total, 7 running, 1087 sleeping, 0 stopped, 0 zombie Cpu(s): 0.3%us, 0.3%sy, 0.0%ni, 99.3%id, 0.2%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 132045392k total, 104394028k used, 27651364k free, 183804k buffers Swap: 131071996k total, 78604k used, 130993392k free, 47292252k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 104880 postgres 20 0 30.8g 1.9g 1.9g R 95.9 1.5 15:48.48 postmaster 111926 postgres 20 0 30.8g 623m 620m R 95.9 0.5 0:00.65 postmaster 111927 postgres 20 0 30.8g 637m 634m R 95.9 0.5 0:00.65 postmaster 111928 postgres 20 0 30.8g 628m 625m R 95.9 0.5 0:00.65 postmaster 111930 postgres 20 0 30.8g 627m 624m R 95.9 0.5 0:00.65 postmaster 111929 postgres 20 0 30.8g 639m 636m R 94.1 0.5 0:00.65 postmaster 111933 root 20 0 15824 1912 828 R 3.7 0.0 0:00.05 top 1 root 20 0 21452 968 716 S 0.0 0.0 0:04.81 init 2 root 20 0 0 0 0 S 0.0 0.0 0:02.32 kthreadd 3 root RT 0 0 0 0 S 0.0 0.0 0:08.69 migration/0 4 root 20 0 0 0 0 S 0.0 0.0 0:03.83 ksoftirqd/0 5 root RT 0 0 0 0 S 0.0 0.0 0:00.00 stopper/0 6 root RT 0 0 0 0 S 0.0 0.0 0:00.60 watchdog/0 top - 08:40:39 up 10 days, 1:21, 5 users, load average: 4.07, 2.20, 1.70 Tasks: 1094 total, 7 running, 1087 sleeping, 0 stopped, 0 zombie Cpu(s): 0.3%us, 0.3%sy, 0.0%ni, 99.3%id, 0.2%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 132045392k total, 104398256k used, 27647136k free, 183844k buffers Swap: 131071996k total, 78604k used, 130993392k free, 47292256k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 112149 postgres 20 0 30.8g 828m 825m R 100.0 0.6 0:00.87 postmaster 112150 postgres 20 0 30.8g 833m 830m R 100.0 0.6 0:00.87 postmaster 112151 postgres 20 0 30.8g 820m 817m R 100.0 0.6 0:00.87 postmaster 112152 postgres 20 0 30.8g 839m 836m R 100.0 0.7 0:00.87 postmaster 112153 postgres 20 0 30.8g 818m 815m R 100.0 0.6 0:00.87 postmaster 104880 postgres 20 0 30.8g 1.9g 1.9g R 98.1 1.5 16:21.32 postmaster 112155 root 20 0 15824 1912 828 R 1.9 0.0 0:00.02 top 1 root 20 0 21452 968 716 S 0.0 0.0 0:04.81 init 2 root 20 0 0 0 0 S 0.0 0.0 0:02.32 kthreadd 3 root RT 0 0 0 0 S 0.0 0.0 0:08.69 migration/0 4 root 20 0 0 0 0 S 0.0 0.0 0:03.83 ksoftirqd/0 5 root RT 0 0 0 0 S 0.0 0.0 0:00.00 stopper/0 6 root RT 0 0 0 0 S 0.0 0.0 0:00.60 watchdog/0 top - 08:41:13 up 10 days, 1:22, 5 users, load average: 4.38, 2.48, 1.81 Tasks: 1094 total, 7 running, 1087 sleeping, 0 stopped, 0 zombie Cpu(s): 0.3%us, 0.3%sy, 0.0%ni, 99.3%id, 0.2%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 132045392k total, 104384600k used, 27660792k free, 183876k buffers Swap: 131071996k total, 78604k used, 130993392k free, 47292256k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 104880 postgres 20 0 30.8g 1.9g 1.9g R 94.6 1.5 16:54.15 postmaster 112342 postgres 20 0 30.8g 312m 309m R 59.8 0.2 0:00.31 postmaster 112344 postgres 20 0 30.8g 312m 309m R 59.8 0.2 0:00.31 postmaster 112346 postgres 20 0 30.8g 316m 313m R 59.8 0.2 0:00.31 postmaster 112343 postgres 20 0 30.8g 313m 310m R 57.9 0.2 0:00.30 postmaster 112345 postgres 20 0 30.8g 313m 310m R 57.9 0.2 0:00.30 postmaster 112340 root 20 0 15824 1912 828 R 3.9 0.0 0:00.03 top 1 root 20 0 21452 968 716 S 0.0 0.0 0:04.81 init 2 root 20 0 0 0 0 S 0.0 0.0 0:02.32 kthreadd 3 root RT 0 0 0 0 S 0.0 0.0 0:08.69 migration/0 4 root 20 0 0 0 0 S 0.0 0.0 0:03.83 ksoftirqd/0 5 root RT 0 0 0 0 S 0.0 0.0 0:00.00 stopper/0 6 root RT 0 0 0 0 S 0.0 0.0 0:00.60 watchdog/0 top - 08:41:46 up 10 days, 1:22, 5 users, load average: 4.74, 2.77, 1.93 Tasks: 1094 total, 7 running, 1087 sleeping, 0 stopped, 0 zombie Cpu(s): 0.3%us, 0.3%sy, 0.0%ni, 99.3%id, 0.2%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 132045392k total, 104394528k used, 27650864k free, 183892k buffers Swap: 131071996k total, 78604k used, 130993392k free, 47292260k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 104880 postgres 20 0 30.8g 1.9g 1.9g R 100.0 1.5 17:27.00 postmaster 112528 postgres 20 0 30.8g 730m 727m R 100.0 0.6 0:00.73 postmaster 112529 postgres 20 0 30.8g 713m 710m R 100.0 0.6 0:00.73 postmaster 112525 postgres 20 0 30.8g 726m 723m R 98.2 0.6 0:00.73 postmaster 112526 postgres 20 0 30.8g 723m 720m R 98.2 0.6 0:00.73 postmaster 112527 postgres 20 0 30.8g 716m 713m R 98.2 0.6 0:00.73 postmaster 112531 root 20 0 15824 1912 828 R 1.9 0.0 0:00.02 top 1 root 20 0 21452 968 716 S 0.0 0.0 0:04.81 init 2 root 20 0 0 0 0 S 0.0 0.0 0:02.32 kthreadd 3 root RT 0 0 0 0 S 0.0 0.0 0:08.69 migration/0 4 root 20 0 0 0 0 S 0.0 0.0 0:03.83 ksoftirqd/0 5 root RT 0 0 0 0 S 0.0 0.0 0:00.00 stopper/0 6 root RT 0 0 0 0 S 0.0 0.0 0:00.60 watchdog/0 top - 08:42:20 up 10 days, 1:23, 5 users, load average: 4.60, 2.92, 2.01 Tasks: 1094 total, 7 running, 1087 sleeping, 0 stopped, 0 zombie Cpu(s): 0.3%us, 0.3%sy, 0.0%ni, 99.3%id, 0.2%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 132045392k total, 104380752k used, 27664640k free, 183916k buffers Swap: 131071996k total, 78604k used, 130993392k free, 47292260k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 104880 postgres 20 0 30.8g 1.9g 1.9g R 96.5 1.5 17:59.83 postmaster 112718 postgres 20 0 30.8g 166m 163m R 38.6 0.1 0:00.20 postmaster 112719 postgres 20 0 30.8g 166m 163m R 38.6 0.1 0:00.20 postmaster 112720 postgres 20 0 30.8g 167m 164m R 38.6 0.1 0:00.20 postmaster 112721 postgres 20 0 30.8g 168m 165m R 38.6 0.1 0:00.20 postmaster 112722 postgres 20 0 30.8g 166m 163m R 38.6 0.1 0:00.20 postmaster 112716 root 20 0 15824 1912 828 R 1.9 0.0 0:00.02 top 1 root 20 0 21452 968 716 S 0.0 0.0 0:04.81 init 2 root 20 0 0 0 0 S 0.0 0.0 0:02.32 kthreadd 3 root RT 0 0 0 0 S 0.0 0.0 0:08.69 migration/0 4 root 20 0 0 0 0 S 0.0 0.0 0:03.83 ksoftirqd/0 5 root RT 0 0 0 0 S 0.0 0.0 0:00.00 stopper/0 6 root RT 0 0 0 0 S 0.0 0.0 0:00.61 watchdog/0 top - 08:42:54 up 10 days, 1:24, 5 users, load average: 4.71, 3.13, 2.11 Tasks: 1094 total, 7 running, 1087 sleeping, 0 stopped, 0 zombie Cpu(s): 0.3%us, 0.3%sy, 0.0%ni, 99.3%id, 0.2%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 132045392k total, 104390956k used, 27654436k free, 183948k buffers Swap: 131071996k total, 78604k used, 130993392k free, 47292264k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 104880 postgres 20 0 30.8g 1.9g 1.9g R 100.0 1.5 18:32.67 postmaster 112902 postgres 20 0 30.8g 577m 574m R 100.0 0.4 0:00.57 postmaster 112904 postgres 20 0 30.8g 573m 570m R 100.0 0.4 0:00.57 postmaster 112905 postgres 20 0 30.8g 578m 575m R 100.0 0.4 0:00.58 postmaster 112906 postgres 20 0 30.8g 572m 569m R 100.0 0.4 0:00.57 postmaster 112903 postgres 20 0 30.8g 577m 574m R 98.3 0.4 0:00.57 postmaster 112908 root 20 0 15824 1912 828 R 1.9 0.0 0:00.02 top 1 root 20 0 21452 968 716 S 0.0 0.0 0:04.81 init 2 root 20 0 0 0 0 S 0.0 0.0 0:02.32 kthreadd 3 root RT 0 0 0 0 S 0.0 0.0 0:08.69 migration/0 4 root 20 0 0 0 0 S 0.0 0.0 0:03.83 ksoftirqd/0 5 root RT 0 0 0 0 S 0.0 0.0 0:00.00 stopper/0 6 root RT 0 0 0 0 S 0.0 0.0 0:00.61 watchdog/0 top - 08:43:27 up 10 days, 1:24, 5 users, load average: 5.09, 3.40, 2.24 Tasks: 1095 total, 7 running, 1087 sleeping, 0 stopped, 1 zombie Cpu(s): 0.3%us, 0.3%sy, 0.0%ni, 99.3%id, 0.2%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 132045392k total, 104383828k used, 27661564k free, 183980k buffers Swap: 131071996k total, 78604k used, 130993392k free, 47292268k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 104880 postgres 20 0 30.8g 1.9g 1.9g R 91.4 1.5 19:05.55 postmaster 113186 postgres 20 0 30.8g 42m 39m R 7.3 0.0 0:00.04 postmaster 113188 postgres 20 0 30.8g 43m 40m R 7.3 0.0 0:00.04 postmaster 113185 postgres 20 0 30.8g 42m 39m R 5.5 0.0 0:00.03 postmaster 113187 postgres 20 0 30.8g 42m 39m R 5.5 0.0 0:00.03 postmaster 113189 postgres 20 0 30.8g 42m 39m R 5.5 0.0 0:00.03 postmaster 113183 root 20 0 15824 1912 828 R 3.7 0.0 0:00.06 top 1 root 20 0 21452 968 716 S 0.0 0.0 0:04.81 init 2 root 20 0 0 0 0 S 0.0 0.0 0:02.32 kthreadd 3 root RT 0 0 0 0 S 0.0 0.0 0:08.69 migration/0 4 root 20 0 0 0 0 S 0.0 0.0 0:03.83 ksoftirqd/0 5 root RT 0 0 0 0 S 0.0 0.0 0:00.00 stopper/0 6 root RT 0 0 0 0 S 0.0 0.0 0:00.61 watchdog/0 top - 08:44:01 up 10 days, 1:25, 5 users, load average: 4.97, 3.53, 2.32 Tasks: 1094 total, 7 running, 1087 sleeping, 0 stopped, 0 zombie Cpu(s): 0.3%us, 0.3%sy, 0.0%ni, 99.3%id, 0.2%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 132045392k total, 104390796k used, 27654596k free, 184068k buffers Swap: 131071996k total, 78604k used, 130993392k free, 47292272k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 104880 postgres 20 0 30.8g 1.9g 1.9g R 94.2 1.5 19:38.42 postmaster 113408 postgres 20 0 30.8g 351m 348m R 62.2 0.3 0:00.33 postmaster 113409 postgres 20 0 30.8g 353m 350m R 62.2 0.3 0:00.33 postmaster 113410 postgres 20 0 30.8g 351m 348m R 62.2 0.3 0:00.33 postmaster 113411 postgres 20 0 30.8g 354m 351m R 62.2 0.3 0:00.33 postmaster 113412 postgres 20 0 30.8g 351m 348m R 62.2 0.3 0:00.33 postmaster 113406 root 20 0 15824 1916 828 R 3.8 0.0 0:00.04 top 1 root 20 0 21452 968 716 S 0.0 0.0 0:04.81 init 2 root 20 0 0 0 0 S 0.0 0.0 0:02.32 kthreadd 3 root RT 0 0 0 0 S 0.0 0.0 0:08.69 migration/0 4 root 20 0 0 0 0 S 0.0 0.0 0:03.83 ksoftirqd/0 5 root RT 0 0 0 0 S 0.0 0.0 0:00.00 stopper/0 6 root RT 0 0 0 0 S 0.0 0.0 0:00.61 watchdog/0 top - 08:44:34 up 10 days, 1:25, 5 users, load average: 4.89, 3.68, 2.41 Tasks: 1094 total, 7 running, 1087 sleeping, 0 stopped, 0 zombie Cpu(s): 0.3%us, 0.3%sy, 0.0%ni, 99.3%id, 0.2%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 132045392k total, 104395992k used, 27649400k free, 184116k buffers Swap: 131071996k total, 78604k used, 130993392k free, 47292276k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 104880 postgres 20 0 30.8g 1.9g 1.9g R 100.0 1.5 20:11.26 postmaster 113636 postgres 20 0 30.8g 679m 676m R 100.0 0.5 0:00.69 postmaster 113637 postgres 20 0 30.8g 675m 672m R 100.0 0.5 0:00.69 postmaster 113638 postgres 20 0 30.8g 685m 682m R 100.0 0.5 0:00.69 postmaster 113639 postgres 20 0 30.8g 673m 670m R 100.0 0.5 0:00.69 postmaster 113635 postgres 20 0 30.8g 678m 675m R 98.4 0.5 0:00.68 postmaster 113641 root 20 0 15824 1916 828 R 3.9 0.0 0:00.03 top 1 root 20 0 21452 968 716 S 0.0 0.0 0:04.81 init 2 root 20 0 0 0 0 S 0.0 0.0 0:02.32 kthreadd 3 root RT 0 0 0 0 S 0.0 0.0 0:08.69 migration/0 4 root 20 0 0 0 0 S 0.0 0.0 0:03.83 ksoftirqd/0 5 root RT 0 0 0 0 S 0.0 0.0 0:00.00 stopper/0 6 root RT 0 0 0 0 S 0.0 0.0 0:00.61 watchdog/0 top - 08:45:08 up 10 days, 1:26, 5 users, load average: 4.93, 3.82, 2.50 Tasks: 1094 total, 7 running, 1087 sleeping, 0 stopped, 0 zombie Cpu(s): 0.3%us, 0.3%sy, 0.0%ni, 99.3%id, 0.2%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 132045392k total, 104384252k used, 27661140k free, 184156k buffers Swap: 131071996k total, 78604k used, 130993392k free, 47292276k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 104880 postgres 20 0 30.8g 1.9g 1.9g R 92.8 1.5 20:44.11 postmaster 113837 postgres 20 0 30.8g 110m 107m R 26.0 0.1 0:00.14 postmaster 113838 postgres 20 0 30.8g 110m 107m R 26.0 0.1 0:00.14 postmaster 113839 postgres 20 0 30.8g 110m 107m R 26.0 0.1 0:00.14 postmaster 113840 postgres 20 0 30.8g 111m 108m R 26.0 0.1 0:00.14 postmaster 113841 postgres 20 0 30.8g 110m 107m R 26.0 0.1 0:00.14 postmaster 113835 root 20 0 15824 1912 828 R 3.7 0.0 0:00.04 top 159 root RT 0 0 0 0 S 1.9 0.0 0:01.10 migration/39 1 root 20 0 21452 968 716 S 0.0 0.0 0:04.81 init 2 root 20 0 0 0 0 S 0.0 0.0 0:02.32 kthreadd 3 root RT 0 0 0 0 S 0.0 0.0 0:08.69 migration/0 4 root 20 0 0 0 0 S 0.0 0.0 0:03.83 ksoftirqd/0 5 root RT 0 0 0 0 S 0.0 0.0 0:00.00 stopper/0 top - 08:45:41 up 10 days, 1:26, 5 users, load average: 4.71, 3.87, 2.57 Tasks: 1094 total, 7 running, 1087 sleeping, 0 stopped, 0 zombie Cpu(s): 0.3%us, 0.3%sy, 0.0%ni, 99.3%id, 0.2%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 132045392k total, 104393228k used, 27652164k free, 184196k buffers Swap: 131071996k total, 78604k used, 130993392k free, 47292276k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 104880 postgres 20 0 30.8g 1.9g 1.9g R 96.1 1.5 21:16.96 postmaster 114061 postgres 20 0 30.8g 486m 483m R 90.3 0.4 0:00.47 postmaster 114062 postgres 20 0 30.8g 490m 487m R 90.3 0.4 0:00.47 postmaster 114059 postgres 20 0 30.8g 488m 485m R 88.4 0.4 0:00.46 postmaster 114060 postgres 20 0 30.8g 490m 487m R 88.4 0.4 0:00.46 postmaster 114063 postgres 20 0 30.8g 485m 482m R 88.4 0.4 0:00.46 postmaster 114057 root 20 0 15824 1912 828 R 1.9 0.0 0:00.02 top 1 root 20 0 21452 968 716 S 0.0 0.0 0:04.81 init 2 root 20 0 0 0 0 S 0.0 0.0 0:02.32 kthreadd 3 root RT 0 0 0 0 S 0.0 0.0 0:08.69 migration/0 4 root 20 0 0 0 0 S 0.0 0.0 0:03.83 ksoftirqd/0 5 root RT 0 0 0 0 S 0.0 0.0 0:00.00 stopper/0 6 root RT 0 0 0 0 S 0.0 0.0 0:00.61 watchdog/0 top - 08:46:15 up 10 days, 1:27, 5 users, load average: 4.85, 3.98, 2.64 Tasks: 1094 total, 7 running, 1087 sleeping, 0 stopped, 0 zombie Cpu(s): 0.3%us, 0.3%sy, 0.0%ni, 99.3%id, 0.2%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 132045392k total, 104396216k used, 27649176k free, 184220k buffers Swap: 131071996k total, 78604k used, 130993392k free, 47292280k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 104880 postgres 20 0 30.8g 1.9g 1.9g R 99.6 1.5 21:49.81 postmaster 114242 postgres 20 0 30.8g 674m 671m R 99.6 0.5 0:00.69 postmaster 114243 postgres 20 0 30.8g 663m 660m R 99.6 0.5 0:00.69 postmaster 114244 postgres 20 0 30.8g 679m 676m R 99.6 0.5 0:00.69 postmaster 114245 postgres 20 0 30.8g 662m 659m R 99.6 0.5 0:00.69 postmaster 114241 postgres 20 0 30.8g 673m 670m R 97.6 0.5 0:00.68 postmaster 114247 root 20 0 15824 1912 828 R 3.8 0.0 0:00.03 top 1 root 20 0 21452 968 716 S 0.0 0.0 0:04.81 init 2 root 20 0 0 0 0 S 0.0 0.0 0:02.32 kthreadd 3 root RT 0 0 0 0 S 0.0 0.0 0:08.69 migration/0 4 root 20 0 0 0 0 S 0.0 0.0 0:03.83 ksoftirqd/0 5 root RT 0 0 0 0 S 0.0 0.0 0:00.00 stopper/0 6 root RT 0 0 0 0 S 0.0 0.0 0:00.61 watchdog/0 top - 08:46:49 up 10 days, 1:27, 5 users, load average: 4.86, 4.08, 2.72 Tasks: 1094 total, 7 running, 1087 sleeping, 0 stopped, 0 zombie Cpu(s): 0.3%us, 0.3%sy, 0.0%ni, 99.2%id, 0.2%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 132045392k total, 104383260k used, 27662132k free, 184236k buffers Swap: 131071996k total, 78604k used, 130993392k free, 47292284k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 104880 postgres 20 0 30.8g 1.9g 1.9g R 96.4 1.5 22:22.64 postmaster 114436 postgres 20 0 30.8g 76m 73m R 15.4 0.1 0:00.08 postmaster 114438 postgres 20 0 30.8g 74m 71m R 15.4 0.1 0:00.08 postmaster 114440 postgres 20 0 30.8g 75m 72m R 15.4 0.1 0:00.08 postmaster 114437 postgres 20 0 30.8g 75m 72m R 13.5 0.1 0:00.07 postmaster 114439 postgres 20 0 30.8g 76m 73m R 13.5 0.1 0:00.07 postmaster 114434 root 20 0 15824 1916 828 R 1.9 0.0 0:00.02 top 1 root 20 0 21452 968 716 S 0.0 0.0 0:04.81 init 2 root 20 0 0 0 0 S 0.0 0.0 0:02.32 kthreadd 3 root RT 0 0 0 0 S 0.0 0.0 0:08.69 migration/0 4 root 20 0 0 0 0 S 0.0 0.0 0:03.83 ksoftirqd/0 5 root RT 0 0 0 0 S 0.0 0.0 0:00.00 stopper/0 6 root RT 0 0 0 0 S 0.0 0.0 0:00.61 watchdog/0 top - 08:47:22 up 10 days, 1:28, 5 users, load average: 4.63, 4.10, 2.78 Tasks: 1094 total, 7 running, 1087 sleeping, 0 stopped, 0 zombie Cpu(s): 0.3%us, 0.3%sy, 0.0%ni, 99.2%id, 0.2%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 132045392k total, 104393024k used, 27652368k free, 184268k buffers Swap: 131071996k total, 78604k used, 130993392k free, 47292288k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 104880 postgres 20 0 30.8g 1.9g 1.9g R 96.3 1.5 22:55.49 postmaster 114621 postgres 20 0 30.8g 476m 473m R 88.6 0.4 0:00.46 postmaster 114622 postgres 20 0 30.8g 473m 470m R 88.6 0.4 0:00.46 postmaster 114620 postgres 20 0 30.8g 476m 473m R 86.7 0.4 0:00.45 postmaster 114623 postgres 20 0 30.8g 479m 476m R 86.7 0.4 0:00.45 postmaster 114624 postgres 20 0 30.8g 476m 473m R 86.7 0.4 0:00.45 postmaster 114618 root 20 0 15824 1912 828 R 1.9 0.0 0:00.02 top 1 root 20 0 21452 968 716 S 0.0 0.0 0:04.81 init 2 root 20 0 0 0 0 S 0.0 0.0 0:02.32 kthreadd 3 root RT 0 0 0 0 S 0.0 0.0 0:08.69 migration/0 4 root 20 0 0 0 0 S 0.0 0.0 0:03.83 ksoftirqd/0 5 root RT 0 0 0 0 S 0.0 0.0 0:00.00 stopper/0 6 root RT 0 0 0 0 S 0.0 0.0 0:00.61 watchdog/0 top - 08:47:56 up 10 days, 1:29, 5 users, load average: 4.62, 4.15, 2.84 Tasks: 1094 total, 7 running, 1087 sleeping, 0 stopped, 0 zombie Cpu(s): 0.3%us, 0.3%sy, 0.0%ni, 99.2%id, 0.2%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 132045392k total, 104400644k used, 27644748k free, 184300k buffers Swap: 131071996k total, 78604k used, 130993392k free, 47292288k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 114804 postgres 20 0 30.8g 785m 782m R 100.0 0.6 0:00.81 postmaster 114805 postgres 20 0 30.8g 784m 781m R 100.0 0.6 0:00.81 postmaster 114807 postgres 20 0 30.8g 795m 792m R 100.0 0.6 0:00.81 postmaster 104880 postgres 20 0 30.8g 1.9g 1.9g R 98.4 1.5 23:28.33 postmaster 114806 postgres 20 0 30.8g 763m 760m R 98.4 0.6 0:00.80 postmaster 114808 postgres 20 0 30.8g 768m 765m R 98.4 0.6 0:00.80 postmaster 114810 root 20 0 15824 1912 828 R 1.9 0.0 0:00.02 top 1 root 20 0 21452 968 716 S 0.0 0.0 0:04.81 init 2 root 20 0 0 0 0 S 0.0 0.0 0:02.32 kthreadd 3 root RT 0 0 0 0 S 0.0 0.0 0:08.69 migration/0 4 root 20 0 0 0 0 S 0.0 0.0 0:03.83 ksoftirqd/0 5 root RT 0 0 0 0 S 0.0 0.0 0:00.00 stopper/0 6 root RT 0 0 0 0 S 0.0 0.0 0:00.61 watchdog/0 top - 08:48:29 up 10 days, 1:29, 5 users, load average: 4.52, 4.19, 2.90 Tasks: 1094 total, 7 running, 1087 sleeping, 0 stopped, 0 zombie Cpu(s): 0.3%us, 0.3%sy, 0.0%ni, 99.2%id, 0.2%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 132045392k total, 104388648k used, 27656744k free, 184324k buffers Swap: 131071996k total, 78604k used, 130993392k free, 47292292k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 104880 postgres 20 0 30.8g 1.9g 1.9g R 96.3 1.5 24:01.16 postmaster 115008 postgres 20 0 30.8g 160m 157m R 38.5 0.1 0:00.20 postmaster 115009 postgres 20 0 30.8g 161m 158m R 38.5 0.1 0:00.20 postmaster 115010 postgres 20 0 30.8g 159m 156m R 36.6 0.1 0:00.19 postmaster 115011 postgres 20 0 30.8g 161m 158m R 36.6 0.1 0:00.19 postmaster 115012 postgres 20 0 30.8g 160m 157m R 36.6 0.1 0:00.19 postmaster 115006 root 20 0 15824 1916 828 R 1.9 0.0 0:00.02 top 1 root 20 0 21452 968 716 S 0.0 0.0 0:04.81 init 2 root 20 0 0 0 0 S 0.0 0.0 0:02.32 kthreadd 3 root RT 0 0 0 0 S 0.0 0.0 0:08.69 migration/0 4 root 20 0 0 0 0 S 0.0 0.0 0:03.83 ksoftirqd/0 5 root RT 0 0 0 0 S 0.0 0.0 0:00.00 stopper/0 6 root RT 0 0 0 0 S 0.0 0.0 0:00.61 watchdog/0 top - 08:49:03 up 10 days, 1:30, 5 users, load average: 4.33, 4.18, 2.94 Tasks: 1094 total, 7 running, 1087 sleeping, 0 stopped, 0 zombie Cpu(s): 0.3%us, 0.3%sy, 0.0%ni, 99.2%id, 0.2%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 132045392k total, 104397400k used, 27647992k free, 184444k buffers Swap: 131071996k total, 78604k used, 130993392k free, 47292296k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 115298 postgres 20 0 30.8g 542m 539m R 99.2 0.4 0:00.53 postmaster 115299 postgres 20 0 30.8g 537m 534m R 99.2 0.4 0:00.53 postmaster 115300 postgres 20 0 30.8g 543m 540m R 99.2 0.4 0:00.53 postmaster 115301 postgres 20 0 30.8g 546m 543m R 99.2 0.4 0:00.53 postmaster 115302 postgres 20 0 30.8g 537m 534m R 99.2 0.4 0:00.53 postmaster 104880 postgres 20 0 30.8g 1.9g 1.9g R 97.3 1.5 24:34.06 postmaster 115296 root 20 0 15824 1900 828 R 3.7 0.0 0:00.04 top 177 root 20 0 0 0 0 S 1.9 0.0 0:00.16 ksoftirqd/43 1 root 20 0 21452 968 716 S 0.0 0.0 0:04.81 init 2 root 20 0 0 0 0 S 0.0 0.0 0:02.32 kthreadd 3 root RT 0 0 0 0 S 0.0 0.0 0:08.69 migration/0 4 root 20 0 0 0 0 S 0.0 0.0 0:03.83 ksoftirqd/0 5 root RT 0 0 0 0 S 0.0 0.0 0:00.00 stopper/0 top - 08:49:36 up 10 days, 1:30, 5 users, load average: 4.55, 4.26, 3.01 Tasks: 1094 total, 6 running, 1088 sleeping, 0 stopped, 0 zombie Cpu(s): 0.3%us, 0.3%sy, 0.0%ni, 99.2%id, 0.2%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 132045392k total, 104394916k used, 27650476k free, 184492k buffers Swap: 131071996k total, 78604k used, 130993392k free, 47292304k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 115525 postgres 20 0 0 0 0 R 100.0 0.0 0:00.90 postmaster 115526 postgres 20 0 0 0 0 R 100.0 0.0 0:00.90 postmaster 104880 postgres 20 0 30.8g 1.9g 1.9g S 98.3 1.5 25:06.90 postmaster 115527 postgres 20 0 0 0 0 R 98.3 0.0 0:00.90 postmaster 115528 postgres 20 0 0 0 0 R 98.3 0.0 0:00.90 postmaster 115529 postgres 20 0 0 0 0 R 98.3 0.0 0:00.90 postmaster 115531 root 20 0 15824 1912 828 R 3.9 0.0 0:00.03 top 1 root 20 0 21452 968 716 S 0.0 0.0 0:04.81 init 2 root 20 0 0 0 0 S 0.0 0.0 0:02.32 kthreadd 3 root RT 0 0 0 0 S 0.0 0.0 0:08.69 migration/0 4 root 20 0 0 0 0 S 0.0 0.0 0:03.83 ksoftirqd/0 5 root RT 0 0 0 0 S 0.0 0.0 0:00.00 stopper/0 6 root RT 0 0 0 0 S 0.0 0.0 0:00.61 watchdog/0 top - 08:50:10 up 10 days, 1:31, 5 users, load average: 4.58, 4.28, 3.06 Tasks: 1094 total, 7 running, 1087 sleeping, 0 stopped, 0 zombie Cpu(s): 0.3%us, 0.3%sy, 0.0%ni, 99.2%id, 0.2%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 132045392k total, 104393904k used, 27651488k free, 184548k buffers Swap: 131071996k total, 78604k used, 130993392k free, 47292312k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 104880 postgres 20 0 30.8g 1.9g 1.9g R 89.1 1.5 25:39.78 postmaster 115732 postgres 20 0 30.8g 345m 342m R 58.8 0.3 0:00.33 postmaster 115733 postgres 20 0 30.8g 345m 342m R 58.8 0.3 0:00.33 postmaster 115734 postgres 20 0 30.8g 344m 341m R 58.8 0.3 0:00.33 postmaster 115735 postgres 20 0 30.8g 345m 342m R 58.8 0.3 0:00.33 postmaster 115736 postgres 20 0 30.8g 343m 340m R 58.8 0.3 0:00.33 postmaster 115730 root 20 0 15824 1916 828 R 3.6 0.0 0:00.07 top 1 root 20 0 21452 968 716 S 0.0 0.0 0:04.81 init 2 root 20 0 0 0 0 S 0.0 0.0 0:02.32 kthreadd 3 root RT 0 0 0 0 S 0.0 0.0 0:08.69 migration/0 4 root 20 0 0 0 0 S 0.0 0.0 0:03.83 ksoftirqd/0 5 root RT 0 0 0 0 S 0.0 0.0 0:00.00 stopper/0 6 root RT 0 0 0 0 S 0.0 0.0 0:00.61 watchdog/0 top - 08:50:44 up 10 days, 1:31, 5 users, load average: 4.12, 4.21, 3.08 Tasks: 1094 total, 7 running, 1087 sleeping, 0 stopped, 0 zombie Cpu(s): 0.3%us, 0.3%sy, 0.0%ni, 99.2%id, 0.2%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 132045392k total, 104402516k used, 27642876k free, 184596k buffers Swap: 131071996k total, 78604k used, 130993392k free, 47292316k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 104880 postgres 20 0 30.8g 1.9g 1.9g R 100.0 1.5 26:12.64 postmaster 115948 postgres 20 0 30.8g 665m 662m R 100.0 0.5 0:00.68 postmaster 115950 postgres 20 0 30.8g 660m 657m R 100.0 0.5 0:00.68 postmaster 115951 postgres 20 0 30.8g 664m 661m R 100.0 0.5 0:00.68 postmaster 115952 postgres 20 0 30.8g 655m 652m R 100.0 0.5 0:00.68 postmaster 115949 postgres 20 0 30.8g 667m 664m R 98.2 0.5 0:00.67 postmaster 115954 root 20 0 15824 1916 828 R 1.9 0.0 0:00.02 top 1 root 20 0 21452 968 716 S 0.0 0.0 0:04.81 init 2 root 20 0 0 0 0 S 0.0 0.0 0:02.32 kthreadd 3 root RT 0 0 0 0 S 0.0 0.0 0:08.69 migration/0 4 root 20 0 0 0 0 S 0.0 0.0 0:03.83 ksoftirqd/0 5 root RT 0 0 0 0 S 0.0 0.0 0:00.00 stopper/0 6 root RT 0 0 0 0 S 0.0 0.0 0:00.61 watchdog/0 top - 08:51:17 up 10 days, 1:32, 5 users, load average: 4.10, 4.20, 3.12 Tasks: 1094 total, 7 running, 1087 sleeping, 0 stopped, 0 zombie Cpu(s): 0.3%us, 0.3%sy, 0.0%ni, 99.2%id, 0.2%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 132045392k total, 104388628k used, 27656764k free, 184628k buffers Swap: 131071996k total, 78604k used, 130993392k free, 47292312k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 104880 postgres 20 0 30.8g 1.9g 1.9g R 96.3 1.5 26:45.47 postmaster 116145 postgres 20 0 30.8g 65m 62m R 13.5 0.1 0:00.07 postmaster 116147 postgres 20 0 30.8g 64m 61m R 13.5 0.1 0:00.07 postmaster 116144 postgres 20 0 30.8g 65m 62m R 11.6 0.1 0:00.06 postmaster 116146 postgres 20 0 30.8g 64m 61m R 11.6 0.1 0:00.06 postmaster 116148 postgres 20 0 30.8g 64m 61m R 11.6 0.1 0:00.06 postmaster 116142 root 20 0 15824 1912 828 R 3.9 0.0 0:00.03 top 1 root 20 0 21452 968 716 S 0.0 0.0 0:04.81 init 2 root 20 0 0 0 0 S 0.0 0.0 0:02.32 kthreadd 3 root RT 0 0 0 0 S 0.0 0.0 0:08.69 migration/0 4 root 20 0 0 0 0 S 0.0 0.0 0:03.83 ksoftirqd/0 5 root RT 0 0 0 0 S 0.0 0.0 0:00.00 stopper/0 6 root RT 0 0 0 0 S 0.0 0.0 0:00.61 watchdog/0 top - 08:51:51 up 10 days, 1:32, 5 users, load average: 4.77, 4.36, 3.20 Tasks: 1094 total, 7 running, 1087 sleeping, 0 stopped, 0 zombie Cpu(s): 0.3%us, 0.3%sy, 0.0%ni, 99.2%id, 0.2%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 132045392k total, 104394856k used, 27650536k free, 184644k buffers Swap: 131071996k total, 78604k used, 130993392k free, 47292320k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 104880 postgres 20 0 30.8g 1.9g 1.9g R 96.3 1.5 27:18.32 postmaster 116331 postgres 20 0 30.8g 353m 350m R 65.5 0.3 0:00.34 postmaster 116333 postgres 20 0 30.8g 353m 350m R 65.5 0.3 0:00.34 postmaster 116335 postgres 20 0 30.8g 354m 351m R 65.5 0.3 0:00.34 postmaster 116332 postgres 20 0 30.8g 356m 353m R 63.5 0.3 0:00.33 postmaster 116334 postgres 20 0 30.8g 355m 352m R 63.5 0.3 0:00.33 postmaster 116329 root 20 0 15824 1912 828 R 3.9 0.0 0:00.03 top 1 root 20 0 21452 968 716 S 0.0 0.0 0:04.81 init 2 root 20 0 0 0 0 S 0.0 0.0 0:02.32 kthreadd 3 root RT 0 0 0 0 S 0.0 0.0 0:08.69 migration/0 4 root 20 0 0 0 0 S 0.0 0.0 0:03.83 ksoftirqd/0 5 root RT 0 0 0 0 S 0.0 0.0 0:00.00 stopper/0 6 root RT 0 0 0 0 S 0.0 0.0 0:00.61 watchdog/0
^ permalink raw reply [nested|flat] 12+ messages in thread

* Re: Postgresql 10.3 , query never completes if LIMIT clause is specified and paralle processing is on
@ 2018-03-22 16:00  Tomas Vondra <tomas.vondra@2ndquadrant.com>
  parent: Alessandro Aste <alessandro.aste@gmail.com>
  0 siblings, 1 reply; 12+ messages in thread

From: Tomas Vondra @ 2018-03-22 16:00 UTC (permalink / raw)
  To: Alessandro Aste <alessandro.aste@gmail.com>; +Cc: pgsql-general@lists.postgresql.org



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




^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: Postgresql 10.3 , query never completes if LIMIT clause is specified and paralle processing is on
@ 2018-03-22 22:29  Alessandro Aste <alessandro.aste@gmail.com>
  parent: Tomas Vondra <tomas.vondra@2ndquadrant.com>
  0 siblings, 1 reply; 12+ messages in thread

From: Alessandro Aste @ 2018-03-22 22:29 UTC (permalink / raw)
  To: Tomas Vondra <tomas.vondra@2ndquadrant.com>; +Cc: pgsql-general@lists.postgresql.org

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?

Regards,

On Thu, Mar 22, 2018 at 5:00 PM, Tomas Vondra <tomas.vondra@2ndquadrant.com>
wrote:

>
>
> 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
>

^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: Postgresql 10.3 , query never completes if LIMIT clause is specified and paralle processing is on
@ 2018-03-22 22:42  Tomas Vondra <tomas.vondra@2ndquadrant.com>
  parent: Alessandro Aste <alessandro.aste@gmail.com>
  0 siblings, 1 reply; 12+ messages in thread

From: Tomas Vondra @ 2018-03-22 22:42 UTC (permalink / raw)
  To: Alessandro Aste <alessandro.aste@gmail.com>; +Cc: pgsql-general@lists.postgresql.org

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




^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: Postgresql 10.3 , query never completes if LIMIT clause is specified and paralle processing is on
@ 2018-03-23 08:31  Alessandro Aste <alessandro.aste@gmail.com>
  parent: Tomas Vondra <tomas.vondra@2ndquadrant.com>
  0 siblings, 1 reply; 12+ messages in thread

From: Alessandro Aste @ 2018-03-23 08:31 UTC (permalink / raw)
  To: Tomas Vondra <tomas.vondra@2ndquadrant.com>; +Cc: pgsql-general@lists.postgresql.org

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 <tomas.vondra@2ndquadrant.com
> 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
>

Attachments:

  report.txt (text/plain, 4.2M) download

^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: Postgresql 10.3 , query never completes if LIMIT clause is specified and paralle processing is on
@ 2018-03-23 19:22  Alessandro Aste <alessandro.aste@gmail.com>
  parent: Alessandro Aste <alessandro.aste@gmail.com>
  0 siblings, 1 reply; 12+ messages in thread

From: Alessandro Aste @ 2018-03-23 19:22 UTC (permalink / raw)
  To: Tomas Vondra <tomas.vondra@2ndquadrant.com>; +Cc: pgsql-general@lists.postgresql.org

 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 <alessandro.aste@gmail.com>
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 <
> tomas.vondra@2ndquadrant.com> 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
>>
>
>

^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: Postgresql 10.3 , query never completes if LIMIT clause is specified and paralle processing is on
@ 2018-03-28 08:30  Alessandro Aste <alessandro.aste@gmail.com>
  parent: Alessandro Aste <alessandro.aste@gmail.com>
  0 siblings, 1 reply; 12+ messages in thread

From: Alessandro Aste @ 2018-03-28 08:30 UTC (permalink / raw)
  To: Tomas Vondra <tomas.vondra@2ndquadrant.com>; +Cc: pgsql-general@lists.postgresql.org

Hello,  any news ?

Thank you,

Alessandro.

On Fri, Mar 23, 2018 at 8:22 PM, Alessandro Aste <alessandro.aste@gmail.com>
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 <
> alessandro.aste@gmail.com> 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 <
>> tomas.vondra@2ndquadrant.com> 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
>>>
>>
>>
>

^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: Postgresql 10.3 , query never completes if LIMIT clause is specified and paralle processing is on
@ 2018-03-28 13:14  Tomas Vondra <tomas.vondra@2ndquadrant.com>
  parent: Alessandro Aste <alessandro.aste@gmail.com>
  0 siblings, 0 replies; 12+ messages in thread

From: Tomas Vondra @ 2018-03-28 13:14 UTC (permalink / raw)
  To: Alessandro Aste <alessandro.aste@gmail.com>; +Cc: pgsql-general@lists.postgresql.org

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
> <alessandro.aste@gmail.com <mailto:alessandro.aste@gmail.com>> 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
>     <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
>     <http://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 <http://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 <http://so.id; = pop.service_order_id left JOIN client_site
>     cs on cs.id <http://cs.id>=so.a_site_id left JOIN country csc on
>     csc.id <http://csc.id>=cs.country_id JOIN circuit c ON
>     so.product_id=c.product_id JOIN circuit_status cst ON cst.id
>     <http://cst.id>=c.status JOIN ( SELECT c.id <http://c.id; AS
>     circuit_id, sg.id <http://sg.id; AS segment_id,
>     c.pop_support_vendor_id AS vendor_id, v.name <http://v.name; AS
>     vendor_name, sg.a_company_name FROM segment sg JOIN circuit_layout
>     cl ON cl.segment_id = sg.id <http://sg.id; AND cl.ordinal = 1 JOIN
>     circuit c ON c.id <http://c.id; = cl.circuit_id JOIN vendor v ON
>     v.id <http://v.id; = c.pop_support_vendor_id ) seg ON seg.circuit_id
>     = c.id <http://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
>     <alessandro.aste@gmail.com <mailto:alessandro.aste@gmail.com>> 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
>         <tomas.vondra@2ndquadrant.com
>         <mailto:tomas.vondra@2ndquadrant.com>> 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




^ permalink  raw  reply  [nested|flat] 12+ messages in thread


end of thread, other threads:[~2018-03-28 13:14 UTC | newest]

Thread overview: 12+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-03-21 16:09 Postgresql 10.3 , query never completes if LIMIT clause is specified and paralle processing is on Alessandro Aste <alessandro.aste@gmail.com>
2018-03-21 19:01 ` Tomas Vondra <tomas.vondra@2ndquadrant.com>
2018-03-21 19:44   ` Alessandro Aste <alessandro.aste@gmail.com>
2018-03-22 02:04     ` Tomas Vondra <tomas.vondra@2ndquadrant.com>
2018-03-22 10:33       ` Alessandro Aste <alessandro.aste@gmail.com>
2018-03-22 16:00         ` Tomas Vondra <tomas.vondra@2ndquadrant.com>
2018-03-22 22:29           ` Alessandro Aste <alessandro.aste@gmail.com>
2018-03-22 22:42             ` Tomas Vondra <tomas.vondra@2ndquadrant.com>
2018-03-23 08:31               ` Alessandro Aste <alessandro.aste@gmail.com>
2018-03-23 19:22                 ` Alessandro Aste <alessandro.aste@gmail.com>
2018-03-28 08:30                   ` Alessandro Aste <alessandro.aste@gmail.com>
2018-03-28 13:14                     ` Tomas Vondra <tomas.vondra@2ndquadrant.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox