pgloader icon indicating copy to clipboard operation
pgloader copied to clipboard

pgloader will hang when the data breaks primary key or not null constraint

Open dasong2410 opened this issue 8 years ago • 2 comments

Single node postgresql will not get this error, when using with citusdb, the error will show. Thanks.

Our server environment: Centos 7 PostgreSQL 10 Citus 7.3

  • [ ] pgloader --version

    pgloader version "3.4.1"
    compiled with SBCL 1.4.0-1.e17
    
  • [ ] did you test a fresh compile from the source tree?

    3.4.2 devel has the same problem

  • [ ] did you search for other similar issues?

  • [ ] how can I reproduce the bug?

--
-- file: my.load
--
load csv
from  /home/trans/test1.bcp
into  postgres://postgres:[email protected]:5432/postgres?tablename=test1
WITH  
fields not enclosed,
workers=32,
concurrency=8,
fields terminated by '\t'
SET work_mem to '1024 MB' , maintenance_work_mem to '2048 MB'
;

--data file: test1.bcp (fields separated by tab)

1	1
2	2
3	3
3	3
4	
5	5
6	6

-- sql&steps&errors
---create_distribute_table
---1
create table test1(id int primary key ,name varchar(100));
select create_distributed_table('test1','id');

----------error
[root@localhost trans]# pgloader my.load 
2016-09-29T02:39:18.255000-04:00 WARNING Target table "\"public\".\"test1\"" has 1 indexes defined against it.
2016-09-29T02:39:18.275000-04:00 WARNING That could impact loading performance badly.
2016-09-29T02:39:18.275000-04:00 WARNING Consider the option 'drop indexes'.

debugger invoked on a TYPE-ERROR in thread
#<THREAD "lparallel" RUNNING {1006D3B4D3}>:
  The value
    NIL
  is not of type
    NUMBER
  when binding SB-KERNEL::Y
2016-09-29T02:39:18.492000-04:00 ERROR PostgreSQL ["test1"] Database error XX000: duplicate key value violates unique constraint "test1_pkey_103155"
DETAIL: Key (id)=(3) already exists.
--2
--------------------
drop table test1;
create table test1(id int ,name varchar(100) not null);
select create_distributed_table('test1','id');
---error
[root@localhost trans]# pgloader my.load 

debugger invoked on a TYPE-ERROR in thread
#<THREAD "lparallel" RUNNING {10069B20D3}>:
  The value
    NIL
  is not of type
    NUMBER
  when binding SB-KERNEL::Y
2016-09-29T02:41:53.462000-04:00 ERROR PostgreSQL ["test1"] Database error XX000: null value in column "name" violates not-null constraint
DETAIL: Failing row contains (4, null).

-------------create_reference_table


-----1
drop table test1;
create table test1(id int primary key ,name varchar(100));
select create_reference_table('test1');

[root@localhost trans]# pgloader my.load 
2016-09-29T02:46:41.247000-04:00 WARNING Target table "\"public\".\"test1\"" has 1 indexes defined against it.
2016-09-29T02:46:41.256000-04:00 WARNING That could impact loading performance badly.
2016-09-29T02:46:41.256000-04:00 WARNING Consider the option 'drop indexes'.

debugger invoked on a TYPE-ERROR in thread
#<THREAD "lparallel" RUNNING {1006D42113}>:
  The value
    NIL
  is not of type
    NUMBER
  when binding SB-KERNEL::Y
2016-09-29T02:46:41.465000-04:00 ERROR PostgreSQL ["test1"] Database error XX000: duplicate key value violates unique constraint "test1_pkey_103204"
DETAIL: Key (id)=(3) already exists.

----2
drop table test1;
create table test1(id int  ,name varchar(100)  not null);
select create_reference_table('test1');

[root@localhost trans]# pgloader my.load 

debugger invoked on a TYPE-ERROR in thread
#<THREAD "lparallel" RUNNING {10069D9213}>:
  The value
    NIL
  is not of type
    NUMBER
  when binding SB-KERNEL::Y
2016-09-29T02:49:31.471000-04:00 ERROR PostgreSQL ["test1"] Database error XX000: null value in column "name" violates not-null constraint
DETAIL: Failing row contains (4, null).


dasong2410 avatar May 14 '18 05:05 dasong2410

I added a test case but failed to reproduce any problem. Can you please retry from current sources?

$ ./build/bin/pgloader ./test/pkey.load 
2018-06-15T22:09:44.051000+02:00 LOG Data errors in '/private/tmp/pgloader/'
2018-06-15T22:09:44.066000+02:00 LOG Parsing commands from file #P"/Users/dim/dev/pgloader/test/pkey.load"
2018-06-15T22:09:44.228000+02:00 WARNING Target table "\"public\".\"pkey\"" has 1 indexes defined against it.
2018-06-15T22:09:44.228000+02:00 WARNING That could impact loading performance badly.
2018-06-15T22:09:44.228000+02:00 WARNING Consider the option 'drop indexes'.
2018-06-15T22:09:44.330000+02:00 ERROR PostgreSQL ["\"public\".\"pkey\""] Database error 23505: duplicate key value violates unique constraint "pkey_pkey"
DETAIL: Key (id)=(3) already exists.
CONTEXT: COPY pkey, line 2
2018-06-15T22:09:44.347000+02:00 LOG report summary reset
             table name     errors       rows      bytes      total time
-----------------------  ---------  ---------  ---------  --------------
                  fetch          0          0                     0.006s
            before load          0          2                     0.015s
-----------------------  ---------  ---------  ---------  --------------
        "public"."pkey"          1          6     0.0 kB          0.083s
-----------------------  ---------  ---------  ---------  --------------
        Files Processed          0          1                     0.017s
COPY Threads Completion          0          9                     0.089s
-----------------------  ---------  ---------  ---------  --------------
      Total import time          1          6     0.0 kB          0.106s

dimitri avatar Jun 15 '18 20:06 dimitri

Thanks for your reply, I will try it again.

dasong2410 avatar Jun 20 '18 10:06 dasong2410