Skip to content

Instantly share code, notes, and snippets.

@fragoulis
Created June 10, 2014 13:50
Show Gist options
  • Save fragoulis/64faebfb932b6a383b7f to your computer and use it in GitHub Desktop.
Save fragoulis/64faebfb932b6a383b7f to your computer and use it in GitHub Desktop.
Postgres dropdb/createdb alternative when there is no maintenance database available to connect to
set PGPASSWORD=password psql --host=host --username=username --command="drop schema public cascade;create schema public;" database
@fragoulis
Copy link
Author

I was using dropdb and createdb to recreate a whole database whenever I needed to do a complete clean up for my under development project.

I came across a situation where I was not able to connect using the (default) maintenance database (which is template1 in 9.2, for more read here). So to make drop/create work without the maintenance database I had to improvise. I connected to the database I wanted to drop, and I dropped/recreated the public schema instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment