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 1mlUBh-0005ew-Nu for pgsql-general@arkaria.postgresql.org; Fri, 12 Nov 2021 10:53:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mlUBf-0003dh-Rg for pgsql-general@arkaria.postgresql.org; Fri, 12 Nov 2021 10:53:39 +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 1mlUBf-0003dX-AA for pgsql-general@lists.postgresql.org; Fri, 12 Nov 2021 10:53:39 +0000 Received: from mout02.posteo.de ([185.67.36.66]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mlUBZ-0001aP-Kk for pgsql-general@postgresql.org; Fri, 12 Nov 2021 10:53:37 +0000 Received: from submission (posteo.de [89.146.220.130]) by mout02.posteo.de (Postfix) with ESMTPS id 86E22240103 for ; Fri, 12 Nov 2021 11:53:30 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1636714410; bh=fHUaGiE5YetwCgBNEqadV0ac/AWbnMEjddnSNgXDqnU=; h=Date:Subject:To:Cc:From:From; b=qz0BJqNVSvs89mQjK+ZQ2fsbTjLM93FwhBVWc46m89OMnpyYXzVIs1YjhNn7FGvCq hVr9/SCJORtLRrhVJbC9DQYse4Hv1gvYIeEoiRtVdo32MXfIg0Xv44X8uBi/NP9i3C WEPr+lp/UXsUa9fntyWWmAq/YF+HXGKMMXqQp1nwERgodcbTRQOo8h65SBR1INzySb yUc0nfAQF5GbeaTcxkmS9tqs4YVh4nBB0toQGHh2Wyq4zldEQeI2wvA0jv97/AIzS1 SHgRDzgZjw+eZfzUB+mLmBYYopHY4mgAwab8CsSyfn/j3AJxslL0uSARymbv7mR+6R bLkfrSFpg5itw== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4HrFn51806z9rxV; Fri, 12 Nov 2021 11:53:29 +0100 (CET) Content-Type: multipart/alternative; boundary="------------ooy1tNG2Tk2jguSJakAUhJZ0" Message-ID: <68d238fe-b316-42d7-5351-9631b0c2b847@posteo.de> Date: Fri, 12 Nov 2021 10:53:28 +0000 MIME-Version: 1.0 Subject: Re: Are all unlogged tables in any case truncated after a server-crash? Content-Language: en-GB To: "David G. Johnston" Cc: pgsql-general References: From: sch8el@posteo.de 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. --------------ooy1tNG2Tk2jguSJakAUhJZ0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hi David, thx for your comments and your advice on reading docs on "checkpoint". Of course consistency is most important to any DBMS, and if in doubt about that, truncate data rows and restore from WAL. But in this case, where data is never modified after bulk load, I thought there might be an undocumented feature or workaround, like ...   - option to set the datafiles of those tables in read-only mode and record this in the metadata   - on server-recovery spare these unlogged tables and indexes from truncating all data rows Its truly a "nice to have"-thing, but I have learned now, that there is not feature like that. Mart Am 11.11.2021 um 22:10 schrieb David G. Johnston: > On Thu, Nov 11, 2021 at 11:39 AM wrote: > > After > that all unlogged tables remain completely unchanged (no > DML-/DDL-Statements). Hence all of my huge unlogged, "static" > tables get > never "unclean" and should not be truncated after a server crash. > > > The server cannot make this assumption so it truncates unlogged > relations upon an unclean shutdown/crash because it has no WAL with > which to ensure a proper restoration. > > BTW, if I set all unlogged tables to logged after bulk load, it takes > additional 1.5 hours, mainly because of re-indexing, I suppose. > > > More likely it is writing the entire table, and all of its indexes, to > WAL. > > I assume > that a restart of the database after a server crash takes another 1.5 > hours (reading from WAL) until the database is up and running. > > > That would be incorrect.  See "CHECKPOINT". > > > Therefore I am seeking a strategy, to not tagging those tables as > "unclean" and not truncating all unlogged tables on server restart. > > > There is no middle ground that I am aware of.  Either the contents of > the table are in WAL ,or they are not.  If not, they can be lost upon > an unclean shutdown.  For manually initiated shutdowns you do have the > option to do so cleanly. > > This topic (unlogged optimizations) does draw quite a bit of attention > every year but so far the problem of proving to the system that the > physical file on disk is a truly accurate representation of the > post-crash relation is yet unsolved. > > David J. > --------------ooy1tNG2Tk2jguSJakAUhJZ0 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit Hi David,

thx for your comments and your advice on reading docs on "checkpoint".

Of course consistency is most important to any DBMS, and if in doubt about that, truncate data rows and restore from WAL.
But in this case, where data is never modified after bulk load, I thought there might be an undocumented feature or workaround, like ...
  - option to set the datafiles of those tables in read-only mode and record this in the metadata
  - on server-recovery spare these unlogged tables and indexes from truncating all data rows

Its truly a "nice to have"-thing, but I have learned
now, that there is not feature like that.

Mart


Am 11.11.2021 um 22:10 schrieb David G. Johnston:
On Thu, Nov 11, 2021 at 11:39 AM <sch8el@posteo.de> wrote:
After
that all unlogged tables remain completely unchanged (no
DML-/DDL-Statements). Hence all of my huge unlogged, "static" tables get
never "unclean" and should not be truncated after a server crash.

The server cannot make this assumption so it truncates unlogged relations upon an unclean shutdown/crash because it has no WAL with which to ensure a proper restoration.

BTW, if I set all unlogged tables to logged after bulk load, it takes
additional 1.5 hours, mainly because of re-indexing, I suppose.

More likely it is writing the entire table, and all of its indexes, to WAL.

I assume
that a restart of the database after a server crash takes another 1.5
hours (reading from WAL) until the database is up and running.

That would be incorrect.  See "CHECKPOINT".


Therefore I am seeking a strategy, to not tagging those tables as
"unclean" and not truncating all unlogged tables on server restart.


There is no middle ground that I am aware of.  Either the contents of the table are in WAL ,or they are not.  If not, they can be lost upon an unclean shutdown.  For manually initiated shutdowns you do have the option to do so cleanly.

This topic (unlogged optimizations) does draw quite a bit of attention every year but so far the problem of proving to the system that the physical file on disk is a truly accurate representation of the post-crash relation is yet unsolved.

David J.


--------------ooy1tNG2Tk2jguSJakAUhJZ0--