Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fT2HA-0007np-G4 for pgsql-hackers@arkaria.postgresql.org; Wed, 13 Jun 2018 09:41:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fT2H6-0002C2-Du for pgsql-hackers@arkaria.postgresql.org; Wed, 13 Jun 2018 09:41:08 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fT2H6-0002Bp-0d; Wed, 13 Jun 2018 09:41:08 +0000 Received: from mail-lf0-x242.google.com ([2a00:1450:4010:c07::242]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1fT2Gy-0004es-Q6; Wed, 13 Jun 2018 09:41:06 +0000 Received: by mail-lf0-x242.google.com with SMTP id v135-v6so2878175lfa.9; Wed, 13 Jun 2018 02:41:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language; bh=Bzcr0+azi5c6k+gNma/nRbcMI7pYOWtr5NxKqqaP1HI=; b=CT9mAITaOLUABjKsovE8Ndu3SY+ShJg6jQAodVVdsqfL4Ve1ae/H2DeWkeg6K9W/GC QDqZLCB5bP+oAPFrQ+FvZFCW3KZKbMOCvG46j074wC/AXGg6ldZgTOKRn2s6yR2Kv9mb 8fsdZfjUTWMhWgqJVbsDj1x61iXvt+I5drd/aqi2zw8wu08ayMtoCJVyQg5CtQz3/d3s wXRPjecq3eFDpwvCIoUxFXHqfemzCUS7qx5Ysw6290VeciqpHl5q6BTqa01Huyd5XAs9 qObLq6l6VcuOK+X6WLFU+oyLicFPhuGSIeg81LQ95XkFd2Uz9S2FyEAvoZIh8Y/Oz7L2 Sc1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=Bzcr0+azi5c6k+gNma/nRbcMI7pYOWtr5NxKqqaP1HI=; b=isgd0SYLo4I5k1YVL8NEQOaZhaWxgvGO4It5bHWPiRm8ci7Q5wMIKHyqUtVanUB5AU 1NL57A74puKKGqAMolxTVDTDe7LUkaSMcY4bE9Vk3kZzBGp9mQ7YSRnkWoLZyPXJiVTy C0jChABKmEmPsJoFa/vvS0w/i/VDy2Nt/aUHjd0sxfogko4cB2jFV26kLD1REhTL2hpn S4yLlGNkZs/3IXzCO2w/i0hmB1LfKquBGMWcw/S6vvDfAcSY9FalADj3GuXJwFNsMae4 fpkbALsrqYsKGAPzUVANZBC5LhwPLKL3y4XdoLk8vBrS797U3rdBZCi/Q6e0Eg2zxZes OuMg== X-Gm-Message-State: APt69E19wA0aICmQ6awC8SaX2QIqc4zZeL6ftk8POmtylDSw7B2hNDjK MIouBVftSDSec/a4MkEw3PeZ4Bkl X-Google-Smtp-Source: ADUXVKKEQSLxQiK3SGoa075OP0oafcnjmpcwpZQ31Z+4y7eSxYY2y0r/4clgiJYkd4cgFKaoKeAomA== X-Received: by 2002:a19:5353:: with SMTP id h80-v6mr2634904lfb.86.1528882856624; Wed, 13 Jun 2018 02:40:56 -0700 (PDT) Received: from [10.3.1.85] ([185.62.200.137]) by smtp.gmail.com with ESMTPSA id u24-v6sm463930ljj.96.2018.06.13.02.40.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Jun 2018 02:40:55 -0700 (PDT) Subject: Re: Slow planning time for simple query To: Tom Lane Cc: pgsql-general@lists.postgresql.org, pgsql-hackers@lists.postgresql.org References: <36adf760-680b-7a4a-e019-64f4eaaf6ff7@gmail.com> <9661.1528573749@sss.pgh.pa.us> From: Maksim Milyutin Message-ID: <7a5653e4-5a94-18d3-17e4-7e11ed2c9919@gmail.com> Date: Wed, 13 Jun 2018 12:40:54 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <9661.1528573749@sss.pgh.pa.us> Content-Type: multipart/alternative; boundary="------------04ECB527A7DC2EAACC9712D3" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------04ECB527A7DC2EAACC9712D3 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit On 09.06.2018 22:49, Tom Lane wrote: > Maksim Milyutin writes: >> On hot standby I faced with the similar problem. >> ... >> is planned 4.940 ms on master and *254.741* ms on standby. > > (I wonder though why, if you executed the same query on the master, > its setting of the index-entry-is-dead bits didn't propagate to the > standby.) I have verified the number dead item pointers (through pageinspect extension) in the first leaf page of index participating in query ('main.message_instance_pkey') on master and slave nodes and have noticed a big difference. SELECT * FROM monitoring.bt_page_stats('main.message_instance_pkey', 3705); On master:  blkno | type | live_items | dead_items | avg_item_size | page_size | free_size | btpo_prev | btpo_next | btpo | btpo_flags -------+------+------------+------------+---------------+-----------+-----------+-----------+-----------+------+------------   3705 | l    |          1 |         58 |            24 |      8192 |      6496 |         0 |      3719 |    0 | 65 On standby:  blkno | type | live_items | dead_items | avg_item_size | page_size | free_size | btpo_prev | btpo_next | btpo | btpo_flags -------+------+------------+------------+---------------+-----------+-----------+-----------+-----------+------+------------   3705 | l    |         59 |          0 |            24 |      8192 |      6496 |         0 |      3719 |    0 | 1 The vacuum routine improves the situation. Сan there be something that I have incorrectly configured WAL logging or replication? > I wonder if we should extend the "SnapshotNonVacuumable" logic introduced > in commit 3ca930fc3 so that in hot standby, *all* index entries are deemed > non vacuumable. This would essentially get rid of long standby planning > times in this sort of scenario by instead accepting worse (possibly much > worse) planner range estimates. I'm unsure if that's a good tradeoff or > not. I applied the patch introduced in this commit to test standby (not master; I don't know if this is correct) and haven't noticed any differences. -- Regards, Maksim Milyutin --------------04ECB527A7DC2EAACC9712D3 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit

On 09.06.2018 22:49, Tom Lane wrote:

Maksim Milyutin <milyutinma@gmail.com> writes:
On hot standby I faced with the similar problem.
...
is planned 4.940 ms on master and *254.741* ms on standby.

(I wonder though why, if you executed the same query on the master,
its setting of the index-entry-is-dead bits didn't propagate to the
standby.)

I have verified the number dead item pointers (through pageinspect extension) in the first leaf page of index participating in query ('main.message_instance_pkey') on master and slave nodes and have noticed a big difference.

SELECT * FROM monitoring.bt_page_stats('main.message_instance_pkey', 3705);

On master:

 blkno | type | live_items | dead_items | avg_item_size | page_size | free_size | btpo_prev | btpo_next | btpo | btpo_flags
-------+------+------------+------------+---------------+-----------+-----------+-----------+-----------+------+------------
  3705 | l    |          1 |         58 |            24 |      8192 |      6496 |         0 |      3719 |    0 |         65

On standby:

 blkno | type | live_items | dead_items | avg_item_size | page_size | free_size | btpo_prev | btpo_next | btpo | btpo_flags
-------+------+------------+------------+---------------+-----------+-----------+-----------+-----------+------+------------
  3705 | l    |         59 |          0 |            24 |      8192 |      6496 |         0 |      3719 |    0 |          1


The vacuum routine improves the situation.
Сan there be something that I have incorrectly configured WAL logging or replication?


I wonder if we should extend the "SnapshotNonVacuumable" logic introduced
in commit 3ca930fc3 so that in hot standby, *all* index entries are deemed
non vacuumable.  This would essentially get rid of long standby planning
times in this sort of scenario by instead accepting worse (possibly much
worse) planner range estimates.  I'm unsure if that's a good tradeoff or
not.

I applied the patch introduced in this commit to test standby (not master; I don't know if this is correct) and haven't noticed any differences.

-- 
Regards,
Maksim Milyutin
--------------04ECB527A7DC2EAACC9712D3--