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 1mB3B0-00020U-OO for pgsql-general@arkaria.postgresql.org; Tue, 03 Aug 2021 22:46:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mB3Az-0007XF-2S for pgsql-general@arkaria.postgresql.org; Tue, 03 Aug 2021 22:46:21 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mB3Ay-0007X6-Pg for pgsql-general@lists.postgresql.org; Tue, 03 Aug 2021 22:46:20 +0000 Received: from mail.hjp.at ([212.17.106.138] helo=rorschach.hjp.at) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mB3Av-0006WZ-0M for pgsql-general@lists.postgresql.org; Tue, 03 Aug 2021 22:46:19 +0000 Received: by rorschach.hjp.at (Postfix, from userid 1000) id 623C2500A; Wed, 4 Aug 2021 00:46:15 +0200 (CEST) Date: Wed, 4 Aug 2021 00:46:15 +0200 From: "Peter J. Holzer" To: pgsql-general@lists.postgresql.org Subject: Re: pg_restore (fromuser -> touser) Message-ID: <20210803224615.GB3138@hjp.at> Mail-Followup-To: pgsql-general@lists.postgresql.org References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="4bRzO86E/ozDv8r1" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --4bRzO86E/ozDv8r1 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2021-07-27 09:43:45 +0800, Ben Madin wrote: > Hi - we have had to do such operations quite commonly, if you want to aut= omate > / stream such a change I would suggest that you look into sed. Off the to= p of > my head, consider something like this: >=20 > pg_dump --format=3Dp --schema=3Dschema_a original_database | sed 's/ sche= ma_a./ > schema_b./g' | psql new_database >=20 > this is presuming a space before the schemaname, and a fullstop between s= chema > and other=A0elements. Actually the "." in a regular expression matches any character, so this will also replace e.g. " schema_a5" with " schema_b.". This is easily fixed (just add a backslash), but more importantly, it will replace that string everywhere, regardless of context. This might lead to syntax errors or data corruption. hp --=20 _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp@hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" --4bRzO86E/ozDv8r1 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAmEJxzEACgkQ8g5IURL+ KF1RIw/9ETlo8RHVzTh+8l3lqHYerZol4Ev/OO3Pqy/+Swk+DAHDvgxG73n4b0RW AAQLCHOZe+6LzW/HHaR6ZNd8w7DBizVBaQF0vxFcGe8G137/xXKMXTH9lEKgAX9F SPTRlcqruwrysxUcYKWIWG0JPtunNPMDKEYEqg/Fd1iasiBVGAoRxUN3///mrENm 75/c6o0XvjJ24j3Kvf6vAxG045WRvwGl6zsP8yUZS+T1yBmP41p9kInoQsV6j2wN xCQyv4M2sv8cOAccjqqfnhj1vpwHiEkhSzb8W7ie4wAzujMDwmwhAZhXBlweGiBO NZsC5fwrduvPF2HB93BqHFsL9WfFvjFXbTBDv19Wk8ODzjNyWUfPM4HqC4kfa+8K l0jHRRsvfIrpoFXk1uqA1hM+IzgFjwU/seROd+JA1A5nIPQyEKyUq8zFwJzGzFA/ SFVOLQRSyQi6USEbLjqcTQmHnWYFmRZ6kOw0n+yCJOIQNWIUaiFi6UaaApTM6Uuy DpC9oDg2sUM/EZE0rJ7WpGpU4n3OpxOuSq61HRmY1aKQ0hj/UeZOagIh3pn9pMJq dChYff478eMGNdPVNY+pcuPNe0w7aVb98AEmq4u1qYe0TAGkL+gMnIBW1iQlLHb4 YXRooGLB0FzHdwSBgvUVAaBzADc+cgD1P3XntsgMwM8RaDP3CNw= =KjWG -----END PGP SIGNATURE----- --4bRzO86E/ozDv8r1--