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 1eq4c4-0001lU-8L for pgsql-general@arkaria.postgresql.org; Sun, 25 Feb 2018 22:17:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1eq4c2-0004eh-Mw for pgsql-general@arkaria.postgresql.org; Sun, 25 Feb 2018 22:17:42 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eq4c2-0004eY-EJ for pgsql-general@lists.postgresql.org; Sun, 25 Feb 2018 22:17:42 +0000 Received: from mout.gmx.net ([212.227.17.21]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1eq4by-0007LL-A3 for pgsql-general@lists.postgresql.org; Sun, 25 Feb 2018 22:17:41 +0000 Received: from hermes ([84.165.100.165]) by mail.gmx.com (mrgmx102 [212.227.17.168]) with ESMTPSA (Nemesis) id 0Mcgur-1f7Ss23eRl-00HxUd for ; Sun, 25 Feb 2018 23:17:36 +0100 Received: from ncq by hermes with local (Exim 4.90_1) (envelope-from ) id 1eq4bu-0005px-6V for pgsql-general@lists.postgresql.org; Sun, 25 Feb 2018 23:17:34 +0100 Date: Sun, 25 Feb 2018 23:17:34 +0100 From: Karsten Hilbert To: pgsql-general@lists.postgresql.org Subject: Re: pg_dumpall SET default_transaction_read_only = off (was Re: == PostgreSQL Weekly News - January 28 2018 ==) Message-ID: <20180225221733.GI1932@hermes.hilbert.loc> References: <20180129025748.GA5084@fetter.org> <20180225172827.GD1932@hermes.hilbert.loc> <15692.1519593641@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="ew6BAiZeqk4r7MaW" Content-Disposition: inline In-Reply-To: <15692.1519593641@sss.pgh.pa.us> 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) User-Agent: Mutt/1.9.3 (2018-01-21) Sender: X-Provags-ID: V03:K0:9XIkzdifzHNO6MaWj0cmzwIHzTB+45B7Pmi3sGt9vy8a5zDHEBO HItk0TSuxHnu3tkaT8WisnBmlYFPIOw+ZgSdtYCwk9N+zGqxGnQOxzoHe2cvd1ultQCciNm nzAYxd3Xya5G0ldEPfz6KjCOTuZUY7/XyaJmjrKy8x1yzlyaFFknSJ5DsF67a76VmKGnX+P vfg1c3/dV67Ok59pndojA== X-UI-Out-Filterresults: notjunk:1;V01:K0:+U9FUVvyW3E=:L4pvPIcHI9byn0jcAbU0GI gmG1Hi51Iu9Zb9FX0+/756n1R04ft6lJTp45SdFBFqH1z6dhrde7GK0psqo3hDQiMVWFWG6Wt F4nylebw6DpV26ac9MmuDfp3cR++e9JYSGlas9b4fZWKWwGeirdyzNUYRsSmqDi034gq5gLYp KJopt572j6gBU7geVjuL78uS4OtykavH4f3Mvmr85MjJmJLZwLwW8dicRsIULZTCAHnF6GkLS mOHeLpCaPzkRZCV85PgngvO7yl7Q5T/e0+YanyxSSUo+miZMXrgF4L0xL2uL5Y8/rb7hXS77K R83yUKRo+z/khYov2RA8O+IhVfOUupRB9c+kGutJ+KOd8S8TIU61roxEKCq9iFeqx/ALuufl8 +BGfPAWyMPYGURBAGpN4gxyF09S1qSJRCm+sKC2louCFySaFDxzHAU/LcNffTaxZXuwyPb6+/ HDzk7nDBtH68HOnZfIl0ZlssOq1Ud4855uMa0o95ptDrK/sotXEO4+otb+DFYXGfX31drQ/q0 BN9YxLPT3uDkOwEYcXAm8IZ5l6+ZkmBizStGtxgmruaoj1N+YDOX7ucPtRT8c1sEWWGmFotBv Z47qnhDpI8x1ENEbcJwkwtnwrQeCasFUnOLv3P/2nSYqOuDWHnwYs7nmbeJyHfP9wX4SAVJUm lGeRHsaHGX9zWWkBJtzqu9+Wis+rgwvN99DfpvZYRH6FDsNt9VlFMgUQuG3CCZWN6yLiijDn6 +QYCEB6//qiXcx/FtH5T7fUKkBi+ye891RXUZpK6YcXoZ1eK/zb+gcOhuINDZV5Swu85oLStQ 0Ve1ojOeOxldVd1oUfj6Ei/JU2h/w== List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --ew6BAiZeqk4r7MaW Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Sun, Feb 25, 2018 at 04:20:41PM -0500, Tom Lane wrote: > No; you're reading the commits in reverse order. The hack I thought we > could use to preserve that behavior didn't work. > > AFAICS, the only way we could maintain something like the old behavior > here is to promote it to a full-fledged feature, something like a > pg_dump/pg_restore option "--ignore-read-only" to make those programs > issue "SET default_transaction_read_only = off" at the right times, > which in turn would need to be invoked by a similar pg_dumpall switch. ... > While that doesn't seem like it would be terribly hard to do, I don't > personally have the interest to go do it. OK, I see. Luckily, pg_upgradecluster allows running custom snippets at appropriate times during the upgrade: HOOK SCRIPTS Some PostgreSQL extensions like PostGIS need metadata in auxiliary tables which must not be upgraded from the old version, but rather initialized for the new version before copying the table data. For this purpose, extensions (as well as administrators, of course) can drop upgrade hook scripts into /etc/postgresql-common/pg_upgradecluster.d/. Script file names must consist entirely of upper and lower case letters, digits, underscores, and hyphens; in particular, dots (i. e. file extensions) are not allowed. Scripts in that directory will be called with the following arguments: Phases: init A virgin cluster of version new version has been created, i. e. this new cluster will already have template1 and postgres, but no user databases. Please note that you should not create tables in this phase, since they will be overwritten by the dump/restore or pg_upgrade operation. finish All data from the old version cluster has been dumped/reloaded into the new one. The old cluster still exists, but is not running. Failing scripts will abort the upgrade. The scripts are called as the user who owns the database. which will allow solving the problem with something like the attached sript. Karsten -- GPG key ID E4071346 @ eu.pool.sks-keyservers.net E167 67FD A291 2BEA 73BD 4537 78B9 A9F9 E407 1346 --ew6BAiZeqk4r7MaW Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=gm-pg_upgradecluster-helper #!/bin/sh #============================================================== # # This script modifies the GNUmed databases such that an # upgrade using Debian's may succeed. # # Drop this file into /etc/postgresql-common/pg_upgradecluster.d/ # if you are using a postgresql-common package < v122 on Debian # and want to upgrade your cluster using . # # Note that pg_upgradecluster will run this as user . # # author: Karsten Hilbert # license: GPL v2 or later #============================================================== DB_VERSIONS="2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20" #============================================================== # There really should not be any need to # change anything below this line. #============================================================== # read data from pg_upgradecluster API OLD_VER="$1" CLUSTER_NAME="$2" NEW_VER="$3" PHASE="$4" # appropriate phase ? if test "${PHASE}" = "init" ; then echo " - removing readonly attribute from GNUmed databases..." ACTION="off" elif test "${PHASE}" = "finish" ; then echo " - re-adding readonly attribute to GNUmed databases..." ACTION="on" else echo "INVALID pg_upgrade PHASE: <${PHASE}>"; exit 1; fi # setup files TS=`date +%Y-%m-%d-%H-%M-%S` SQL_FILE="/tmp/gm-pg_upgradecluster-helper-readonly_${ACTION}-${TS}.sql" LOG_FILE="/tmp/gm-pg_upgradecluster-helper-readonly_${ACTION}-${TS}.log" # create SQL script echo "\\unset ON_ERROR_STOP" > ${SQL_FILE} for DB_VER in ${DB_VERSIONS} ; do echo "" >> ${SQL_FILE} echo "BEGIN;" >> ${SQL_FILE} echo "ALTER DATABASE \"gnumed_v${DB_VER}\" SET default_transaction_read_only TO ${ACTION};" >> ${SQL_FILE} echo "END;" >> ${SQL_FILE} done # get port of OLD cluster as suggested by pg_upgradecluster maintainer CMD="use PgCommon; \$p = get_cluster_port \"${OLD_VER}\", \"${CLUSTER_NAME}\"; print \"\$p\\n\"" PORT=`perl -I/usr/share/postgresql-common/ -e "$CMD"` # run SQL script against OLD cluster echo "Accessing port: ${PORT}" > ${LOG_FILE} 2>&1 psql -p ${PORT} -f ${SQL_FILE} >> ${LOG_FILE} 2>&1 # also run it against NEW cluster on finish if test "${PHASE}" = "finish" ; then CMD="use PgCommon; \$p = get_cluster_port \"${NEW_VER}\", \"${CLUSTER_NAME}\"; print \"\$p\\n\"" PORT=`perl -I/usr/share/postgresql-common/ -e "$CMD"` echo "Accessing port: ${PORT}" >> ${LOG_FILE} 2>&1 psql -p ${PORT} -f ${SQL_FILE} >> ${LOG_FILE} 2>&1; fi exit 0 --ew6BAiZeqk4r7MaW--