Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

My OS is RHEL5.

I want to direct the console output produced by the following database command to a log/file.

psql mydb mydbuser -c "VACUUM ANALYZE VERBOSE"

I've tried out the following commands and is not working as expected. But it is printing output to the terminal console instead.

psql mydb mydbuser -c "VACUUM ANALYZE VERBOSE" > vacuum.log
psql mydb mydbuser -c "VACUUM ANALYZE VERBOSE" | tee vacuum.log

Here, in this case, is not the output produced by this command a standard input/output/error?

NOTE: psql is a terminal-based front-end to PostgreSQL. It enables you to type in queries interactively, issue them to PostgreSQL, and see the query results.

share|improve this question
up vote 3 down vote accepted

Redirect stderr as well.

psql mydb mydbuser -c "VACUUM ANALYZE VERBOSE" &> vacuum.log
share|improve this answer
@Ignacio: Thanks, that's working perfectly as expected. Actually, I'm not a Linux expert, for me to understand this better, & is the stderr and > is standard output? – Gnanam Sep 1 '10 at 10:13
> is stdout, 2> is stderr, &> is both. – Ignacio Vazquez-Abrams Sep 1 '10 at 10:37
@Ignacio: Thanks again. Can you share with me some useful resource about Linux redirection operators? – Gnanam Sep 1 '10 at 10:52
@Gnanam: Also, the Bash Manual section on Redirections and Greg Wooledge's BashGuide section on Redirection. – Dennis Williamson Sep 1 '10 at 15:08

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.