Postgres: clear entire database before re-creating / re-populating from bash script

Posted by Hoff on Stack Overflow See other posts from Stack Overflow or by Hoff
Published on 2010-01-13T13:25:34Z Indexed on 2010/05/24 9:11 UTC
Read the original article Hit count: 310

Filed under:
|
|
|

hi folks,

I'm writing a shell script (will become a cronjob) that will:

1: dump my production database

2: import the dump into my development database

Between step 1 and 2, I need to clear the development database (drop all tables?). How is this best accomplished from a shell script? So far, it looks like this:

#!/bin/bash
time=`date '+%Y'-'%m'-'%d'`
# 1. export(dump) the current production database
pg_dump -U production_db_name > /backup/dir/backup-${time}.sql

# missing step: drop all tables from development database so it can be re-populated

# 2. load the backup into the development database
psql -U development_db_name < backup/dir/backup-${time}.sql

Many thanks in advance!

Martin

© Stack Overflow or respective owner

Related posts about database

Related posts about postgresql