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 1vMmpD-0022VH-0k for pgsql-general@arkaria.postgresql.org; Sat, 22 Nov 2025 12:34:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vMmpA-00BW0h-2T for pgsql-general@arkaria.postgresql.org; Sat, 22 Nov 2025 12:34:45 +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 1vMmpA-00BW0Z-1E for pgsql-general@lists.postgresql.org; Sat, 22 Nov 2025 12:34:44 +0000 Received: from mail-ot1-x329.google.com ([2607:f8b0:4864:20::329]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vMmp8-000tJ6-1x for pgsql-general@lists.postgresql.org; Sat, 22 Nov 2025 12:34:44 +0000 Received: by mail-ot1-x329.google.com with SMTP id 46e09a7af769-7c7533dbd87so2060997a34.2 for ; Sat, 22 Nov 2025 04:34:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763814879; x=1764419679; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:references:in-reply-to :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=dy5ia2O1NDZfUSfy68wrJRy2c4KzfecO6jPscpb12nI=; b=FTQ8tHV1dqP3zQ3Gkk2MQl0nUYLLdhe8QEco9FQslEhTT2q6wstnjYzwD1A5xNDWMh grqsnEXHbXhbpewgPVa0/+RKrmW/1LLj5sdm9HxRHgdOQn3rgGcfMCV6Odtc6aA7qh9I W1t2aPNc+AD/9h6mwgWsjW0cs7IfVCoYakm8lVmMc4s8MdkB1fh/nvsUmvtS6n0vK33N mHfoaWAEWfjNpT1SMVZbBzbumrwC8G7UaM5asJNhXh5m/c3EwqJ5S36oGoFMcNOmTmFi hx0yJ/3M0Q4Ds3tte2l65I/+/N6cCWyCy5Wr4Zg4BHQxfNKAcmh6pYhvmCJJpREmqPcw 3F0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763814879; x=1764419679; h=cc:to:subject:message-id:date:from:references:in-reply-to :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=dy5ia2O1NDZfUSfy68wrJRy2c4KzfecO6jPscpb12nI=; b=K4d2BxOoLZwS153wYqk4P3rCK14a2Uy8GZS6MOJ56NWwnVzQZNw9koG0GHeAVfU1Lf RK4MAUNx6FfCqax7C8gvgOWHt+o1yEcIQleRiadf7M9jALngxJh5o0oWYnec31pd2qWK MPgwwDd5YUzLRYKrhnxLhbY4BWIsyX3M5nD9uoATQ/XdQ/seZ/fU5AcUUsMdQixsyXkS DF5gI4QHQnVV4ISoy/M9qnqwouXwkSwH+WC6D7lGLyb5L8POwdjPs++wPM/p4ZkwZrMx DrOCNcXYkvDzSxEITr6xW2kS0Q/t1PfhSqvhRgrHeGfzxcI+EPXHS/2JVzlYkr0dhNZc r1+g== X-Gm-Message-State: AOJu0YxZp65ANmAJxqVGvAZRKDXCSrhegG87Dp4LUOrZGMZdnGGbwu1B Swwezmlcw5DPXAi8SQ4Kr688vicaioejQf173VUX4QMbvO5t2nvkjNnRRnL6Ypfy4oeAdsBLowt qIK2R2MuGLefSSkk1MzcwAxQL2YgEsCw= X-Gm-Gg: ASbGncu3lyIbL0CkQsBxB04/9JgKC51kFuA4XnWmJdo4Ym2GvaZOe/EBuaMecIE2toD Jnfk55gU63O0xLuJUZMg4tOA6ui9ye1BZttjxuaTQYarlujqJApCGMWbFwGlFmHONUAP6KoI+gt 6gDc7cVyli8atxADZrk/NOhqVqm3RVMMi2YV+yISAhS/UVFKPCfeTogVJXzFuoEJIGi9NavWwzs q5HMM+kkU2zXpeaN5ebs0eUiKUSl1dXYtXnLZummwnRkG36QlQlRUELn6H4eBatUYATHpg= X-Google-Smtp-Source: AGHT+IEQ84tcKxkx+Mgf7fBdkuIjrJtK7mqPdeRh+ZoCppfErRPNdHtDBmmWlB3EZ7SXqiczQyICdk6Bjnrpyj1DR/0= X-Received: by 2002:a05:6808:c1f2:b0:450:d09a:8ce7 with SMTP id 5614622812f47-45112928a54mr2188304b6e.20.1763814879271; Sat, 22 Nov 2025 04:34:39 -0800 (PST) MIME-Version: 1.0 Received: by 2002:a05:6802:4c19:b0:605:8c60:fd86 with HTTP; Sat, 22 Nov 2025 04:34:38 -0800 (PST) In-Reply-To: <5031a50c-aca7-4512-9478-95583606b5ff@Spark> References: <5031a50c-aca7-4512-9478-95583606b5ff@Spark> From: "David G. Johnston" Date: Sat, 22 Nov 2025 06:34:38 -0600 X-Gm-Features: AWmQ_blRzB7PkCDYShW7pAccErLOGqsmCNShWOA-ldrg7VOnmS6fJ1UsJm21zRQ Message-ID: Subject: Re: FK from logged to unlogged table? To: "dolan@directdemocracysolutions.com" Cc: "pgsql-general@lists.postgresql.org" Content-Type: multipart/alternative; boundary="0000000000005421c706442e2736" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000005421c706442e2736 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Friday, November 21, 2025, wrote: > Hello, > > I'm looking to improve bulk write performance on a table of about 23 > million rows by setting it unlogged. If lost, the table can be re-generat= ed > from archived raw data. The unlogged table would be referenced from a > different, logged, table by a sparse but very important foreign key. > > If the unlogged table is lost, I can repair the foreign key data by > re-uploading the raw data and following a different unique key. However, > this would be annoying and I would rather not have to implement it if I c= an > protect the keyed records instead. > > 1. Is it allowed to key from a logged table to an unlogged table? > 2. What is the system behavior if the unlogged table is lost? > 3. Is there a clean way to protect only the subset of records that are > keyed? (Yes, I am considering periodic backups to an archive table, bu= t > there would still be some repair needed that way). > > Both 1 and 2 Feels like something you should take the couple of minutes to try. For 3, it=E2=80=99s an unlogged table - the entire thing. David J. --0000000000005421c706442e2736 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Friday, November 21, 2025, <dolan@directdemocracysolutions.com> wrote:
Hello,
=C2=A0
I'm looking to improve bulk write performance on a table of about = 23 million rows by setting it unlogged. If lost, the table can be re-genera= ted from archived raw data. The unlogged table would be referenced from a d= ifferent, logged, table by a sparse but very important foreign key.
=C2=A0
If the unlogged table is lost, I can repair the foreign key data by re= -uploading the raw data and following a different unique key. However, this= would be annoying and I would rather not have to implement it if I can pro= tect the keyed records instead.
  1. Is it allowed to key from a logged table to an unlogged table?
  2. What is the system behavior if the unlogged table is lost?
  3. Is there a clean way to protect only the subset of records that are key= ed? (Yes, I am considering periodic backups to an archive table, but there = would still be some repair needed that way).

Both 1 and 2 Feels like something you should take t= he couple of minutes to try.=C2=A0 For 3, it=E2=80=99s an unlogged table - = the entire thing.

David J.

--0000000000005421c706442e2736--