title: PostgreSQL query/error logging for .sql scripts
body: <p>Here is the problem: I need to know how to get all PostgreSQL output from an executed .sql script to log to a file, including errors and query results.</p>
  
  <p>I have already surrounded my script with \o  and \o opening and closing tags, but this only logs the results of queries, which tells me nothing about what did and did not succeed.  I have tried piping the results of a call to to PostgreSQL using Unix tools like so:</p>
  
  <pre><code>    $~: psql &lt; filename.sql | tee &amp;&gt; filename.log
  </code></pre>
  
  <p>... with no success.  Filename.log in this case ends up completely empty.</p>
  
  <p>I don't want to activate universal logging, as I am only concerned with the success/failure of the scripts I have written and keeping a record of this for future reference.</p>
  
  <p>In Oracle, I used SPOOL, in MySQL I used TEE.  Both of these worked well enough for my needs, but \o does not have this functionality, and neither does activating logging, as this logs to a single file and I want my logs separated based on which file resulted in those logs.</p>
  
  <p>Any help would be appreciated.</p>
  
  <p>EDIT: the version I am using is 9.1</p>
  
  <p>EDIT: The problem I am having is that using -f and using &lt; to execute .sql files gives me essentially the same results; it doesn't log the errors, it only logs query results.  I need to somehow get stderr (if that's what is used) to print it's messages to a file and not just the command line such that the file will essentially look identical to the command line results of running the file, with query results and errors mixed in.  The reason I need to do this is because it makes debugging a .sql file much easier and it allows me to keep targeted records while avoiding universal error logging.</p>