As I see in pg_stat_activiry
, only one of COPY
command executes at once. Other queries are in Lock state as I see in wait_event_type
column.
How can I run several COPY mytable FROM STDIN
in parallel without locking table?
ps. mytable
is hypertable of TimescaleDB 2.5.0.
UPD
CREATE TABLE "public"."mytable" (
"q_time" timestamp,
"symbol_id" int,
"o" decimal(24,12),
"c" decimal(24,12),
"h" decimal(24,12),
"l" decimal(24,12),
"v" bigint,
CONSTRAINT mytable_ts_pkey PRIMARY KEY (symbol_id, "q_time")
);
SELECT create_hypertable('mytable', 'q_time', 'symbol_id', 1,
create_default_indexes => false,
chunk_time_interval => '7 days'::interval);
UPD2
I run in parallel next commands:
out, err := exec.Command("bash", "-c", "cat file01.gz | gunzip | psql -d db -U user -c "\copy mytable from stdin HEADER DELIMITER ';' CSV\"").Output()
TimescaleDB 2.5.0
PostgreSQL 13
max_connections = 200
max_worker_processes = 21
max_parallel_workers = 10
file_fdw
then why not attach the file as a foreign table (or a temporary foreign table inpg_temp
schema) and theninsert into mytable ... select ... from the_foreign_table ...
? I think that this is more powerful and flexible than COPY as (almost) all SQL features are available. – Skirtingpsql
may be reason of locking. – Thence