Rotating Trace Log to Manage its Size
On this page
Without a log rotation policy in place, the tracelog can keep growing in size until it consumes all remaining disk space.
SingleStore supports two approaches to trace log rotation: via a built-in function to rotate and manage trace log files, or you can build your own custom solution using something like logrotate
.
Built-In Trace Log Rotation
The SingleStore provided trace log rotation feature includes settings for:
-
rotating based on log size
-
rotating based on time
-
deleting logs based on age
You can enable log rotation based on log size or time on disk or both.
To enable trace log rotation, set either or both of the tracelog_
and tracelog_
engine variables to a valid value other than 0 -- the default values are 0 (disabled).
If you set both engine variables, rotation will happen on either of triggers;, i.
Trace Log Rotation Engine Variables
The following engine variables control the behavior of the built-in trace log rotation feature.
tracelog_
specifies the log file size threshold in bytes.
tracelog_
specifies the log file rotation time threshold in seconds.
tracelog_
controls the amount of time in days to keep rotated logs on the file system.
Warning
If tracelog_
is not enabled, trace log files will eventually fill the filesystem.
tracelog_
and tracelog_
are used to control the rotation strategy.sdb-admin update-config
command.
Examples of Trace Log Rotation Configuration
This table shows various trace log rotation settings and their effects.
Engine Variable Settings |
Trace Log Rotation Behavior |
---|---|
|
Trace log rotation disabled. |
|
Trace log rotation disabled. |
|
Trace log rotation enabled. |
|
Trace log rotation enabled. |
|
Trace log rotation enabled. |
|
Trace log rotation enabled. |
Using logrotate
The memsql.
file can be rotated by moving the memsql.
file and then sending SIGHUP
to the memsqld
process.memsql.
and continue writing.
To automate tracelog
rotation, you may use the logrotate
utility.logrotate
utility runs with the default /etc/logrotate.
configuration./etc/logrotate.
; the include
directive in the logrotate.
file makes sure that the custom configuration files are read as well.logrotate
command.logrotate
, refer to the logrotate
man page.
Example logrotate
Configuration File
The following logrotate
configuration file rotates two log files: memsql.
and query.
.
Note: The example paths use the default folder location for SingleStore with an example ID value in the folder name for a Master Aggregator node.root
user when running logrotate
.
cat > /var/tmp/tracelog-logrotate.conf <<EOF/var/lib/memsql/master-3306-MI4478312f/tracelogs/memsql.log /var/lib/memsql/master-3306-MI4478312f/tracelogs/query.log {dailyrotate 7missingokcompresssharedscriptspostrotate# Send SIGHUP to both memsqld processeskillall -q -s1 memsqldendscript}EOF
The directives used in the above example indicate the following:
-
daily
: Log files are rotated every day; alternately, you can rotate them weekly or monthly. -
rotate
[count]: Specifies the number of times log files are rotated before being deleted.In the example, log files are rotated 7 times before being deleted. You can specify the number of times you want to rotate the old log files before deleting them. If run with the --mail
option, the log files will be rotated the specified number of times before being emailed, rather than being removed. -
missingok
: If a specified log file is missing, this directive ensures thatlogrotate
rotates the next file in the queue without throwing an error. -
compress
: Old versions of log files are compressed with gzip by default. -
sharedscripts
: With this directive specified, thepostrotate
script is run only one time (after the old logs have been compressed), not each time a log file is rotated. -
postrotate/endscript
: The lines between these directives are executed after the log file is rotated.The example uses the killall -q -s1 memsqld
command, which allows for a new tracelog to be generated and written to the next trace.
Scheduling logrotate
The logrotate
process is typically run as a daily cron
job by the cron
daemon./etc/cron.
that runs logrotate
with the default /etc/logrotate.
configuration.
#! /bin/sh
/user/sbin/logrotate /etc/logrotate.conf
You can also create cron
jobs in the cron.
, cron.
, or cron.
folders.cron.
folder are run by the cron
service, per the instructions in the /etc/crontab
file.logrotate
with a custom schedule, create a cron
job and place it under /etc/cron.
.
Note that the cron
jobs stored in /etc/cron.
and /etc/crontab
directories are system cron
jobs.cron
jobs are defined in shared directories on the filesystem.sudo
privileges to define system cron
jobs.
Cron
jobs are defined using the unix-cron format in both /etc/cron.
and /etc/crontab
directories.cron
job must be executed.cron
job must run and then the command to execute.cron
job issues logrotate
using the /etc/tracelog-logrotate.
configuration every Saturday at five minutes past midnight.
5 0 * * 6 root /usr/sbin/logrotate /etc/tracelog-logrotate.conf
Manually Running logrotate
To manually run logrotate
, use the following command and specify the configuration file.
logrotate -f /var/tmp/tracelog-logrotate.conf
To list the compressed log files, run the following command.
ls /var/lib/memsql/master-3306-MI4478312f/tracelogs/*.gz
Alternatives to logrotate
As an alternative to logrotate
, you can configure SingleStore to log using the syslog
daemon, such as journald
, and then implement log rotation.
Last modified: January 18, 2024