Re: LogFile Management

Lists: pgsql-novice
From: Peter Elmers <p(dot)elmers(at)gmx(dot)de>
To: pgsql-novice(at)postgresql(dot)org
Subject: LogFile Management
Date: 2007-03-20 09:19:39
Message-ID: 778CC40F-CF61-45AE-A5B4-67C3BF4E7DE0@gmx.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-novice

Hi!

After countless tries for configuring postgres logmanagement without
success, i hope the community can help me solving the following problem:

I would like to have postgres write logfiles, which must not exceed a
specific size all together. After the files have reached the desired
size, it would be nice that the files will

a) be overwritten or
b) rotate and are overwritten after reaching the limit of file numbers.

I am sorry to say that log_filename = 'g_pgsql.log%a' is not an
option because the logfiles can increase rapidly within a few minutes.

This is the current configuration:

#-----------------------------------------------------------------------
----
# ERROR REPORTING AND LOGGING
#-----------------------------------------------------------------------
----

# - Where to Log -

#log_destination = 'stderr' # Valid values are combinations of
# stderr, syslog and eventlog,
# depending on platform.

# This is used when logging to stderr:
redirect_stderr = on # Enable capturing of stderr into log
# files
# (change requires restart)

# These are only used if redirect_stderr is on:
log_directory = '/Library/Application\ Support/Test/
PostgreSQL_logs/' # Directory where log files are written
# Can be absolute or relative to PGDATA
log_filename = 'g_pgsql.log' # Log file name pattern.
# Can include strftime() escapes
log_truncate_on_rotation = on # If on, any existing log file of the same
# name as the new log file will be
# truncated rather than appended to. But
# such truncation only occurs on
# time-driven rotation, not on restarts
# or size-driven rotation. Default is
# off, meaning append to existing files
# in all cases.
#log_rotation_age = 0 # Automatic rotation of logfiles will
# happen after that time. 0 to
# disable.
log_rotation_size = 1MB # Automatic rotation of logfiles will
# happen after that much log
# output. 0 to disable.

# These are relevant when logging to syslog:
#syslog_facility = 'LOCAL0'
#syslog_ident = 'postgres'

The generated logfile-names:

g_pgsql.log.1173887776
g_pgsql.log.1173974605
g_pgsql.log.1174028625

Best Regards,

Peter


From: Shane Ambler <pgsql(at)Sheeky(dot)Biz>
To: Peter Elmers <p(dot)elmers(at)gmx(dot)de>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: LogFile Management
Date: 2007-03-20 13:35:30
Message-ID: 45FFE322.5070303@Sheeky.Biz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-novice

Peter Elmers wrote:
> Hi!
>
> After countless tries for configuring postgres logmanagement without
> success, i hope the community can help me solving the following problem:
>
> I would like to have postgres write logfiles, which must not exceed a
> specific size all together. After the files have reached the desired
> size, it would be nice that the files will
>
> a) be overwritten or
> b) rotate and are overwritten after reaching the limit of file numbers.

Pretty sure there is no such option within postgresql.
The log settings are to simply provide a maximum file size for each log
to make them easier to manage when you want to look at recent activity,
not to remove old log files which is more of a sysadmin task.

I would suggest you look at something like the steps you can find in
/etc/daily and adjust to your log names. The steps that exist there can
point you to ways of finding files greater than a certain age (the find
using the atime option near the start) and rotating to have a certain
number of log files as shown near the end for rotating the system.log
which also compresses the old log files. If you have postgresql changing
log files by size (log_rotation_size = 1MB) then the number of files in
the log dir will give you the rough total size or you may want to use du
to get the disk space used by the log dir.

The common way to handle this would be create a shell script (or perl if
that is your preference) with the steps you want and then have cron run
them on a regular basis. I have used Cronnix for a few years now which
can make that step easier.
http://h5197.serverkompetenz.net:9080/abstracture_public/projects-en/cronnix/

If you are new to using the terminal then I suggest you use the
available man pages to find the options that meet your needs for the
steps you want. If you have the Apple dev tools installed with docs then
you can also find them in xcode's help (find man page...) also Apple has
a shell scripting tutorial which you can find -
/Developer/ADC Reference
Library/documentation/OpenSource/Conceptual/ShellScripting/index.html
or online at -
http://developer.apple.com/documentation/OpenSource/Conceptual/ShellScripting/index.html

--

Shane Ambler
pgSQL(at)Sheeky(dot)Biz

Get Sheeky @ http://Sheeky.Biz