aws memo

AWS関連の備忘録 (※本ブログの内容は個人的見解であり、所属組織及び企業の意見を代弁するものではありません。1年以上古いエントリは疑ってかかってください)

RDS : Storage容量の内訳について

RDSは、起動時および停止中にストレージサイズを変更可能。

ストレージの空き状況も、CloudWatchのFreeStorageSpaceで確認可能。

では、Storageには何がはいっているのか?

https://forums.aws.amazon.com/thread.jspa?threadID=75508

The storage space used by your instance does not include the MySQL or Oracle binaries, but does include the databases, innodb log files, binlogs, and the InnoDB tablespace (ibdata1, which grows automatically) and log files which are usually small. Those extra files are not accounted for by your query, but occupy space in your data volume. Space required for those other files can increase with usage, if you have large transactions or a spike in database changes. Read replicas that fall behind can also require more space for binlogs in the primary (binlogs are not deleted until they are backed up and are not needed by any read replica).

つまり、ユーザが指定したサイズで作ったStorageには、MySQLのバイナリはふくまれていないが、

  • ibdata (innodbのデータファイル, データそのものとIndex)
  • innodb log ( crash recovery用)
  • binary log (5分 or バックアップ時に flush binlog & S3にアップ後、PURGEされる。Point in Time Recoveryが直近5分前まで戻る理由ははここから)
  • slow log (自動で消えない)

を含んでいる。

特に、logの挙動・設定には注意が必要。

http://stackoverflow.com/questions/7210646/rds-database-storage-runs-out-of-space

https://forums.aws.amazon.com/thread.jspa?threadID=83248

https://forums.aws.amazon.com/thread.jspa?threadID=85556

  • binglog_cache_size 32768 ()
  • binlog_format MIXED
  • expire_log_days 0
  • general_log OFF  ()
  • innodb_log_file_size 134217728
  • innodb_log_files_in_group 2
  • slow_query_log OFF()
  • long_query_time 10.000000 ()
  • log_warnings 1
  • max_binlog_size 134217728 ()
  • relay_log_space_limit 0 
  • sql_log_off OFF

この中で厄介なのは、デフォルトでは無効のgeneral_log, slow_query_logをParameter Groupで有効にした場合。RDSでも、slow logは自動でローテート・削除されないので、放置するとStorage usageを上げる要因になる。(Parameter Groupで無効に戻すと増加は止まるが、、)

RDSで、slow_query_logを操作するには

mysql> CALL mysql.rds_rotate_slow_log

この操作で、 mysql.slow_log テーブルのデータが、 mysql.slow_log_backupテーブルに移動し、mysql.slow_logテーブルは空になる。(つまり1世代保持)。よって、古いデータも削除したい場合は、 上記操作を2回連続で行うことになる。

general_logも同様。

mysql> CALL mysql.rds_rotate_general_log

 ちなみに、slow_query_logテーブルの実体はCSVファイルなので(log_output=TABLE)、ほとんどMySQLの性能に対する影響は小さいが、フィアルが大きくなりすぎるとそれなりに影響があるので、適宜 rds_rotate_slow_log でローテートすること。

なお、long_query_timeで、msecを設定することはできない(1以下の少数を使えない)

 

このへんも参考になる。

Appendix: Common DBA Tasks for MySQL - Amazon Relational Database Service