Update What I mean is can I have multiple log files per database? Probably not but I was curious if there was anything possible like this out of the box with Postgresql or if you required a third party product or building your own app to do this.

I saw from another thread you can do this:

ALTER DATABASE your_database_name SET log_statement = 'all';

I was looking through the online documentation and I found this link for logging


log_filename (string) When logging_collector is enabled, this parameter sets the file names of the created log files. The value is treated as a strftime pattern, so %-escapes can be used to specify time-varying file names. (Note that if there are any time-zone-dependent %-escapes, the computation is done in the zone specified by log_timezone.) The supported %-escapes are similar to those listed in the Open Group's strftime specification. Note that the system's strftime is not used directly, so platform-specific (nonstandard) extensions do not work. The default is postgresql-%Y-%m-%d_%H%M%S.log.

If you specify a file name without escapes, you should plan to use a log rotation utility to avoid eventually filling the entire disk. In releases prior to 8.4, if no % escapes were present, PostgreSQL would append the epoch of the new log file's creation time, but this is no longer the case. If CSV-format output is enabled in log_destination, .csv will be appended to the timestamped log file name to create the file name for CSV-format output. (If log_filename ends in .log, the suffix is replaced instead.)

This parameter can only be set in the postgresql.conf file or on the server command line.

Boo, is there any way to set up logging for just a specific database on a server that anyone has ever tried?


You can set the global log_statement=none. Then for the specific database:

ALTER DATABASE my_db_name set log_statement='all'

I also have this in my global config so the log file shows the db name and the user.
log_line_prefix = '< %m %d %u >'

  • I will give you a thumbs up because I titled my question wrong. I meant could I have a DB1.log, DB2.log side by side. What you are stating is exactly what I am doing as it is the best way to accomplish what I want but I was hoping I could tailor individual logs for specific databases. Essentially though it seems that this probably is the best way to do it and then change settings later after I am done examining. – djangojazz Nov 2 '17 at 15:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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