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 1lwiJa-0006Th-GJ for pgsql-general@arkaria.postgresql.org; Fri, 25 Jun 2021 09:39:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lwiJY-0006AU-U5 for pgsql-general@arkaria.postgresql.org; Fri, 25 Jun 2021 09:39:56 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lwiJY-0006AM-KP for pgsql-general@lists.postgresql.org; Fri, 25 Jun 2021 09:39:56 +0000 Received: from mout.gmx.net ([212.227.17.22]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lwiJW-0008MA-O5 for pgsql-general@lists.postgresql.org; Fri, 25 Jun 2021 09:39:56 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1624613988; bh=Nl96YLp4r8+UZCbD+BMuyKuFlZwq+KIdkBCVgWwmwYY=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:References:In-Reply-To; b=jdSN9SZDf5LsrUjgFtwS2L5ME5/tJt0P6otA0ryfjDbw6wV+kmPcldmbcTWomgE2q rW+fN+w4t5BtLQQjNBNkENvnC8gLF5HRADQMmDYAmu0YHEWmaXjuxi/+wTrxShA4Ru 0jp6qbBiwMqNM+SmvXbuSEik+PA1z27OYpOkbRoE= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from hermes ([89.12.104.25]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1N4Qwg-1lE3s22NZW-011UkA; Fri, 25 Jun 2021 11:39:48 +0200 Received: from ncq by hermes with local (Exim 4.94.2) (envelope-from ) id 1lwiJO-000761-3s; Fri, 25 Jun 2021 11:39:46 +0200 Date: Fri, 25 Jun 2021 11:39:46 +0200 From: Karsten Hilbert To: Adrian Klaver Cc: Tom Lane , pgsql-general@lists.postgresql.org Subject: Re: pg_dump/pg_restore vs default_transaction_read_only under PG 13.2 Message-ID: References: <1511776.1624211267@sss.pgh.pa.us> <3d842ba4-13c1-cd95-8ef9-b69a06eeb6c1@aklaver.com> <002748a5-5258-26b4-a7b4-d8f15c914d5c@aklaver.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <002748a5-5258-26b4-a7b4-d8f15c914d5c@aklaver.com> Ma_X_il-Followup-to: d Re_X_turn-receipt-to: Karsten.Hilbert@gmx.net Di_X_sposition-Notification-To: Karsten.Hilbert@gmx.net X-Confi_X_rm-Reading-To: Karsten.Hilbert@gmx.net X-Pri_X_ority: 2 (High) Sender: X-Provags-ID: V03:K1:RgGTEIxi7NiDD3XN0ra8pfeDAifYnHnmuLlaBIZLRk5qwBr/V3t ZG6gEwWx9IvTmXcXM4uus0J5icO7MavtQsC04vBPejTK9cTEFSsDGAPsiitCSJ6wJdA5jxw X7DFvjsR3UafuWr9rMgMT3LGj0XUGMN0Blj+cSzcPTlu6ihf2evkRXiu7NnbprlleKAlZLN yFOMKqCmAnLZwG8nePjIA== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:EA0WVjyrO30=:C9yAepdg6IZKsWtQc2mZlo gMDGTx+w2NPU4SM0VCay8DNd8d0MpoZUThtNTB3dHIUEmrkKbSfcP+JwYVEKLPbD9z599ZicV 8FSLcbxCfGQphdBkCoNetl+1dvf/Rm0i1nX7L5W+tZWT6xdKAhPU1YFyU95byfpLjgoG7pgoO 1dALPFkGxa5wfRwsTo90M8XrcjWlBldRKWPZUJvgALPVHX1xtrfG5QG8SV5wdzqK4i5YX4K7i 86LYt67USYjFYSCsh/Y6+LVk4nMiPwaX5mE3Xb/t1epcnjMDkYhqRfYKpnI0wvPNSLh9PpAif HB1TWB2GpgbLcJxUURzBsL90fVHHa981LQ+Pzf/Mf1rbu8FI30NHSctSMjdbAKW/InnkqIAO7 jn0nrw4b8Ucn2BOOQJljHl4HpxpRt0HpOfYIY4Kqipn4d11ansKZ0GXIs0Bre/tG+xzRhzFko f8AsM7fEZKngkmceLw3K91HGF98bYJY2vxrEK7MKzMiMwiiyDN2JC5M7Nlx5MJFhUCIsyQAYW 1mMbwUk4SME9K9Hwx8RyRTkLddjwcvg7nuOXWLvwAak3QjKHQZqOBhBNVjvauLO1HHQap0Fs4 mpR+rf/IMckg5cfQDB30VBZKlv0DmFBdTJzINrgprVpOX0niSal7q0yFJ3r/JTgafxHC3tMhW 2divrZF6t+mC3zXyOIP6TGahUvssgytzNSzXxqmbNJqKvKlJ8FOv3rMdEWeEry1yzV/PC29dY y6BvyPeuHPpyu7QZAADFBmZ5zLh+6GdMoK92NZDECry1FxZoHKSpsNu178JnoP+nfBWwNn4gw Jl3vEDD9gVM/jwwEFjOOtYJZBJB4R6YDQvK84cO/htEYLchmxzhagjByGiwb33m9oiYNM06n2 jPt0FuDb9SJWELnhArRqay6G+Q4MVzPlaSTkoGNEKAVlAlGoYgKqEl5o+0lDuy0HNlBjWarV/ gDshC15OPs3pGv5CKoZ/IAilUZyBQERsKMklVMR44EpiO7uxQOeNW3IMHt5Sbg2w4dEAb7Cbi 0J4biYvP+izEHjiF/4lGzD7Xw+yW/Ybv6c6K7MuBO3SlX4C6dGlBImsK68U/ve1pGQjneU4l+ j+Zxnsp3nsp3atLTbczfdG29fqVjEUYA5/FFnTjlvngZ6v5zu2ummzJqA== Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > >And this is the restore: > > > sudo -u postgres psql -d postgres -f create_database.sql > > sudo -u postgres pg_restore --verbose --create --dbname=3Dtemplate1 --= exit-on-error -p ${GM_PORT} ${BACKUP}.dir/ > Remove --create and change dbname to the database name from crea= te_database.sql > > sudo -u postgres psql -d -f alter_database.sql > > At this point version 14 is past the point of adding new features and 15= is 1+ year out, > so there is going to have to be some sort of kludge. I know. I was asking in principle, whether a felt-to-be-more-proper change in pg_dump/pg_restore for handling default_transaction_read_only can be hoped to happen or not (short of submitting a patch). For the record: The kludge I have implemented now is this CMD_PG_RESTORE=3D"pg_restore --create --file=3D- ${BACKUP}.dir" CMD_PSQL=3D"psql --echo-errors --dbname=3Dtemplate1 --port=3D${GM_PORT} -= -no-psqlrc" CMD_SUDO=3D"sudo --user=3Dpostgres" { ${CMD_PG_RESTORE} | grep --ignore-case --invert-match --regexp=3D"alter = database ${TARGET_DB} set default_transaction_read_only to.*on" - | ${CMD_= SUDO} ${CMD_PSQL} } &>> "${LOG}" which I am sure can be improved (such as, I was unable to get the quoting right for factoring out the grep from the pipeline :-) I would be happy to hope that pg_dump might gain knowledge to skillfully emit alter database ... default_transaction_read_only to 'on' only after having emitted any data-loading statements or else gain a --do-not-alter-database-to-read-only effectively omitting said statement thereby allowing for a more elegant treatment of the issue. Best, Karsten =2D- GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B