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 1twk8A-00HBuh-C5 for pgsql-general@arkaria.postgresql.org; Mon, 24 Mar 2025 15:54:26 +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 1twk89-005VIN-29 for pgsql-general@arkaria.postgresql.org; Mon, 24 Mar 2025 15:54:25 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1twk5S-005Ow4-AE for pgsql-general@lists.postgresql.org; Mon, 24 Mar 2025 15:51:38 +0000 Received: from mout.gmx.net ([212.227.15.18]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1twk5Q-000spW-1R for pgsql-general@lists.postgresql.org; Mon, 24 Mar 2025 15:51:37 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.net; s=s31663417; t=1742831491; x=1743436291; i=jimis@gmx.net; bh=QjJxOuRu92/fHB/qAF0/G4FIEO8I+gShieAssQ4JNWA=; h=X-UI-Sender-Class:Date:From:To:cc:Subject:In-Reply-To:Message-ID: References:MIME-Version:Content-Type:cc:content-transfer-encoding: content-type:date:from:message-id:mime-version:reply-to:subject: to; b=NCaB1PL7MFSeZ08EO8jyUtvhp509xfC9WJTkNogWtXZ4MyvcafUrCn63wh2Xr5li WBjYLbKq5fflUqNrpOI1I8+UxcN3mqWEpgORWKfIVpJOmyUVSu9ZDXKAMcmGiP5HL XHzDPE50lkt1ObM5PlnxWcwZCz8OVp3A/bh0z6jpJNlRoOfT2Xu6ZSb/sGC4OrzKv VSsxZpmdZXOOvihGYeEdJEqpQ/IgwOBOuYVkFeuXuqhuLYeZUKqEEK1r7aOMUuZmz MlWWSJKi352o+UYliThtvGK6iyiuTNKWpcQXHlB0aSJmQGbZ0P8rqfUMgTk/WUs5c /bVm9hRi3HcIm9SZEQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [10.9.70.81] ([185.55.106.54]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MgeoI-1tVLpP20dw-00bKTD; Mon, 24 Mar 2025 16:51:31 +0100 Date: Mon, 24 Mar 2025 16:51:30 +0100 (CET) From: Dimitrios Apostolou To: Adrian Klaver cc: Laurenz Albe , pgsql-general@lists.postgresql.org Subject: Re: Experience and feedback on pg_restore --data-only In-Reply-To: <832c1cdd-c0fe-464b-b4b9-f9d0482b9b78@aklaver.com> Message-ID: <7e990eae-e55c-0d04-1be8-f49bb3251073@gmx.net> References: <53760c70-4a87-a453-9e02-57abc9cb2e54@gmx.net> <455d28421ae33c73b73a6f527d2f72816ca5dd29.camel@cybertec.at> <5f1ebeda-f080-cb31-75c0-ce2211ea348f@gmx.net> <832c1cdd-c0fe-464b-b4b9-f9d0482b9b78@aklaver.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="0-1272647902-1742831491=:1515035" X-Provags-ID: V03:K1:m4dxgIWw0Ddsx52MlRPAp82X2ISswaGMyjEdkIi0YhQHSA/vERP eYLNkbwcbOlsPb21FjGb7JFdDzXZhdgWjMCUKQKWXlf11RxLo86hIwD7tMJVavLhgmSfhNN DcOYbUmahekbCcHiPFufBrGU7N4gc7lQT2taI5mF5RKlWYHmKfK+TE0GxoZmPfXaEJPRd9N Xlz71hzrh7VIHSwWP8WSQ== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:y95aa+ws8Mc=;VMnXMCq9SnykLRk4NKmwRtGCBOr BniIqa/4MOnigXPmm6S2inaL1QtR+r9xxtFECxlid8K4cOCkxeLDCkHfSZ7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cFKpjM5KqhNr xOqaC7XUwE+jXF7YRhZgB1RY1qcuKN7XxsUzDBX0dSF9lvkK/jw0lhu88Od6zm77A2Ua6XnQE yNimu0eH8butIyEiVvWkLXv1dIZ/9qXHK7a3m2woAdw82cB3CY341/i5H/Y2OGOo2Jt60dhai BzpS4a6uEyp5Ysoi/7dtbrtwFP6IY8+dxueAsDVlJTFAJN766JnyPgvX0mDzjwkU84srF14O3 A4BAFFlPRVV2jw2xv49rJ7l/Knq/pFVVvNDlpAxPu5dr2ZTYkft3dMxIKLx7UjzRe+xoRoZu/ jUkA9wQ== List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --0-1272647902-1742831491=:1515035 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable On Mon, 24 Mar 2025, Adrian Klaver wrote: > 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 >>>> =C2=A0=C2=A0 setting wal_level=3Dminimal. I even wrote my own functi= on to ALTER all >>>> =C2=A0=C2=A0 tables to UNLOGGED, but failed with "could not change t= able T to >>>> =C2=A0=C2=A0 unlogged because it references logged table".=C2=A0 I'm= out of ideas on >>>> this >>>> =C2=A0=C2=A0 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 th= e >> 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 invol= ve > pg_restore. Not sure why doing the pg_restore --data-only portion in sin= gle > transaction is not possible? Laurenz informed me that I could avoid writing to the WAL if I "create and load the table in a single transaction". I haven't tried, but here is what I would do to try --single-transaction: Transaction 1: manually issuing all of CREATE TABLE etc. Transaction 2: pg_restore --single-transaction --data-only The COPY command in transaction 2 would still need to write to WAL, since it's separate from the CREATE TABLE. Am I wrong somewhere? >> Something that might work, would be for pg_restore to issue a TRUNCATE >> before the COPY. I believe this would require superuser privelege thou= gh, >> that I would prefer to avoid. Currently I issue TRUNCATE for all table= s >> manually before running pg_restore, but of course this is in a differe= nt >> transaction so it doesn't help. >> >> By the way do you see potential problems with using --single-transacti= on >> 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. So if I restore all tables, then an error about a "table not found" would not roll back already copied tables, since it's not part of a COPY? Thank you for the feedback, Dimitris --0-1272647902-1742831491=:1515035--