Re: feature request: pg_restore renaming target schema

From: CN <cnliou9(at)fastmail(dot)fm>
To: pgsql-admin(at)postgresql(dot)org
Subject: Re: feature request: pg_restore renaming target schema
Date: 2015-12-22 16:19:14
Message-ID: 1450801154.79237.474120345.758EF3FA@webmail.messagingengine.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

I am pleased to revoke this request.

Once option -O is applied to pg_dump, only two lines in the dumped file
need to be edited.

In case it is also useful to anyone, here is the script I use to dump
schema "ss" from source database "sd" and restore as new schema "ts" to
database "td". Hard disk is not used as intermediate file is not
created. I have a feeling that it is safe to run this script
concurrently.

#!/bin/sh
SOURCE_DATABASE=sd TARGET_DATABASE=td TEMPLATE_SCHEMA=ss NEW_SCHEMA=ts
pg_dump -O -E utf8 -n $TEMPLATE_SCHEMA -w -U postgres $SOURCE_DATABASE
2>&1 | awk -v source="$TEMPLATE_SCHEMA" -v target="$NEW_SCHEMA" ' BEGIN
{ pattern1="CREATE SCHEMA " source ";"; pattern2="SET
search_path = " source ", pg_catalog;"; pattern1_is_done=0
pattern2_is_done=0 is_data=0; print "BEGIN;"; #Wrap all
statements in single transaction. } { if(!is_data){
if(substr($0,1,2) == "--") $0="";
else if(!pattern1_is_done){ if($0 == pattern1){
$0="CREATE SCHEMA " target ";";
pattern1_is_done=1; } }
else if(!pattern2_is_done){ if($0 == pattern2){
$0="SET search_path TO " target ";";
pattern2_is_done=1; } }
else if(match($0,/^COPY .+ FROM stdin;$/) > 0)
is_data=1; } print } END{ print "COMMIT;";
#Wrap all statements in single transaction. } ' | psql -q -o /dev/null
-w -U postgres $TARGET_DATABASE 2>&1 vacuumdb -q -Z -w -U postgres
$TARGET_DATABASE 2>&1
>

--
http://www.fastmail.com - The professional email service

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Jim Nasby 2015-12-23 02:32:57 Re: Connections "Startup"
Previous Message Rick Otten 2015-12-22 11:36:34 Re: Connections "Startup"