Improving the Command-Line Postgres Experience
robots.thoughtbot.com
robots.thoughtbot.com
I'm largely new to PostgreSQL and it is quite possible that I'm using it all wrong, sorry for ranting.
Also, dropdb, createdb, postgres, pg_ctl, initdb, pg_basebackup. No consistency.
EDIT: There was a discussion and a patch 5 years ago, but I am not sure what was the final result other than that it was obviously not changed.
http://www.postgresql.org/message-id/47EA5CC0.8040102@sun.co...
I tend not to use the CLI though as anything that presents a readline interface is a POS to work with when you have a verbose statement to type in. I'll type it out in VIM then throw the buffer through psql.
I wouldn't run anything on OSX bar some Cocoa apps myself. Same with Windows. Everything Unixy happens inside a virtual machine. I don't care if OSX is Unix certified or Windows has cygwin - they're both a pain to deal with on a daily basis.
My only issue with this workflow is when I want to yank the command out to the clipboard. For some reason it doesn't seem to respect clipboard settings on OS X.
\pset pager
\pset null 'NULL'
\timing
\encoding unicode
SET search_path=public,postgis
The first line turns off paging, since I dislike how paging causes previous queries/results to disappear after I press q.The second line is like the article's.
`\timing` shows how long each query took to run.
I honestly don't remember why/if `\encoding unicode` was necessary. Playing nice with my terminal? Writing to a file with `\o`?
The `search_path` line is because I often install PostGIS objects in a `postgis` schema, and this lets me reference them without a prefix. If there is no `postgis` schema I get a warning when I start psql, but that's no bother to me.
export PAGER='less -S'
export EDITOR='emacs -nw' #or a lesser editor if you prefer
That way you'll get result sets without linewraps and your queries will be edited in the non-default editor, which is `vi` in most distributions.I spend most of my time in emacs doing things in python, sql or what have you. Usually the only time I talk to a production database directly is when it's already in trouble.
And yes; one's migrations and DDL etc. should all be tested before being rolled out to production; apparently that is not an assumption people make around here.
https://github.com/TylerBrock/mongo-hacker
I found that adding color to the JSON output helped newcomers differentiate the data types and understand the structure of the data models more easily.