Postgres command line

less than 1 minute read

I find the postgres command line tools slightly annoying to use, so I wrote pg.

With it, I can run commands in a more natural way. For instance:

$ pg list

List databases (same as psql -l), or with –short, prints only their names.

$ pg drop db_name

Drops a database. The only difference between this and dropdb is that it always uses --if-exists.

Or more interesting things:

$ pg mv origin target

Rename a database after killing all connections to origin.

$ pg copy origin target

Creates a “copy” of a database after killing all connections to origin. I use this to create fast snapshots that I can go back to later, much like version control.

These are very simple wrappers around createdb, psql etc, but since I was starting to repeat myself a lot, I decided it was worth it.

You can find the code on github, along with tests, yes.

Comments