Sign up to create your own snipts, or login.

Public snipts » Fotinakis's snipts » Make copy and transfer entire PostgreSQL DB

posted on Jul 28, 2009 at 6:15 p.m. EDT in 
  • pg_dump -d prod_db -U prod_db -h localhost > /tmp/transferdump.sql
    
    psql -U prod_db_user -h localhost -t -d other_db -c "SELECT 'DROP TABLE ' || n.nspname || '.' ||
    c.relname || ' CASCADE;' FROM pg_catalog.pg_class AS c LEFT JOIN
    pg_catalog.pg_namespace AS n ON n.oid = c.relnamespace WHERE relkind =
    'r' AND n.nspname NOT IN ('pg_catalog', 'pg_toast') AND
    pg_catalog.pg_table_is_visible(c.oid)" >/tmp/dropothertables.sql;
    
    psql -d other_db -h localhost -U other_db_user < /tmp/dropothertables.sql;
    psql -d other_db -h localhost -U other_db_user < /tmp/transferdump.sql
    

    copy | embed

0 Comments

Sign up, or login to leave a comment.