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.96) (envelope-from ) id 1vMnqp-002U6E-2B for pgsql-general@arkaria.postgresql.org; Sat, 22 Nov 2025 13:40:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vMnqm-00BloD-0Y for pgsql-general@arkaria.postgresql.org; Sat, 22 Nov 2025 13:40:28 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vMnql-00Blo5-2S for pgsql-general@lists.postgresql.org; Sat, 22 Nov 2025 13:40:28 +0000 Received: from mail-yw1-x112e.google.com ([2607:f8b0:4864:20::112e]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vMnqj-000tre-2P for pgsql-general@lists.postgresql.org; Sat, 22 Nov 2025 13:40:27 +0000 Received: by mail-yw1-x112e.google.com with SMTP id 00721157ae682-786a85a68c6so28816247b3.3 for ; Sat, 22 Nov 2025 05:40:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763818823; x=1764423623; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=wYPENDwnXQf1iToHAK+LHV9PBRs0HWLve3BL2mvYBRM=; b=Axu/l2A5UoZioBT1cz1WaRHxzKZMTZXxSXqjKbCR9Y3sD9w1ATG1n/6yGuaUJQkCsE D7nRU5DBzwDix9KybzyQrYjLYdTwgRA4NYcN6gEIi8/rze/fDTS50+g4Qp1QSby/yOHz F2DlE09IoBeZkYOFsB9kPbhZZ+On4iUyGtZlGL0B4xGKLHttZBKcrmRASKp1snVhjKrg h6EYffzhn+oAxKWCvep80izFgzPCmtXG7DyTYYSXlD6cEKlF2/3n3YZT64Bi3g56wMNf ZK69QBQsYHzyPqLahw3W2grZMco+Y5bnSoPIftSgeYud5iO7tRwqLuvDWE0wKqltL1CI BdnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763818823; x=1764423623; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=wYPENDwnXQf1iToHAK+LHV9PBRs0HWLve3BL2mvYBRM=; b=S25dNuMNYYHgxf3M1XoYPrfbsGNQDSt5VgMYNgzxoLeBMHAwglQnhDsyzwPJwrMF0A 8MCEEJlc75/guZ6Oyp943U303FzKCMnlFQryqCtQVQLz19H02t43XGXSY5o+TJlnDK9y 6LXWuoKYn2v2/Gc5cgRvSW4iBLN0j4487hQKhimFsmSq1EqPLQpZzvtl3JTFkH6ZgWhG bDwKaojX60WPFjSZVlxg2ykVJPpCm57JP44jD8217pp3XELmkX/XFZywQLR7bneqbFEI A57IPBzuyOnoVtW/n++TQ6KmHaWaW4oqn+U2d+gjsMUNvhZFxz21wuLRUrvM1cJvIH+q ONYQ== X-Gm-Message-State: AOJu0Yyg70PWY5/2IKvlXwIwiP346q3cmdU2T81tslYa6Z5h+cYWnVt5 jkpmn5GRNWW5CoQX2ovITO+62is9nY6iXxW2cGTN1zZE31Z5vQXSv6wKWzzUXkmdnxUpbUgiTk9 KJFubuICY2Ae1ktv6NSOd/1bwWdSel+M= X-Gm-Gg: ASbGncsa7oKgw3QFvcuOaTh/0WbUSipZ1klQ+lkkAx7ElPkVeXila/lMvwE9DWqb98F 06FCHmpiiFg40cJOWKKvXzaBDh6k/ztHQjuQ49I+2LT9/i90F4vkJ3sBQQbHAjnxmW0jP51Q61u Ur0m/aAPM1psGIHKPD3DxhJo4VP98FZO/f5HvtW0t5ttZ8ZnNTlNugWUdbDdX3SNkPIic4dRjq6 Vubf+yMsQBdmwxLP+EJXTaqSMAR0DGMcrg3YQhokYPsitlDwvHwEX+p31JudQDzdR87qCFs24LS Z82ZgU5bEcbERjF0u6ZucUZEAq2Fk6w= X-Google-Smtp-Source: AGHT+IG9u58ziMPxSTSamBqCYbfDVlSKLddEbmBCSV0JD3RZVc3KSuJ5N7L8azLVcVfIuNL2QAdTDYKSoSfe+UATMpo= X-Received: by 2002:a05:690c:4b89:b0:786:9817:edac with SMTP id 00721157ae682-78a8b529387mr44669057b3.43.1763818823269; Sat, 22 Nov 2025 05:40:23 -0800 (PST) MIME-Version: 1.0 References: <5031a50c-aca7-4512-9478-95583606b5ff@Spark> In-Reply-To: <5031a50c-aca7-4512-9478-95583606b5ff@Spark> From: Bernice Southey Date: Sat, 22 Nov 2025 13:39:47 +0000 X-Gm-Features: AWmQ_bmPgXZepMIj7h6Xc-zmQNBIhI470pakae0VOdAQTuGXH7G4EfCQU5ZrB44 Message-ID: Subject: Re: FK from logged to unlogged table? To: dolan@directdemocracysolutions.com Cc: pgsql-general@lists.postgresql.org Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk wrote: > Is it allowed to key from a logged table to an unlogged table? I tried and it seems not: create unlogged table u(i int primary key); create table l(i int references u); ERROR: constraints on permanent tables may reference only permanent tables Interestingly it works in the other direction. I assume it's forbidden because the loss of the unlogged table will break the constraint. I expect you could simulate the foreign key with a trigger, but I'm not sure you should. > Is there a clean way to protect only the subset of records that are keyed? I wonder if partitioning could help you. I believe it's possible to have logged and unlogged partitions in the same table [1]. I'm sure you've explored other options for faster inserts [2]. Most of the times I've wanted to use an unlogged table, I've decided it's not worth the rescue effort. Thanks, Bernice [1] https://www.postgresql.org/message-id/flat/ZiiyGFTBNkqcMQi_%40paquier.xyz [2] https://www.postgresql.org/docs/current/populate.html