pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Multiple COPY on the same table
10+ messages / 6 participants
[nested] [flat]

* Multiple COPY on the same table
@ 2018-08-20 14:54  Ravi Krishna <sravikrishna@aol.com>
  0 siblings, 2 replies; 10+ messages in thread

From: Ravi Krishna @ 2018-08-20 14:54 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

Can I split a large file into multiple files and then run copy using each file.  The table does not contain any serial or sequence column which may need serialization. Let us say I split a large file to 4 files.  Will theperformance boost by close to 4x??
ps: Pls ignore my previous post which was without a subject (due to mistake)

^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: Multiple COPY on the same table
@ 2018-08-20 15:56  Nicolas Paris <nicolas.paris@riseup.net>
  parent: Ravi Krishna <sravikrishna@aol.com>
  1 sibling, 1 reply; 10+ messages in thread

From: Nicolas Paris @ 2018-08-20 15:56 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

> Can I split a large file into multiple files and then run copy using
> each file.  

AFAIK, copy command locks the table[1] while there is no mention of this
in the documentation[2]. 

>  Will the performance boost by close to 4x??

You might be interested in the pbBulkInsert tool[3] that allows parallel
copy with some succes accordingly to benchmarks. However, that tool does
not handle multiline csv. Because of that limitation I have been using
the standard copy command with binary format with some succes.


[1] https://grokbase.com/t/postgresql/pgsql-general/01597pv3qs/copy-locking
[2] https://www.postgresql.org/docs/current/static/sql-copy.html
[3] https://github.com/bytefish/PgBulkInsert




^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: [External] Multiple COPY on the same table
@ 2018-08-20 16:47  Vijaykumar Jain <vjain@opentable.com>
  parent: Ravi Krishna <sravikrishna@aol.com>
  1 sibling, 1 reply; 10+ messages in thread

From: Vijaykumar Jain @ 2018-08-20 16:47 UTC (permalink / raw)
  To: Ravi Krishna <sravikrishna@aol.com>; pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>

Hey Ravi,

What is the goal you are trying to achieve here.
To make pgdump/restore faster?
To make replication faster?
To make backup faster ?

Also no matter how small you split the files into, if network is your bottleneck then I am not sure you can attain n times the benefit my simply sending the files in parallel but yeah maybe some benefit.
But then for parallel processing you also need to ensure your server is having relevant resources or else it will just be a lot of context switching I guess ?
Pg dump has an option to dump in parallel
pgbasebackup is single threaded I read but pgbackrest can allow better parallel processing in backups.
There is also logical replication where you can selectively replicate your tables to avoid bandwidth issues.
I might have said a lot and nothing may be relevant, but you need to let us know the goal you want to achieve :)

Regards,
Vijay
________________________________
From: Ravi Krishna <sravikrishna@aol.com>
Sent: Monday, August 20, 2018 8:24:35 PM
To: pgsql-general@lists.postgresql.org
Subject: [External] Multiple COPY on the same table

Can I split a large file into multiple files and then run copy using each file.  The table does not contain any
serial or sequence column which may need serialization. Let us say I split a large file to 4 files.  Will the
performance boost by close to 4x??

ps: Pls ignore my previous post which was without a subject (due to mistake)

^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: [External] Multiple COPY on the same table
@ 2018-08-20 16:52  Ravi Krishna <sravikrishna@aol.com>
  0 siblings, 1 reply; 10+ messages in thread

From: Ravi Krishna @ 2018-08-20 16:52 UTC (permalink / raw)
  To: vjain@opentable.com; pgsql-general@lists.postgresql.org



> What is the goal you are trying to achieve here.
> To make pgdump/restore faster?
> To make replication faster?
> To make backup faster ?

None of the above.
 We got csv files from external vendor which are 880GB in total size, in 44 files.  Some of the large tables had COPY running for several hours. I was just thinking of a faster way to load.

^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: [External] Multiple COPY on the same table
@ 2018-08-20 17:00  Christopher Browne <cbbrowne@gmail.com>
  parent: Ravi Krishna <sravikrishna@aol.com>
  0 siblings, 1 reply; 10+ messages in thread

From: Christopher Browne @ 2018-08-20 17:00 UTC (permalink / raw)
  To: sravikrishna@aol.com; +Cc: vjain@opentable.com; pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>

On Mon, 20 Aug 2018 at 12:53, Ravi Krishna <sravikrishna@aol.com> wrote:

> > What is the goal you are trying to achieve here.
> > To make pgdump/restore faster?
> > To make replication faster?
> > To make backup faster ?
>
> None of the above.
>
>  We got csv files from external vendor which are 880GB in total size, in 44 files.  Some of the large tables had COPY running for several hours. I was just thinking of a faster way to load.


Seems like #4...

#4 - To Make Recovery faster

Using COPY pretty much *is* the "faster way to load"...

The main thing you should consider doing to make it faster is to drop
indexes and foreign keys from the tables, and recreate them
afterwards.
-- 
When confronted by a difficult problem, solve it by reducing it to the
question, "How would the Lone Ranger handle this?"




