Re: alter table xxx set unlogged take long time - Mailing list pgsql-performance

From Joe Conway
Subject Re: alter table xxx set unlogged take long time
Date
Msg-id e1920272-57a6-7c5a-924d-be26065ad9ad@joeconway.com
Whole thread Raw
In response to RE: alter table xxx set unlogged take long time  ("James Pang (chaolpan)" <chaolpan@cisco.com>)
Responses Re: alter table xxx set unlogged take long time  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-performance
On 7/26/22 08:59, James Pang (chaolpan) wrote:
>     We use JDBC to export data into csv ,then copy that to Postgres. 
> Multiple sessions working on multiple tables.  If not set unlogged , how 
> to make COPY run fast ?   possible to start a transaction include all of 
> these  “truncate table xxx; copy table xxxx; create index on tables….”  
> With wal_level=minimal, is it ok to make copy and create index  without 
> logging ?

Not sure if it would work for you, but perhaps a usable strategy would 
be to partition the existing large table on something (e.g. a new column 
like batch number?).

Then (completely untested) I *think* you could create the "partition" 
initially as a free standing unlogged table, load it, index it, switch 
to logged, and then attach it to the partitioned table.

Perhaps you could also have a background job that periodically 
aggregates the batch partitions into larger buckets to minimize the 
overall number of partitions.


-- 
Joe Conway
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com



pgsql-performance by date:

Previous
From: Justin Pryzby
Date:
Subject: Re: Postgresql 14 partitioning advice
Next
From: Tom Lane
Date:
Subject: Re: alter table xxx set unlogged take long time