Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oIxB8-0006S4-Eh for pgsql-general@arkaria.postgresql.org; Tue, 02 Aug 2022 19:03:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oIxA9-00052k-7x for pgsql-general@arkaria.postgresql.org; Tue, 02 Aug 2022 19:02:41 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oIxA8-00052b-Tj for pgsql-general@lists.postgresql.org; Tue, 02 Aug 2022 19:02:40 +0000 Received: from mail-oi1-x233.google.com ([2607:f8b0:4864:20::233]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oIxA7-0003Sm-0I for pgsql-general@lists.postgresql.org; Tue, 02 Aug 2022 19:02:40 +0000 Received: by mail-oi1-x233.google.com with SMTP id u76so17569620oie.3 for ; Tue, 02 Aug 2022 12:02:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language:to :references:from:in-reply-to; bh=YD8zRJiaazRQs/vS1Nud2jjEXO0acqqXe7SA8Jse2aw=; b=IG4X9kHoBe1187bhCnpOCiLeT3n8uiXaIWyyLEI48e2YkZd8BB3iQ7mffcFGWCLxbc DuIm3caSnDYGXoK6+osoTJu7lOeUGHnB8R/v58nBemIpFzjeKkIm0FJy9ppIaZy8URsD LiGqmeVL2ZGMVq+CNjhvuQR4HuqptQOXdevM6DdaCk+P41lMc3Amo4QYPtqwGoXCAjWH aN/tzsXRJgj/Cs0O2c71bvli/UI7nefc9d62NOzGYE+nk1T875RUL/BU6S2TijJMedBM hdZomrWBmXgniStej85haHuEw3t9a55kpEpa0gRaEhpx7p8tEfH7/HSXzG4/pJSdn9oA IRow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:in-reply-to; bh=YD8zRJiaazRQs/vS1Nud2jjEXO0acqqXe7SA8Jse2aw=; b=JOD4W5DkhbwIPrSgV+xeMHq6oxAz4HFyzXgDyVicsgqYmRZqBZA+NTA5XfUrTQMVpo sGAqL3fOwAc50uSvkdoOaGfMjGP/dFjpJ1SLP90x1eDLhrItSVXnAkw0s9igtS2a1IM2 I8xw7pW6WM7d8xz6AcZCajjf75LzPmwKkhjnUnF2azhKByYUCpVaVQdQ/rM5iYWgSHiX MOsLdqLYFR45SwCiKcLDqzXYZ2wAKh9EoThXffKKPQoFJzuYQmFV34xPHwjhp7j+PGew 7QIBx+hQAqgvechnFQNH9aIH9wPC1/sVFK0kE9H92/XVLmwZ1+1fEftGtSLdyOhevCwz A0+Q== X-Gm-Message-State: ACgBeo1m3jJUTxS1ouvsQdSld6idKvTnzzjeeFTObXccTPDlRopw3BHG Q4n9hOY/8jPfIac13l9AjX+fB+d4CfU= X-Google-Smtp-Source: AA6agR61nVPd3G++NnTYTVxaDVoSs7Mwlbzt/6HydRrw1/0P/W/G2cvevH8nGsjT6F9/wHr3bS9bPw== X-Received: by 2002:a05:6808:20a0:b0:33a:8965:3a92 with SMTP id s32-20020a05680820a000b0033a89653a92mr357163oiw.62.1659466956798; Tue, 02 Aug 2022 12:02:36 -0700 (PDT) Received: from [192.168.88.10] (ip68-11-68-85.no.no.cox.net. [68.11.68.85]) by smtp.googlemail.com with ESMTPSA id t22-20020a056808159600b0032ed2343100sm3127628oiw.14.2022.08.02.12.02.36 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 02 Aug 2022 12:02:36 -0700 (PDT) Content-Type: multipart/alternative; boundary="------------iq88CvhxP7JYIfHlX2kNhwgC" Message-ID: <6a0b6197-c0ce-f0a0-2b2f-18f2b6e9b0fa@gmail.com> Date: Tue, 2 Aug 2022 14:02:35 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Subject: Re: Copying records from TABLE_A to TABLE_B (in the same database) Content-Language: en-US To: pgsql-general@lists.postgresql.org References: <5adcc923-889d-bb68-5a04-60125b6f0e96@gmail.com> <3e06c774-e323-db92-0cea-8600e1155600@gmx.net> From: Ron In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------iq88CvhxP7JYIfHlX2kNhwgC Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 8/2/22 13:59, Rob Sargent wrote: > On 8/2/22 12:51, Thomas Kellerer wrote: >> Ron schrieb am 02.08.2022 um 20:37: >>> AWS RDS Postgresql 12.10 >>> >>> There are no indices or constraints (except for NOT NULL) on table_a. >>> >>> The two ways that I know are: >>>      INSERT INTO table_a SELECT * FROM table_b; >>> and >>>      \COPY table_a TO '/tmp/table_a.tsv' WITH (FORMAT BINARY); >>>      \COPY table_b FROM '/tmp/table_a.tsv' WITH (FORMAT BINARY); >>> >>> Is there a faster/better way? >> >> The INSERT is most probably faster then \copy >> >> Another option is to have a trigger on table_a >> to automatically replay all DML on table_b >> >> >> Logical replication might be another option. >> Although I am not sure if that is even possible inside >> the samme database. >> I know it's tricky inside the same server >> (between different databases) >> >> >> > If you can get outside sql, the bulk copy facilities (CopyManager in java) > is blindingly fast for me. ?? -- Angular momentum makes the world go 'round. --------------iq88CvhxP7JYIfHlX2kNhwgC Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit On 8/2/22 13:59, Rob Sargent wrote:
On 8/2/22 12:51, Thomas Kellerer wrote:
Ron schrieb am 02.08.2022 um 20:37:
AWS RDS Postgresql 12.10

There are no indices or constraints (except for NOT NULL) on table_a.

The two ways that I know are:
     INSERT INTO table_a SELECT * FROM table_b;
and
     \COPY table_a TO '/tmp/table_a.tsv' WITH (FORMAT BINARY);
     \COPY table_b FROM '/tmp/table_a.tsv' WITH (FORMAT BINARY);

Is there a faster/better way?

The INSERT is most probably faster then \copy

Another option is to have a trigger on table_a
to automatically replay all DML on table_b


Logical replication might be another option.
Although I am not sure if that is even possible inside
the samme database.
I know it's tricky inside the same server
(between different databases)



If you can get outside sql, the bulk copy facilities (CopyManager in java) is blindingly fast for me.

??

--
Angular momentum makes the world go 'round.
--------------iq88CvhxP7JYIfHlX2kNhwgC--