Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l0ttz-0003VF-0w for pgsql-hackers@arkaria.postgresql.org; Sat, 16 Jan 2021 22:18:35 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1l0ttw-0004HZ-Tc for pgsql-hackers@arkaria.postgresql.org; Sat, 16 Jan 2021 22:18:32 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l0ttw-0004HS-Gs for pgsql-hackers@lists.postgresql.org; Sat, 16 Jan 2021 22:18:32 +0000 Received: from mail-ej1-x62a.google.com ([2a00:1450:4864:20::62a]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1l0tto-0008W4-LA for pgsql-hackers@lists.postgresql.org; Sat, 16 Jan 2021 22:18:31 +0000 Received: by mail-ej1-x62a.google.com with SMTP id g12so18440890ejf.8 for ; Sat, 16 Jan 2021 14:18:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=+wunJiUOmjvoFA46GQopQjJKVBnmR90xXQ5/s/OTbdA=; b=0MtTvEr+rvD0+InlAtKPcv7Rw/x0S7S98uK5fRBZeWO365Yvtzq5ksY/tefZwbL+9Q 3XXGbWa7Poau8YwKEou37DE7myH5uhS3eOv500SMWcdcdbPZG5AUiQTki6NVRAPbdAWC WyPUn9Phb00g0sdylKrw+XPyyk9tvvHyS3YECsTtLjMmMPel4y/gDmydrK7XSjY4BsH4 fU3Uy9T0F40Q6gybL22/C8EBHhh+3QvDsfDA9jGVtMLYKZQXzYGa+EmQlt3IvrwjXzoR m66yPMPkt/KyGgMFDik2+frnYOQv+CPKENQs7EiCNvE09+16NXS/+SQXCHMd20ZgmPgV Musg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=+wunJiUOmjvoFA46GQopQjJKVBnmR90xXQ5/s/OTbdA=; b=JFGGGUb1hLPaPpHTqkD642ffw6S/qMMpO9hXN6vhZEy9FOkGBrUtoK2c8/COFRO7tL +q2VWPuiAolnDqSYLnu6Iaky1VfIG2QiAuCXRC16scT3G1uugQePwh174JhxAqsaKueM 4mseHU4K0xoRuOaOzNo9+nSdTdbycw+B9o4JlzSkMJXdT3PqZHNdjerimbsM3qbRokC4 7XMYOM9Lvh6HnmVMAqzzN+Awym7YVIa0blykwPuS5BQ+xG8gyCkabyFpAPxn8PN4jFCm A3jyZ0Ya5k85LFp8tnVSlgXIX/mEucglne347MM+WcMtHjFA/rsVhb57TX6/r00Zuhv1 CaJg== X-Gm-Message-State: AOAM532s/e0ozhhq/ZoHZLbpmdi4o6TR1g0ewcSr1w8uIPLcT70PNYBm oH/APwyYJuFnKo+QcOnSujTpa1z1a5C54bE8I6rz9yBxZ3WpdkYO3pMdw917HXKk7UwYDvUIWll L6ShjRjVSsjWo9JIXCCmAgsTQ1JeBvigp8rJpzQ1ADZFskx5MCeNA/KwcN1I6PuYCSs0FWzKovf Dxe7QZ7YDF2zLke0hhtE4eIsckv45Lc5Sld9ihkyGKcDNvnWgZvr3x X-Google-Smtp-Source: ABdhPJxMTto7rEX+F5aphcD7vwuiF16gF/gv4abtn/t8vp1fGr6jdnGNim8geZdcz0GXLa20Pv4gUA== X-Received: by 2002:a17:906:3949:: with SMTP id g9mr12424653eje.493.1610835502226; Sat, 16 Jan 2021 14:18:22 -0800 (PST) Received: from [10.137.0.20] (ip-86-49-253-127.net.upcbroadband.cz. [86.49.253.127]) by smtp.gmail.com with ESMTPSA id d18sm8224145edz.14.2021.01.16.14.18.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 16 Jan 2021 14:18:21 -0800 (PST) Subject: Re: COPY FREEZE and setting PD_ALL_VISIBLE/visibility map bits To: Anastasia Lubennikova , Tomas Vondra Cc: Tatsuo Ishii , lubennikovaav@gmail.com, pgsql-hackers@lists.postgresql.org, pavan.deolasee@gmail.com, ibrar.ahmad@gmail.com References: <160382617166.1204.475752573208579406.pgcf@coridan.postgresql.org> <20201028.144653.966121790856478893.t-ishii@sraoss.co.jp> <20201030004252.d63rwclys4bniluu@development> <1d2e0f4a-6ab8-10f1-c177-af97475df001@postgrespro.ru> <20201102144453.tumlk7qhw3gzn2dk@development> <7e6a006f-c59a-93fc-3ddf-f9c661319bc8@2ndquadrant.com> <75f3760f-1077-07c1-aea4-975d5c127d6d@postgrespro.ru> <93b767d6-4cde-7326-8de4-d71d81817c16@postgrespro.ru> <8669d452-d078-bdf9-5a62-6f1acd55f3c6@enterprisedb.com> <58359211-c505-1ee6-c5fd-78db84afb46f@postgrespro.ru> From: Tomas Vondra Message-ID: <13a5b2dc-4fe9-d4a6-01df-d2c7bba8fd2c@enterprisedb.com> Date: Sat, 16 Jan 2021 23:18:19 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: <58359211-c505-1ee6-c5fd-78db84afb46f@postgrespro.ru> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-CLOUD-SEC-AV-Info: enterprisedb,google_mail,monitor X-CLOUD-SEC-AV-Sent: true X-Gm-Spam: 0 X-Gm-Phishy: 0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 1/16/21 4:11 PM, Anastasia Lubennikova wrote: > > ... > > As Pavan correctly figured it out before the problem is that > RelationGetBufferForTuple() moves to the next page, losing free space in > the block: > > > ... I see that a relcache invalidation arrives > > after 1st and then after every 32672th block is filled. That clears the > > rel->rd_smgr field and we lose the information about the saved target > > block. The code then moves to extend the relation again and thus > skips the > > previously less-than-half filled block, losing the free space in that > block. > > The reason of this cache invalidation is vm_extend() call, which happens > every 32762 blocks. > > RelationGetBufferForTuple() tries to use the last page, but for some > reason this code is under 'use_fsm' check. And COPY FROM doesn't use fsm > (see TABLE_INSERT_SKIP_FSM). > > >         /* >          * If the FSM knows nothing of the rel, try the last page > before we >          * give up and extend.  This avoids one-tuple-per-page syndrome > during >          * bootstrapping or in a recently-started system. >          */ >         if (targetBlock == InvalidBlockNumber) >         { >             BlockNumber nblocks = RelationGetNumberOfBlocks(relation); >             if (nblocks > 0) >                 targetBlock = nblocks - 1; >         } > > > I think we can use this code without regard to 'use_fsm'. With this > change, the number of toast rel pages is correct. The patch is attached. > Thanks for the updated patch, this version looks OK to me - I've marked it as RFC. I'll do a bit more testing, review, and then I'll get it committed. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company