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 1oIxAL-0006Ph-7z for pgsql-general@arkaria.postgresql.org; Tue, 02 Aug 2022 19:02:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oIx9L-0001Cl-Rk for pgsql-general@arkaria.postgresql.org; Tue, 02 Aug 2022 19:01:51 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oIx9L-0001Cb-Fv for pgsql-general@lists.postgresql.org; Tue, 02 Aug 2022 19:01:51 +0000 Received: from mail-oa1-x31.google.com ([2001:4860:4864:20::31]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oIx9J-0000LK-IP for pgsql-general@lists.postgresql.org; Tue, 02 Aug 2022 19:01:50 +0000 Received: by mail-oa1-x31.google.com with SMTP id 586e51a60fabf-10ea9ef5838so12837942fac.3 for ; Tue, 02 Aug 2022 12:01:49 -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:content-transfer-encoding; bh=DjJTlNePHCDD3bkZ7bgYSrb5AJvP1QYLlVrswwCcIVg=; b=JGg1HuRQmj9T153Vid5JyKMVnrdGTxkd7/H2Hizq5ZOY669bzUREiDv2IuD0WaKigS 3sL+ZpkECD6i7Pd/BzhSokbwnnE15vgETm7QiuwXF95Q02ONrnP1gSWo8Oe5Lpiv2bU4 CcJ0SMdIX46ZYENpOdm4Gk7/BT1cC828WQeD2aABVNGPSo/yuB4T5/XQb7hZ0+oappbb Kyd4CT5k4t980eHCvpF0ZJtxaEI+wDocfzhMtDwhK+Qt1FSGFiLz7cBEWQntgsB1NC5J lajjvvg5jV1ZKoKyDS/HorhNJdFZP3evCROxxfAAVIBwtzZV+UIWmW9wqTvZc8wJ2Jp1 CNSg== 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 :content-transfer-encoding; bh=DjJTlNePHCDD3bkZ7bgYSrb5AJvP1QYLlVrswwCcIVg=; b=ewwyNK7wfapw3SDdktvEpoeDMRA46zzjzIlz8pQbfKD7id3A69kn/dMyQGSKJdOPot uiKbTKfUiojKhO5FwZ5SoGyD7UKe3ngidCmX+hFfgdANP7YYU05LJRCnP/0QfmmiumzL X2R0aHUd6iZX8zoaz+Zhe9iD4PHQw+5tUAY+PLSS4NQ9ZwI6Y7cEOC67cO6qL8TzdYhs AEWWMM2DUiFiHZ9EhdIluYyUyRHPYJdlaObBhnZFEQimAX3a4b6xuJmLd9lv6CrBSF/T WdUyrQcPNp78TV5ZZ8HxRVTEXjUmaqe7z2Qm0n7JZN82BPEj08zsscVMwXOlqhaquvkm OSeQ== X-Gm-Message-State: ACgBeo2zrX2RwkZi8ry93RSKJmNnIEasxD0FKyZ5HbjWFoV/X61YqHdu IV70b4opj2+rLljDi96SdX4ydTCl5YE= X-Google-Smtp-Source: AA6agR75xJLkEZNUnp3caCWRI7Q0zy90LxsUJZHYo/v4Rh9+82Gq3DmIMvrfUxgSOuO6F/f1DQH/rQ== X-Received: by 2002:a05:6871:85:b0:fe:29a0:4a2c with SMTP id u5-20020a056871008500b000fe29a04a2cmr394623oaa.249.1659466908065; Tue, 02 Aug 2022 12:01:48 -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 s23-20020a056870631700b0010e20d0b2e3sm1955596oao.44.2022.08.02.12.01.47 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 02 Aug 2022 12:01:47 -0700 (PDT) Message-ID: Date: Tue, 2 Aug 2022 14:01:46 -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: <3e06c774-e323-db92-0cea-8600e1155600@gmx.net> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 8/2/22 13: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 That's what I figured, since COPY means moving data over the (admittedly very fast) wire, onto disk, and then back over the wire into the new table. > > Another option is to have a trigger on table_a > to automatically replay all DML on table_b How would you originally populate it? > 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) -- Angular momentum makes the world go 'round.