Added some logging and exception handling 

...and ensuring that any DB connection is closed.  I'm not sure if you would like this, but I thought I would file a PR anyway (I'm not a big time Ruby dev either).  The gist is to just add some additional debug logging and attempt to ensure a DB connection is closed if it exists (perhaps in cases where the SQL is incorrect...maybe there is something about the pg gem or fluentd that I am missing).