^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: [External] Multiple COPY on the same table
@ 2018-08-20 17:28  Vijaykumar Jain <vjain@opentable.com>
  parent: Christopher Browne <cbbrowne@gmail.com>
  0 siblings, 0 replies; 10+ messages in thread

From: Vijaykumar Jain @ 2018-08-20 17:28 UTC (permalink / raw)
  To: Christopher Browne <cbbrowne@gmail.com>; sravikrishna@aol.com <sravikrishna@aol.com>; +Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>


I guess this should help you, Ravi.

https://www.postgresql.org/docs/10/static/populate.html




On 8/20/18, 10:30 PM, "Christopher Browne" <cbbrowne@gmail.com> wrote:

    On Mon, 20 Aug 2018 at 12:53, Ravi Krishna <sravikrishna@aol.com> wrote:
    
    > > What is the goal you are trying to achieve here.
    > > To make pgdump/restore faster?
    > > To make replication faster?
    > > To make backup faster ?
    >
    > None of the above.
    >
    >  We got csv files from external vendor which are 880GB in total size, in 44 files.  Some of the large tables had COPY running for several hours. I was just thinking of a faster way to load.
    
    
    Seems like #4...
    
    #4 - To Make Recovery faster
    
    Using COPY pretty much *is* the "faster way to load"...
    
    The main thing you should consider doing to make it faster is to drop
    indexes and foreign keys from the tables, and recreate them
    afterwards.
    -- 
    When confronted by a difficult problem, solve it by reducing it to the
    question, "How would the Lone Ranger handle this?"
    



^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: [External] Multiple COPY on the same table
@ 2018-08-20 17:49  Ron <ronljohnsonjr@gmail.com>
  parent: Vijaykumar Jain <vjain@opentable.com>
  0 siblings, 0 replies; 10+ messages in thread

From: Ron @ 2018-08-20 17:49 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

Maybe he just has a large file that needs to be loaded into a table...

On 08/20/2018 11:47 AM, Vijaykumar Jain wrote:
> Hey Ravi,
>
> What is the goal you are trying to achieve here.
> To make pgdump/restore faster?
> To make replication faster?
> To make backup faster ?
>
> Also no matter how small you split the files into, if network is your 
> bottleneck then I am not sure you can attain n times the benefit my simply 
> sending the files in parallel but yeah maybe some benefit.
> But then for parallel processing you also need to ensure your server is 
> having relevant resources or else it will just be a lot of context 
> switching I guess ?
> Pg dump has an option to dump in parallel
> pgbasebackup is single threaded I read but pgbackrest can allow better 
> parallel processing in backups.
> There is also logical replication where you can selectively replicate your 
> tables to avoid bandwidth issues.
> I might have said a lot and nothing may be relevant, but you need to let 
> us know the goal you want to achieve :)
>
> Regards,
> Vijay
> ----------------------------------------------------------------------------
> *From:* Ravi Krishna <sravikrishna@aol.com>
> *Sent:* Monday, August 20, 2018 8:24:35 PM
> *To:* pgsql-general@lists.postgresql.org
> *Subject:* [External] Multiple COPY on the same table
> Can I split a large file into multiple files and then run copy using each 
> file.  The table does not contain any
> serial or sequence column which may need serialization. Let us say I split 
> a large file to 4 files.  Will the
> performance boost by close to 4x??
>
> ps: Pls ignore my previous post which was without a subject (due to mistake)

-- 
Angular momentum makes the world go 'round.

^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: [External] Multiple COPY on the same table
@ 2018-08-20 18:16  Ravi Krishna <sravikrishna@aol.com>
  0 siblings, 0 replies; 10+ messages in thread

From: Ravi Krishna @ 2018-08-20 18:16 UTC (permalink / raw)
  To: ; +Cc: pgsql-general@lists.postgresql.org

1. The tables has no indexes at the time of load.2.  The create table and copy are in the same transaction.
So I guess that's pretty much it.  I understand the long time it takes as some of the tables have 400+ million rows.Also the env is a container and since this is currently a POC system , not much time has been invested in fine tuning it.
thanks all.

^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: Multiple COPY on the same table
@ 2018-08-20 20:23  Adrian Klaver <adrian.klaver@aklaver.com>
  parent: Nicolas Paris <nicolas.paris@riseup.net>
  0 siblings, 1 reply; 10+ messages in thread

From: Adrian Klaver @ 2018-08-20 20:23 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

On 08/20/2018 08:56 AM, Nicolas Paris wrote:
>> Can I split a large file into multiple files and then run copy using
>> each file.
> 
> AFAIK, copy command locks the table[1] while there is no mention of this
> in the documentation[2].

[1] Is from Postgres 7.1(17 years ago). I suspect the conditions have 
changed at least a little:).

