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 1lBjq2-0006Hc-I7 for pgsql-general@arkaria.postgresql.org; Mon, 15 Feb 2021 19:47:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lBjq1-0007v2-7K for pgsql-general@arkaria.postgresql.org; Mon, 15 Feb 2021 19:47:17 +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 1lBjq0-0007uv-Tn for pgsql-general@lists.postgresql.org; Mon, 15 Feb 2021 19:47:16 +0000 Received: from mail-ot1-x32f.google.com ([2607:f8b0:4864:20::32f]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lBjpy-00018i-Lr for pgsql-general@lists.postgresql.org; Mon, 15 Feb 2021 19:47:16 +0000 Received: by mail-ot1-x32f.google.com with SMTP id b16so4641480otq.1 for ; Mon, 15 Feb 2021 11:47:14 -0800 (PST) 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:content-transfer-encoding; bh=V14UeiI0xxl8NUCgsDCsk9cAyZsm5s5JGoOTuD06gp4=; b=dSVcuBbrBoctUXamch5CntZQa4dDaMunHX1R6SyoDuSzMdwrI6eWrMCeh+NHD2Etzm IwhD++tVurU6W6E1ioyFfphGUiUQT+Biaz9zknLD/p/SeBZvRI9pVxnmVgYcq+TixKLU G9E1f2b27wKr769UkZpyCeAyy3vjD3OFVCamfJCpkLX38bKVIiQsyif2CX4tVifhe4iQ 4iizyLHG7RweBNpNSjAllpx8eVnmpVhjPLwohWguU37xkM9C4J77HxB6cb3q0SzWx8vd XQ1Qh9ljQnxxPGBUT9Y+5GOXxDQKUN8zBKqM0oNWE4ckZPj6L5YKIwby+8VJMAU6933m BTDw== 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=V14UeiI0xxl8NUCgsDCsk9cAyZsm5s5JGoOTuD06gp4=; b=qyHjMuIYAzfk02Go1dDhC0vCYVBMQMCVZXkpgoIB1dR3xbQdljaGcDrp5BUGtSRL9j PhJj1aYXMBlkWDUz5gbtUKx1lqvjEIpNuUgEVbhVe/q3Sd22ops4SVnZ1dQU2NJt6In3 ghELKl2eTnosaHjV8qtFs4J7XURvokEOuuQ+s97SgAc8E6xj4YeaAVpj299Aw9fJFS1x mosf4vqAFsnz79iCyj+l+zS6ZQLoYvHpQzEANGgA6JIh+OjxI87IB3nq4TAHEyhumptS H4wx1va/mbzk1hDuf8d7NhNU5KPEZJ5yqTVHvqaz5TDASlkgFB1IBWW34B85XFboJxuU YZRA== X-Gm-Message-State: AOAM533OoQcDhCv6+15ekmzIFkisL0Jd/dFjCXuy13PMeWQ7zCRi5Oj/ B/3Rk9lMdMbJJwqD6tsuemyGaxVP70M= X-Google-Smtp-Source: ABdhPJwp3ZTvBOHSQoXaCPWHf0++TxZveHRyXG4TS58RxHXYaV2xHuBqk1/WcUcC/ekZZ1aT+yKrlg== X-Received: by 2002:a9d:5d09:: with SMTP id b9mr2440234oti.36.1613418432986; Mon, 15 Feb 2021 11:47:12 -0800 (PST) Received: from ?IPv6:2601:681:5500:dde0:216a:ac73:ce4:9476? ([2601:681:5500:dde0:216a:ac73:ce4:9476]) by smtp.gmail.com with ESMTPSA id j25sm3450060otn.55.2021.02.15.11.47.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 15 Feb 2021 11:47:12 -0800 (PST) Subject: Re: Insert into on conflict, data size upto 3 billion records To: Karthik K Cc: pgsql-general@lists.postgresql.org References: <2a876340-e227-c96a-1d79-f8a74aa45e4a@gmail.com> <5ebe9fe2-3546-14f4-cd59-0b7335e26a40@gmail.com> From: Rob Sargent Message-ID: <6075918d-c07d-7a29-aecc-95e0b160033a@gmail.com> Date: Mon, 15 Feb 2021 12:47:11 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-CA Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2/15/21 12:22 PM, Karthik K wrote: > yes, I'm using \copy to load the batch table, > > with the new design that we are doing, we expect updates to be less > going forward and more inserts, one of the target columns I'm updating > is indexed, so I will drop the index and try it out, also from your > suggestion above splitting the on conflict into insert and update is > performant but in order to split the record into batches( low, high) I > need to do a count of primary key on the batch tables to first split it > into batches > > I don't think you need to do a count per se. If you know the approximate range (or better, the min and max) in the incoming/batch data you can approximate the range values.