stoqlt
stoqlt

Reputation: 43

postgres 9.1 logfile change

I have a standard Ubuntu postgres9.1 install running continuosly, I may not stop it.

Nothing has been specifically configured regarding the logging target, so there is a (rotating somehow) logfile /var/log/postgresqlpostgresql-9.1-main.log. I suppose, it grabs the standard output of the processes.

What I want is to configure a different file target, and, without restart, (Sorry, no collector, no syslog ... those need restarting) but with reconfig, the new child processes used that file.

Is that possible? Thank you.

Upvotes: 3

Views: 3837

Answers (2)

Philip Couling
Philip Couling

Reputation: 14903

I've modified my previous answer because as Daniel Vérité pointed out, you can't set the log file without using the logging_collector, the log_filename option will be ignored.

Rotation is done through "copy-truncate". That is logrotate makes a copy of the file and then empties the main log file.

In this case I think you will be lucky in that the server opens up a file handle to the log and uses just that one to write to. This means that you can simply rename the file mv old_name.log new_name.log. The file handle that postgresql uses is bound to the file itself and not the name.

This solution does come with the problem that when the server is restarted, it will create a new log file under the old name. You will need to make configuration changes so that when it restarts it continues to write to the same place.

Upvotes: 0

Philip Couling
Philip Couling

Reputation: 14903

I believe this is relatively simple. Sadly it does require the use of the logging collector which would require a restart to enable. Without that you can't move a log between partitions.

You can configure which log is used in: /etc/postgresql/<version>/<cluster>/postgresql.conf

log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log

Once you change this, you will need to do a service postgresql reload to get it to pick up the changes.

Perhaps I should be clear here, that the point of this answer is that you can use service postgresql reload without restarting the server.

Upvotes: 4

Related Questions