How to COPY into one PostgreSQL table in parallel without lock?

Viewed 913

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.

There are only one active query at once

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

0 Answers
Related