Log File Maintenance

It is a good idea to save the database server's log output somewhere, rather than just routing it to /dev/null. The log output is invaluable when it comes time to diagnose problems. However, the log output tends to be voluminous (especially at higher debug levels) and you will not want to save it indefinitely. You need to "rotate" the log files so that new log files are started and old ones thrown away every so often.

If you simply direct the postmaster's stderr into a file, the only way to truncate the log file is to stop and restart the postmaster. This may be fine for development setups but you won't want to run a production server that way.

The simplest production-grade approach to managing log output is to send it all to syslog and let syslog deal with file rotation. Because the Red Hat Database PostgreSQL is built with the --enable-syslog configure option, you can send log output to syslog by setting syslog to 2 (log to syslog only) in postgresql.conf. Then you can send a SIGHUP signal to the syslog daemon whenever you want to force it to start writing a new log file.

You may find it useful to pipe the postmaster's stderr to some type of log rotation script. If you start the postmaster with pg_ctl, then the postmaster's stderr is already redirected to stdout, so you just need a pipe command:
pg_ctl start | logrotate

If you have Apache, you have a log rotation mechanism installed: the Apache utility rotatelogs. To enable rotatelogs, put it in the path of the postgres user and start the database with the following command:
pg_ctl start | rotatelogs "$PGDATA/logs/pgsql" 86400 &
where $PGDATA/logs is a directory you made and pgsql will be the name that all of your log files will start with.