Skip to content

Instantly share code, notes, and snippets.

@rjdp
Created March 24, 2017 20:24
Show Gist options
  • Save rjdp/6ae9a0c204ee10aba7d2bd111ccc8495 to your computer and use it in GitHub Desktop.
Save rjdp/6ae9a0c204ee10aba7d2bd111ccc8495 to your computer and use it in GitHub Desktop.
# dump specific postgres schemas from database `mydb`
pg_dump -U postgres -nschema1 -npublic -npg_catalog -npg_toast -ninformation_schema -Fc mydb > mydb.dump
# after restoring above data move the table from the original schema to public schema
DO
$$
DECLARE
row record;
BEGIN
FOR row IN SELECT tablename FROM pg_tables WHERE schemaname = 'schema_primedomaincom'
LOOP
BEGIN
EXECUTE 'ALTER TABLE schema_primedomaincom.' || quote_ident(row.tablename) || ' SET SCHEMA public;';
EXCEPTION
WHEN others THEN CONTINUE;
END;
END LOOP;
END;
$$;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment