删除 MySQL 日志文件会影响数据库的性能吗?
Will remove MySQL logs file impact the performance of the database?
我们的一位用户正在使用 Cloud SQL(MySQL)。
他们打开 general logs
标志并且 log_output 是 file
。
由于某些特殊情况,他们需要这些通用日志。
MySQL 生成大约 8TB 的一般日志,这些日志会占用更多磁盘空间。
这是棘手的部分:
他们想删除这些 general logs file
[1] 以减小磁盘的大小。
但是,这是他们的生产数据库。他们担心这个操作会影响他们数据库的性能。
由于这些日志文件位于 /var/log/mysql.log
,删除日志操作将在 OS 级别执行,对吗? -> 这是我们不太确定的部分。
如果我们的用户执行这个 truncateAPI,这个操作会影响他们数据库的性能吗?
对于这种情况有什么最佳实践吗?
P.S:我们的用户不想关闭 general logs
标志。他们会尝试一次截断这些日志。但是现在,他们需要截断过去几个月积累的大量日志。
[1] https://cloud.google.com/sql/docs/mysql/admin-api/v1beta4/instances/truncateLog
我了解到您已打开 general logs
标志并且 log_output
是 FILE
并且您想删除这些常规日志文件以减小磁盘大小。
根据官方文档link:
To make your general or slow query logs available, enable the
corresponding flag and set the log_output flag to FILE. This makes the
log output available using the Logs Viewer in the Google Cloud
Platform Console. Note that Stackdriver logging charges apply.
If log_output is set to NONE, you will not be able to access the logs.
If you set log_output to TABLE, the log output is placed in a table in
your database. If this table becomes large, it can affect instance
restart time or cause the instance to lose its SLA coverage; for this
reason, the TABLE option is not recommended. If needed, you can
truncate your log tables by using the API. For more information, see
the instances.truncateLog reference page.
Instances: truncateLog
截断 MySQL 一般和慢速查询日志表。
如果我没理解错的话,你不能"truncate the huge amount of logs that they accumulated in the past few months"因为你没有把log_output
设置为TABLE,所以没有要截断的表。
关于数据库性能:TRUNCATE TABLE Statement
On a system with a large InnoDB buffer pool and
innodb_adaptive_hash_index enabled, TRUNCATE TABLE operations may
cause a temporary drop in system performance due to an LRU scan that
occurs when removing an InnoDB table's adaptive hash index entries.
The problem was addressed for DROP TABLE in MySQL 5.5.23 (Bug
13704145, Bug #64284) but remains a known issue for TRUNCATE TABLE (Bug #68184).
在这里你可以查看MySQL Server Log Maintenance。
删除 MySQL general_log 文件应该不会影响数据库的性能。
我们的一位用户正在使用 Cloud SQL(MySQL)。
他们打开 general logs
标志并且 log_output 是 file
。
由于某些特殊情况,他们需要这些通用日志。
MySQL 生成大约 8TB 的一般日志,这些日志会占用更多磁盘空间。
这是棘手的部分:
他们想删除这些 general logs file
[1] 以减小磁盘的大小。
但是,这是他们的生产数据库。他们担心这个操作会影响他们数据库的性能。
由于这些日志文件位于 /var/log/mysql.log
,删除日志操作将在 OS 级别执行,对吗? -> 这是我们不太确定的部分。
如果我们的用户执行这个 truncateAPI,这个操作会影响他们数据库的性能吗?
对于这种情况有什么最佳实践吗?
P.S:我们的用户不想关闭 general logs
标志。他们会尝试一次截断这些日志。但是现在,他们需要截断过去几个月积累的大量日志。
[1] https://cloud.google.com/sql/docs/mysql/admin-api/v1beta4/instances/truncateLog
我了解到您已打开 general logs
标志并且 log_output
是 FILE
并且您想删除这些常规日志文件以减小磁盘大小。
根据官方文档link:
To make your general or slow query logs available, enable the corresponding flag and set the log_output flag to FILE. This makes the log output available using the Logs Viewer in the Google Cloud Platform Console. Note that Stackdriver logging charges apply.
If log_output is set to NONE, you will not be able to access the logs.
If you set log_output to TABLE, the log output is placed in a table in your database. If this table becomes large, it can affect instance restart time or cause the instance to lose its SLA coverage; for this reason, the TABLE option is not recommended. If needed, you can truncate your log tables by using the API. For more information, see the instances.truncateLog reference page.
Instances: truncateLog
截断 MySQL 一般和慢速查询日志表。
如果我没理解错的话,你不能"truncate the huge amount of logs that they accumulated in the past few months"因为你没有把log_output
设置为TABLE,所以没有要截断的表。
关于数据库性能:TRUNCATE TABLE Statement
On a system with a large InnoDB buffer pool and innodb_adaptive_hash_index enabled, TRUNCATE TABLE operations may cause a temporary drop in system performance due to an LRU scan that occurs when removing an InnoDB table's adaptive hash index entries. The problem was addressed for DROP TABLE in MySQL 5.5.23 (Bug 13704145, Bug #64284) but remains a known issue for TRUNCATE TABLE (Bug #68184).
在这里你可以查看MySQL Server Log Maintenance。
删除 MySQL general_log 文件应该不会影响数据库的性能。