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.
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