Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qxjok-0037Xc-US for pgsql-hackers@arkaria.postgresql.org; Tue, 31 Oct 2023 08:09:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qxjoj-0014f2-Es for pgsql-hackers@arkaria.postgresql.org; Tue, 31 Oct 2023 08:09:41 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qxjoj-0014er-3B for pgsql-hackers@lists.postgresql.org; Tue, 31 Oct 2023 08:09:41 +0000 Received: from mail-qt1-x82d.google.com ([2607:f8b0:4864:20::82d]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qxjog-003Dtf-N5 for pgsql-hackers@postgresql.org; Tue, 31 Oct 2023 08:09:39 +0000 Received: by mail-qt1-x82d.google.com with SMTP id d75a77b69052e-41cd566d8dfso161021cf.0 for ; Tue, 31 Oct 2023 01:09:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698739778; x=1699344578; darn=postgresql.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=mBpuHI6IleX/zB9ms00ZS+oOW0vnEjMN6DKOpmRSJ0E=; b=iJoAEBSlgGvfMUlC04vOtk1mZzOemTBud4A1y9rybz3xfr2P4eqObzvingLjFRunRo v5CFN+NUw2kgFEgBeAyBmbz+N1NYUUvzf/Jxgyj1qoYErzd99hEtlCLu1gqQbvMVgY0P jO44Gv7BGXMeH2yXJkP5Wh3bJ2duNI2DEtRBDDr+wRF4fO+xIvNfS2f7yoroEG6xKibl n9e5EqCoUx11ZTF5iMaWebKBjCadTFgMBKmM3r1ayQ0bEsMSDdV/Rls20pYfTuA/lBzD YrTHowM1LfL2KCU8HycIyt8wrWmS3cPgjVbXpmYl3Gm5+rCxyOMObLwcFHXR2L+30/uW pvgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698739778; x=1699344578; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=mBpuHI6IleX/zB9ms00ZS+oOW0vnEjMN6DKOpmRSJ0E=; b=BV13STph06mIcXRfekgmr5vy1WdgdzfFl5sC8/K4Iv+5srmsMdAkE/NhCYnTx6zeMd tjj8i12VqTHC2QjgFydxsw7FUuyWo0hN0kLUTplrMHD19Xjs5UL7Yy2Uxe9lkxeB8KSm Zy/BjJrmB7W6I/XYHvzXwp3qd0HvjS20iZrUlbtrCqdV6kJP7zo6Cv5IWqHy8fVF5fcI X4dqL/7WnpHG6HzUIcai5e981uKhA7QyhM8XGV12TN+/wZKzXgMlRzwtE+MNZ6BDgOG/ ua51VQWQXkm3CEZ3Fo1BDP5aV0dIltCmqQPp4vYxXAZ17sZ8quktvOQaKAqtsbbXQySB oPEQ== X-Gm-Message-State: AOJu0YyWheBaNPR2w48gkfxnT/z6MluXVZVJzHAqlK8RuCp94s/M5nPf vxHrZpuEBF/9hWwNhrz/32tRQRDaV1MW/WvdG8cZR1ELRcPic3reExL62Eg4 X-Google-Smtp-Source: AGHT+IElPiMFSKAGxFe/420ujA5WAzVK4XkJXdOPMiFrTlPdrpQ5hEWe2wadWSvTK0q0nMvaYg/+Y//qugAz2AWxbP0= X-Received: by 2002:ac8:4f57:0:b0:41e:3778:3389 with SMTP id i23-20020ac84f57000000b0041e37783389mr142085qtw.22.1698739777492; Tue, 31 Oct 2023 01:09:37 -0700 (PDT) MIME-Version: 1.0 From: Hannu Krosing Date: Tue, 31 Oct 2023 09:09:24 +0100 Message-ID: Subject: Allowing TRUNCATE of FK target when session_replication_role=replica To: pgsql-hackers Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi Currently we do not allow TRUNCATE of a table when any Foreign Keys point to that table. At the same time we do allow one to delete all rows when session_replication_role=replica This causes all kinds of pain when trying to copy in large amounts of data, especially at the start of logical replication set-up, as many optimisations to COPY require the table to be TRUNCATEd . The main two are ability to FREEZE while copying and the skipping of WAL generation in case of wal_level=minimal, both of which can achieve significant benefits when data amounts are large. Is there any reason to not allow TRUNCATE when session_replication_role=replica ? Unless there are any serious objections, I will send a patch to also allow TRUNCATE in this case. Best Regards Hannu