pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ron <ronljohnsonjr@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: Insert into on conflict, data size upto 3 billion records
Date: Sat, 13 Feb 2021 14:04:17 -0600
Message-ID: <2a876340-e227-c96a-1d79-f8a74aa45e4a@gmail.com> (raw)
In-Reply-To: <CAD-twtSfABMBH3ODxJiKdh6FHBtB0UuXn4mN-xwnC7tb=Cphjg@mail.gmail.com>
References: <CAD-twtSfABMBH3ODxJiKdh6FHBtB0UuXn4mN-xwnC7tb=Cphjg@mail.gmail.com>

On 2/12/21 12:46 PM, Karthik Kumar Kondamudi wrote:
> Hi,
>
> I'm looking for suggestions on how I can improve the performance of the 
> below merge statement, we have a batch process that batch load the data 
> into the _batch tables using Postgres and the task is to update the main 
> target tables if the record exists else into it, sometime these batch 
> table could go up to 5 billion records. Here is the current scenario
>
> |target_table_main| has 700,070,247  records and is hash partitioned into 
> 50 chunks, it has an index on |logical_ts| and the batch table has 
> 2,715,020,546 close to 3 billion records, so I'm dealing with a huge set 
> of data so looking of doing this in the most efficient way.

Many times, I have drastically sped up batch processing by #1 partitioning 
on the same field as an index, and #2 pre-sorting the input data by that field.

That way, you get excellent "locality of data" (meaning lots of writes to 
the same hot bits of cache, which later get asynchronously flushed to 
disk).  Unfortunately for your situation, the purpose of hash partitioning 
is to /reduce/ locality of data.  (Sometimes that's useful, but *not* when 
processing batches.)

-- 
Angular momentum makes the world go 'round.

view thread (7+ messages)  latest in thread

Message-ID: <2a876340-e227-c96a-1d79-f8a74aa45e4a@gmail.com>
Permalink:  ../2a876340-e227-c96a-1d79-f8a74aa45e4a@gmail.com/
Also on:    postgresql.org/message-id/2a876340-e227-c96a-1d79-f8a74aa45e4a@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: ronljohnsonjr@gmail.com
  Subject: Re: Insert into on conflict, data size upto 3 billion records
  In-Reply-To: <2a876340-e227-c96a-1d79-f8a74aa45e4a@gmail.com>
  References: <CAD-twtSfABMBH3ODxJiKdh6FHBtB0UuXn4mN-xwnC7tb=Cphjg@mail.gmail.com> <2a876340-e227-c96a-1d79-f8a74aa45e4a@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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