> 
>>   Will the performance boost by close to 4x??
> 
> You might be interested in the pbBulkInsert tool[3] that allows parallel
> copy with some succes accordingly to benchmarks. However, that tool does
> not handle multiline csv. Because of that limitation I have been using
> the standard copy command with binary format with some succes.
> 
> 
> [1] https://grokbase.com/t/postgresql/pgsql-general/01597pv3qs/copy-locking
> [2] https://www.postgresql.org/docs/current/static/sql-copy.html
> [3] https://github.com/bytefish/PgBulkInsert
> 
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com




^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: Multiple COPY on the same table
@ 2018-08-21 16:14  Christopher Browne <cbbrowne@gmail.com>
  parent: Adrian Klaver <adrian.klaver@aklaver.com>
  0 siblings, 0 replies; 10+ messages in thread

From: Christopher Browne @ 2018-08-21 16:14 UTC (permalink / raw)
  To: adrian.klaver@aklaver.com; +Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>

On Mon, 20 Aug 2018 at 16:23, Adrian Klaver <adrian.klaver@aklaver.com> wrote:
>
> On 08/20/2018 08:56 AM, Nicolas Paris wrote:
> >> Can I split a large file into multiple files and then run copy using
> >> each file.
> >
> > AFAIK, copy command locks the table[1] while there is no mention of this
> > in the documentation[2].
>
> [1] Is from Postgres 7.1(17 years ago). I suspect the conditions have
> changed at least a little:).

oxrsdb-generated@localhost->  create temp table foo ();
CREATE TABLE
oxrsdb-generated@localhost->  begin;
BEGIN
oxrsdb-generated@localhost-> * \copy foo from '/dev/null';
COPY 0
oxrsdb-generated@localhost-> * select oid, relname from pg_class where
relname = 'foo';
  oid   | relname
--------+---------
 350686 | foo
(1 row)

oxrsdb-generated@localhost-> * select * from pg_locks ;
  locktype  | database | relation | page | tuple | virtualxid |
transactionid | classid | objid | objsubid | virtualtransaction |  pid
 |       mode       | granted | fastpath
------------+----------+----------+------+-------+------------+---------------+---------+-------+----------+--------------------+-------+------------------+---------+----------
 relation   |   345742 |    11713 |      |       |            |
       |         |       |          | 2/200573           | 16754 |
AccessShareLock  | t       | t
 relation   |   345742 |     3455 |      |       |            |
       |         |       |          | 2/200573           | 16754 |
AccessShareLock  | t       | t
 relation   |   345742 |     2663 |      |       |            |
       |         |       |          | 2/200573           | 16754 |
AccessShareLock  | t       | t
 relation   |   345742 |     2662 |      |       |            |
       |         |       |          | 2/200573           | 16754 |
AccessShareLock  | t       | t
 relation   |   345742 |     2685 |      |       |            |
       |         |       |          | 2/200573           | 16754 |
AccessShareLock  | t       | t
 relation   |   345742 |     2684 |      |       |            |
       |         |       |          | 2/200573           | 16754 |
AccessShareLock  | t       | t
 relation   |   345742 |     2615 |      |       |            |
       |         |       |          | 2/200573           | 16754 |
AccessShareLock  | t       | t
 relation   |   345742 |     1259 |      |       |            |
       |         |       |          | 2/200573           | 16754 |
AccessShareLock  | t       | t
 relation   |   345742 |   350686 |      |       |            |
       |         |       |          | 2/200573           | 16754 |
RowExclusiveLock | t       | t
 virtualxid |          |          |      |       | 2/200573   |
       |         |       |          | 2/200573           | 16754 |
ExclusiveLock    | t       | t
(10 rows)

Table 'foo' has a RowExclusiveLock lock taken out as a consequence of
running COPY against it.

But that does not prevent other connections from concurrently writing
to the table.

Not all locks block other locks...
-- 
When confronted by a difficult problem, solve it by reducing it to the
question, "How would the Lone Ranger handle this?"




^ permalink  raw  reply  [nested|flat] 10+ messages in thread


end of thread, other threads:[~2018-08-21 16:14 UTC | newest]

Thread overview: 10+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-08-20 14:54 Multiple COPY on the same table Ravi Krishna <sravikrishna@aol.com>
2018-08-20 15:56 ` Nicolas Paris <nicolas.paris@riseup.net>
2018-08-20 20:23   ` Adrian Klaver <adrian.klaver@aklaver.com>
2018-08-21 16:14     ` Christopher Browne <cbbrowne@gmail.com>
2018-08-20 16:47 ` Vijaykumar Jain <vjain@opentable.com>
2018-08-20 17:49   ` Ron <ronljohnsonjr@gmail.com>
2018-08-20 16:52 Re: [External] Multiple COPY on the same table Ravi Krishna <sravikrishna@aol.com>
2018-08-20 17:00 ` Christopher Browne <cbbrowne@gmail.com>
2018-08-20 17:28   ` Vijaykumar Jain <vjain@opentable.com>
2018-08-20 18:16 Re: [External] Multiple COPY on the same table Ravi Krishna <sravikrishna@aol.com>

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