Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I'm running Postgres 9.1 (Homebrew installation on Mac OSX) and I'd like to monitor my postgres server more closely.

My question relates to logs. I'd like to get the logs displaying in a terminal pane. Here's what the Postgres docs say about the logs:

"On Unix-like systems, by default, the server's standard output and standard error are sent to pg_ctl's standard output (not standard error). The standard output of pg_ctl should then be redirected to a file or piped to another process such as a log rotating program like rotatelogs; otherwise postgres will write its output to the controlling terminal (from the background) and will not leave the shell's process group. On Windows, by default the server's standard output and standard error are sent to the terminal. These default behaviors can be changed by using -l to append the server's output to a log file. Use of either -l or output redirection is recommended."

So, when I get my postgres server running with the following:

pg_ctl start -D /usr/local/var/postgres

The logs display in the terminal window. When I run:

pg_ctl start -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log

The logs go to my logfile and don't display in terminal.

In short, it would be great if anyone can tell me what command I use after I've directed logs to the file (with the second command) to make the logs also appear at the command line. It helps when I'm developing (in Django) to watch the SQL statements get executed in real time.

share|improve this question
1  
If I understand you correctly, you should have a look at tee. –  dezso Aug 4 '12 at 7:55

2 Answers 2

the "-a" in the "tee" command is for appeding text to the log file.

pg_ctl start -D /usr/local/var/postgres | tee -a /usr/local/var/postgres/server.log
share|improve this answer

Just use tail -f /path/to/log and you'll be able to see the log contents in a terminal as well. You can use a terminal tool that can "monitor for activity" if you'd like to be notified when something happens.

A more complex solution would be to set PostgreSQL to log to rsyslog, and set rsyslog to log to a tty as well as a file

share|improve this answer

Your Answer

 
discard

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.