简体   繁体   English

删除 MySQL 日志文件会影响数据库的性能吗?

[英]Will remove MySQL logs file impact the performance of the database?

One of our users is using Cloud SQL(MySQL).我们的一位用户正在使用 Cloud SQL(MySQL)。

They turn on general logs flag and log_output is file .他们打开general logs标志并且 log_output 是file

They need these general logs because of some special circumstances.由于某些特殊情况,他们需要这些通用日志。

MySQL generates about 8TB of general logs and these logs result a bigger use of the disk. MySQL 生成大约 8TB 的一般日志,这些日志导致磁盘使用量更大。

Here is the tricky part:这是棘手的部分:

They want to remove these general logs file [1] to decrease the size of the disk.他们想删除这些general logs file [1] 以减小磁盘的大小。

However, this is their production database.但是,这是他们的生产数据库。 They afraid this operation will impact their database's performance.他们担心此操作会影响其数据库的性能。

Since these log files are located in /var/log/mysql.log , the remove logs operation will execute on the OS level, right?由于这些日志文件位于/var/log/mysql.log中,因此删除日志操作将在操作系统级别执行,对吗? -> This is the part we are not so sure. ->这是我们不太确定的部分。

If our user executes this truncateAPI, will this operation affect their database's performance?如果我们的用户执行这个 truncateAPI,这个操作会影响他们数据库的性能吗?

Is there any best practice for this kind of situation?这种情况有什么最佳做法吗?

PS: Our user doesn't want to turn off general logs flag. PS:我们的用户不想关闭general logs标志。 They will try to truncate these logs once for a while.他们会尝试在一段时间内截断这些日志。 But for now, they need to truncate the huge amount of logs that they accumulated in the past few momths.但是现在,他们需要截断过去几个月积累的大量日志。

[1] https://cloud.google.com/sql/docs/mysql/admin-api/v1beta4/instances/truncateLog [1] https://cloud.google.com/sql/docs/mysql/admin-api/v1beta4/instances/truncateLog

I understand that you have turned on general logs flag and log_output is FILE and you want to remove these general logs files to decrease the size of the disk.我了解到您已打开general logs标志且log_outputFILE ,您希望删除这些通用日志文件以减小磁盘大小。

According to to the official documentation link :根据官方文档 链接

To make your general or slow query logs available, enable the corresponding flag and set the log_output flag to FILE.要使您的常规或慢查询日志可用,请启用相应的标志并将 log_output 标志设置为 FILE。 This makes the log output available using the Logs Viewer in the Google Cloud Platform Console.这使得日志 output 可以使用 Google Cloud Platform Console 中的日志查看器访问。 Note that Stackdriver logging charges apply.请注意,需要收取 Stackdriver 日志记录费用。

If log_output is set to NONE, you will not be able to access the logs.如果 log_output 设置为 NONE,您将无法访问日志。

If you set log_output to TABLE, the log output is placed in a table in your database.如果将 log_output 设置为 TABLE,则日志 output 将放置在数据库的表中。 If this table becomes large, it can affect instance restart time or cause the instance to lose its SLA coverage;如果此表变大,可能会影响实例重启时间或导致实例失去其 SLA 覆盖范围; for this reason, the TABLE option is not recommended.因此,不推荐使用 TABLE 选项。 If needed, you can truncate your log tables by using the API.如果需要,您可以使用 API 截断日志表。 For more information, see the instances.truncateLog reference page.有关更多信息,请参阅 instances.truncateLog 参考页面。

Instances: truncateLog truncate MySQL general and slow query log tables. Instances: truncateLog truncate MySQL 通用和慢查询日志表。

If I understood correctly, you can not "truncate the huge amount of logs that they accumulated in the past few months" because you did not set log_output to TABLE, therefore there are no tables to be truncated.如果我理解正确,您不能“截断过去几个月积累的大量日志”,因为您没有将log_output设置为 TABLE,因此没有要截断的表。

Regarding database performance: TRUNCATE TABLE Statement关于数据库性能: TRUNCATE TABLE 语句

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.在具有大型 InnoDB 缓冲池和启用 innodb_adaptive_hash_index 的系统上,由于删除 InnoDB 表的自适应 hash 索引条目时发生 LRU 扫描,TRUNCATE TABLE 操作可能会导致系统性能暂时下降。 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 5.5.23 中的 DROP TABLE 问题已得到解决(错误 13704145,错误 #64284),但对于 TRUNCATE TABLE 仍然是一个已知问题(错误 #68184)。

Here you can check MySQL Server Log Maintenance .在这里您可以查看MySQL 服务器日志维护

Removing MySQL general_log FILES should not impact the performance of the database.删除 MySQL general_log 文件不应影响数据库的性能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM