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 1twjmR-00H6yv-G2 for pgsql-general@arkaria.postgresql.org; Mon, 24 Mar 2025 15:31:59 +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 1twjmQ-004xJF-2M for pgsql-general@arkaria.postgresql.org; Mon, 24 Mar 2025 15:31:58 +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.94.2) (envelope-from ) id 1twjmP-004xJ6-5V for pgsql-general@lists.postgresql.org; Mon, 24 Mar 2025 15:31:57 +0000 Received: from fout-b3-smtp.messagingengine.com ([202.12.124.146]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1twjmK-000teO-2i for pgsql-general@lists.postgresql.org; Mon, 24 Mar 2025 15:31:56 +0000 Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfout.stl.internal (Postfix) with ESMTP id 9BD371140092; Mon, 24 Mar 2025 11:31:50 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Mon, 24 Mar 2025 11:31:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm1; t=1742830310; x=1742916710; bh=yxzvjFDWSK/rddvhles1xcqfSSjwCTm0IhgLLIm1rWQ=; b= HpUyf5qoCN658+Nvx6RuwSwcHTTUDZRpUIPfBGhVKTRnlj3PpoK19VaR16GWzZEY zI9/FxTybQYP0+/yopUx2TjHrF9nm2tmbKRlIDPkah7hzS34jenAMd8Ikzx0nDCi Wj1C0RIEMpV27cGU6WyDmIBx1U1kW3sugNmZo78xdRqgVP0jOmg6gw29xG3FgK4e SHBKD1QgaQDXwSGfPW/dueoBDoyPgpt56BubAE9EA/0HLBRL8q8txWEvrfFuGUXg fDKyha5/qgOeT+ZonnqWvhMuY9WatlYtI1V92U5oIMhsbIY0PaN6BllNWJYJd1MR m35tcTcQGqFWQt3g23wrSg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1742830310; x= 1742916710; bh=yxzvjFDWSK/rddvhles1xcqfSSjwCTm0IhgLLIm1rWQ=; b=E n8FmY4Quxi11xTn0caXcsBiRLRhU5xDCweTyYTd8ViAhW62HAMOFxgZnONGYI6dw sdEB8SoKE11THL/FksqKB/YeCKiEnAuscj8QUo6jO2b5ZCYS9T83N8ogP9KNVO3l /Us550nAqim4kWx+xQn6vmYqFXzb0vxn3E1LZ6JBfu4BUDDM3vQ9dJ5vkyKQLvCZ hT+k7Crr54g43QofyEqlH6rhElw15LiAnkeexX1xcoIiq9FkAvFl4EyQllepZFNl jajzvSjVR8LWmS4eYibxsCfT77wnefzD9q+QwEh4g/Ehl0vXc6M9yCDw+sdIYr3V M2TNdjBrrA57HQJ/mJadA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdduiedtudefucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpih gvnhhtshculddquddttddmnecujfgurhepkfffgggfuffvvehfhfgjtgfgsehtkeertddt vdejnecuhfhrohhmpeetughrihgrnhcumfhlrghvvghruceorggurhhirghnrdhklhgrvh gvrhesrghklhgrvhgvrhdrtghomheqnecuggftrfgrthhtvghrnhepgfdufeekhfevfeel veeiueevhedvuddukeduvddvlefhueeuieejtdeuvdevvdeunecuffhomhgrihhnpehpoh hsthhgrhgvshhqlhdrohhrghenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhep mhgrihhlfhhrohhmpegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhmpd hnsggprhgtphhtthhopeefpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehjihhm ihhssehgmhigrdhnvghtpdhrtghpthhtoheplhgruhhrvghniidrrghlsggvsegthigsvg hrthgvtgdrrghtpdhrtghpthhtohepphhgshhqlhdqghgvnhgvrhgrlheslhhishhtshdr phhoshhtghhrvghsqhhlrdhorhhg X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 24 Mar 2025 11:31:49 -0400 (EDT) Message-ID: <832c1cdd-c0fe-464b-b4b9-f9d0482b9b78@aklaver.com> Date: Mon, 24 Mar 2025 08:31:49 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Experience and feedback on pg_restore --data-only To: Dimitrios Apostolou , Laurenz Albe Cc: pgsql-general@lists.postgresql.org References: <53760c70-4a87-a453-9e02-57abc9cb2e54@gmx.net> <455d28421ae33c73b73a6f527d2f72816ca5dd29.camel@cybertec.at> <5f1ebeda-f080-cb31-75c0-ce2211ea348f@gmx.net> Content-Language: en-US From: Adrian Klaver In-Reply-To: <5f1ebeda-f080-cb31-75c0-ce2211ea348f@gmx.net> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 3/24/25 07:24, Dimitrios Apostolou wrote: > On Sun, 23 Mar 2025, Laurenz Albe wrote: > >> On Thu, 2025-03-20 at 23:48 +0100, Dimitrios Apostolou wrote: >>> Performance issues: (important as my db size is >5TB) >>> >>> * WAL writes: I didn't manage to avoid writing to the WAL, despite >>> having >>>    setting wal_level=minimal. I even wrote my own function to ALTER all >>>    tables to UNLOGGED, but failed with "could not change table T to >>>    unlogged because it references logged table".  I'm out of ideas on >>> this >>>    one. >> >> You'd have to create an load the table in the same transaction, that is, >> you'd have to run pg_restore with --single-transaction. > > That would restore the schema from the dump, while I want to create the > schema from the SQL code in version control. I am not following, from your original post: " ... create a clean database by running the SQL schema definition from version control, and then copy the data for only the tables created. For this case, I choose to run pg_restore --data-only, and run it as the user who owns the database (dbowner), not as a superuser, in order to avoid changes being introduced under the radar. " You are running the process in two steps, where the first does not involve pg_restore. Not sure why doing the pg_restore --data-only portion in single transaction is not possible? > > Something that might work, would be for pg_restore to issue a TRUNCATE > before the COPY. I believe this would require superuser privelege though, > that I would prefer to avoid. Currently I issue TRUNCATE for all tables > manually before running pg_restore, but of course this is in a different > transaction so it doesn't help. > > By the way do you see potential problems with using --single-transaction > to restore billion-rows tables? COPY is all or none(version 17+ caveat(see https://www.postgresql.org/docs/current/sql-copy.html ON_ERROR)), so if the data dump fails in --single-transaction everything rolls back. > > > Thank you, > Dimitris -- Adrian Klaver adrian.klaver@aklaver.com