Is it better to save the log to the database or the local file?

this is true. If the mall wants to dock with third-party payment, now it needs to add a callback log in the payment callback entry, and all requests that have entered the callback are saved in the log. Now there is a question as to whether the callback log should be saved to the database or to a local file. saving to the database is afraid of taking up database resources. Callback requests now have millions of requests every day, and there is the possibility of concurrent requests. In the end, whether the callback log is written to the database or the local file. Ask for an experienced Daniel solution

Mar.30,2021

it is recommended to save to the log file. The log volume is large. Each time you save the database, you will increase the write burden of the database, and put it in the log file. Later, you can do similar Logstash applications to do log collection and data visualization analysis. At this time, you do not have to worry about the extra database reading burden. After all, the database read and write resources are very important.


this saves the database well and is not easy to delete.


I agree with the suggestion upstairs. It is not recommended to save to the database in the case of such concurrency and data volume. When the amount of data gradually takes up more and more disk space of the database, the performance of the database will be a new problem.

give two suggestions to the subject

  1. Save log data to local files, and store regular backups to other places
  2. how to involve log analysis in the future, you can consider third-party log services. For example, Aliyun's log service (definitely not advertising, because I am using it)
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3a64b-2c1ef.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3a64b-2c1ef.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?