Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eh30o-00006M-B9 for pgsql-general@arkaria.postgresql.org; Thu, 01 Feb 2018 00:45:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eh30n-0000CO-7M for pgsql-general@arkaria.postgresql.org; Thu, 01 Feb 2018 00:45:57 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eh30m-0000CE-PU for pgsql-general@lists.postgresql.org; Thu, 01 Feb 2018 00:45:57 +0000 Received: from mail-pf0-x241.google.com ([2607:f8b0:400e:c00::241]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1eh30S-0000vm-11 for pgsql-general@postgresql.org; Thu, 01 Feb 2018 00:45:55 +0000 Received: by mail-pf0-x241.google.com with SMTP id b25so14426369pfd.9 for ; Wed, 31 Jan 2018 16:45:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=RThOvKjNalXM87K4ppK6bl5R7qbSsLMs3OcEpULlLtI=; b=kamrtm+fGOxqUpht+JXE+H7iMuQeWIMZJ1OuufAP/llKOSTmddSMPX/Ge7HBmpeiYX mgbODyTonI/hoFOdBrEtyudWZhFc9ZHsoAesXnky1Oj4NeczQoHwvPM8d1RIm80ZIrub 9u8oSZBesvXl33SiDsEb+nqWrB+q8+OHNo8kEBlhmV5QIKe5W8hewCG9GaRysGH60wd7 idcY77etS+fXQUkhNSZl//lksYa7QoFxJA/qGpEMOVUczhCiYeWyGRfhUERbcmtVEF64 fqrlbX5yv9Xmwlqj2rb9hdYkheelENZl7fS0FJnMtD6FRmS9riHvng/gCpNxyLQnKLKm xzdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=RThOvKjNalXM87K4ppK6bl5R7qbSsLMs3OcEpULlLtI=; b=NHLVF8QDbykoAx+8P78fxMAiQuXkTUb40NY8zvI4Q/N6890i1NYAHmQfcu06bwWLnz tqFry7XKflQ2PGpLc1+Oj3vPYk7fiiIYgyRLV6PG8cHjfqT0rCypXxSxdL8xxDslJWcq O42Ls6BWgv/Q6KxYWW8UXh0F3uKzQyKqc7T3pwEGVTA40uAy87p7pyJAylk3VAbfKxSh RKMDhv/Hu40dZeHjo/7sTBfSevoTmizWuohLOCuJZwlZw4Ba8GQrOdeuqj/19HmZllRX xGsPAwKUOKj1SrpzFJMitpPewpRMc68+/L5eEi76VMV8qriaF/M8QavETVqJe3OltIg5 fHPQ== X-Gm-Message-State: AKwxytcWBoGq6/HQZEfFtLhjRpewmiPkW/neew/+88RSb68PEsuK+77r JtW87+TqneTQyKDxZIUudJ4= X-Google-Smtp-Source: AH8x227kcMtB42nB1SX85FL9KZA8qqHdE0q+lNGpDfMjA8eK9RCJE91jq7rdQAaMoc9phuRiXfbmdg== X-Received: by 2002:a17:902:6a81:: with SMTP id n1-v6mr7367620plk.11.1517445934601; Wed, 31 Jan 2018 16:45:34 -0800 (PST) Received: from paquier.xyz (c137162.net61215.cablenet.ne.jp. [61.215.137.162]) by smtp.gmail.com with ESMTPSA id r12sm38316845pfh.153.2018.01.31.16.45.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 31 Jan 2018 16:45:32 -0800 (PST) Date: Thu, 1 Feb 2018 09:45:28 +0900 From: Michael Paquier To: Alexander Stoddard Cc: pgsql-general@postgresql.org Subject: Re: Please help me understand unlogged tables Message-ID: <20180201004528.GA27440@paquier.xyz> References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="HcAYCG3uE/tztfnV" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --HcAYCG3uE/tztfnV Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Jan 31, 2018 at 10:52:38AM -0600, Alexander Stoddard wrote: > If a table is set to unlogged is it inherently non-durable? That, is any > crash or unsafe shutdown _must_ result in truncation upon recovery? Yes, they are designed like that. Upon recovery all unlogged tables are re-initialized. What happens internally is that their init fork files gets copied to become the one in use. > I can imagine a table that is bulk loaded in a warehousing scenario and > then sitting statically could be safe, but maybe the question becomes how > could the system know it is unchanged if it isn't logged... >=20 > Would a correct solution be to bulk load into an unlogged table and then > (fairly cheaply?) set the table back to being logged? Note that switching a table from unlogged to logged using ALTER TABLE generates a large amount of WAL, as you need to make this table's data consistent it is necessary to copy a full image of it. > If I my mental model is correct the table would be liable to being lost to > a crash during loading but once set back to logged it is durable. Is that > correct? Yes, ALTER TABLE makes that possible but be careful about the WAL generated because of the table rewrite. > Is it the case that setting a large table to logged status after loading = it > unlogged is a reasonably cheap operation? If you load a logged table the cost would be the same as switching it =66rom unlogged to logged. So what matters is how much operation is generated between the time you created the table, like random writes on it. For an initial load on a very large table, you could reduce wal_level temporarily to minimal, and make the WAL generated less painful. For a one-time load this can matter. -- Michael --HcAYCG3uE/tztfnV Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAlpyYygACgkQnvQgOdby QH3j/A/+Kq8rhbAYpmUyEf8p5XaOTszjy8+2NDQTtM29yKZQc79aO+u2/+yImHag yMAKDU/lurV6UNi0X+xPZDYKXct4Hyl4vPj8L8GCthMYXV0r2B2AZGcww8S/8Lqf 7/FusEY7GMM45SvQnsFJeW/gSgrDlhjJ1tcP8orxdVcywRNKx+x8Wchr6n9N0vqQ 8ZdI7iytH2DzTM3Zloo6YawL7wnsPWqp2yIJqiPFrBP58RIjOCtZVzHfOAme+xey RV/cb1JbDWITt7IzU7Seqry2G0/YHkSMz65+IhvlneNOT8lcJ/+Cj4J312lwOn0O yfmXtpod1frwOBSkw3gaL866Ti23PgAYuqaYwovQx/KEZqMiKQzXiRKx0sNzT/zE tN2BZQ7kU2kV0Ndkytr9iWre1817nTCv2PNaOPsUu/D6C4RIWw5IohD7mI8l8pSe bD4mAA4gAcKFkbqBTR2X0fUfGm4wFjOTkJkVpjZ5IfcniyVefV3+IoCtKI8DjvCn kCM/qhyRJKqL379QnyZ7Iiw6w6dSXCmoxJHZ2GYUDJF4b6ntE8Q0BaiYMCY7SXJP Vl5RZ9KL1IxXG/awnyS7bc9lA2ZsN7Lzft/15zQ+etEc6wlwry9F5lrIp56RTTmD tzexcFw+R9EtCmsq3///bgo/xYkAVAUfkW/Iyu/onsXgtR/O+TI= =Simb -----END PGP SIGNATURE----- --HcAYCG3uE/tztfnV--