Wednesday 25 April 2018

PostgreSQL: Script to Tear Down and Recreate Database

I've used this as either a either PowerShell or Bash script when in a development environment. You'll need the postgres user's password. The .sql file is the file I keep in order to be able to generate the structure of my database (and seed it) in an empty database.

It connects as the postgres user to the postgres database, drops the specified database, if it exists, creates the new database, connects to the new database, and executes the schema & seed SQL file.

No comments:

Post a Comment