# #YOU WILL NEED: # A database dump DUMP_FILE_DIR=/tmp/ ORIG_DUMP_FILE=$DUMP_FILE_DIR/playdb DUMP_FILE=$DUMP_FILE_DIR/my_dump_file #Pick a directory, any directory for the db to live in. # I reccommend one the is not under version control # I typically create a new one called 'databases', then create a 'data' # directory under it. DB_DIR=$HOME/test_db # # Replace "postgres" with your username sed "s/postgres/$USER/g" $ORIG_DUMP_FILE > $DUMP_FILE #make the directory for our db to live in. mkdir -p $DB_DIR/data #Create a postgres (pgs) db cluster initdb -D $DB_DIR/data #Start postmaster pg_ctl start -D $DB_DIR/data -l$DB_DIR/db_log_file sleep 5 #Create database within this cluster cd $DB_DIR/data createdb production-pgs cd - #Create common user in each database (or just the one created above) psql -c "CREATE USER pgsqluser" production-pgs # -pgs responds with the command or reason for failure. #Load the database(s) echo "loading production database with $DUMP_FILE" psql -f $DUMP_FILE production-pgs sleep 1 echo " " #Stop postmaster echo "Automatically shutting down the database. An alias has been added to " echo "your profile for restarts. You will be able to restart it with the " echo "start_test_db command. Similarly, stop_test_db should stop it." pg_ctl stop -D $DB_DIR/data #The next time that postmaster is started, all should be well. #NOTE: # Use start_test_db to restart database when needed. if test "`grep start_test_db ~/.profile`" = "" then echo "alias start_test_db=\"pg_ctl start -D $DB_DIR/data -l$DB_DIR/db_log_file\"" >>~/.profile echo "alias stop_test_db=\"pg_ctl stop -D $DB_DIR/data\"" >>~/.profile alias start_test_db="pg_ctl start -D $DB_DIR/data -l$DB_DIR/db_log_file" alias stop_test_db="pg_ctl stop -D $DB_DIR/data" fi