ログ自動削除

(12cR1)

https://qiita.com/Esfahan/items/a8058f1eb593170855a1
https://qiita.com/kotarosan/items/af32198e969b026434dd

【1】アラートログ、リスナーログ

logrotateコマンドで実行

vim /etc/logrotate.d/oracle

/u01/app/oracle/diag/rdbms/orcl/orcl/trace/alert_orcl.log
/u01/app/oracle/diag/tnslsnr/mmm050/listener/trace/listener.log {
create 640 oracle oinstall
notifempty
daily
rotate 5
missingok
compress
sharedscripts
}


--動作確認
----ドライラン
/usr/sbin/logrotate -dv /etc/logrotate.d/oracle

----強制実行
/usr/sbin/logrotate -f /etc/logrotate.d/oracle

 

【2】トレースファイル

ADRの自動purge機能を使用

--コマンド起動
adrci

--ADRホーム設定
show homepath
set homepath diag/rdbms/orcl/orcl
show homepath

--設定確認
show control

--削除ポリシーを1日にする場合
set control (SHORTP_POLICY = 24)
set control (LONGP_POLICY = 24)

--パージの手動実行
purge

 

 

(8.0)

【1】エラーログ、スロークエリログ、一般クエリログ

logrotateコマンドで実行

--パスワード設定

mysql_config_editor set --login-path=client --user=root --host=localhost --password
/usr/bin/mysqladmin ping

--設定ファイル

vim /etc/logrotate.d/mysql

/var/lib/mysql/mmm054.log
/var/lib/mysql/mmm054-slow.log
/var/log/mysqld.log {
create 640 mysql mysql
notifempty
daily
rotate 5
missingok
compress
sharedscripts
postrotate
# just if mysqld is really running
if test -x /usr/bin/mysqladmin && \
/usr/bin/mysqladmin ping &>/dev/null
then
/usr/bin/mysqladmin flush-logs
fi
endscript
}


--動作確認
----ドライラン
/usr/sbin/logrotate -dv /etc/logrotate.d/mysql

----強制実行
/usr/sbin/logrotate -f /etc/logrotate.d/mysql

 

【2】バイナリログ


下記パラメータで指定
vim /etc/my.cnf

binlog_expire_logs_seconds = 259200

(9.4)
vim postgresql.conf

log_filename = 'postgresql-%a.log'
log_rotation_age = '1d'
log_rotation_size = 0
log_truncate_on_rotation = on

 

https://blog.engineer-memo.com/2012/04/02/sql-server-%E3%81%AE%E3%83%AD%E3%82%B0%E3%83%AD%E3%83%BC%E3%83%86%E3%83%BC%E3%82%B7%E3%83%A7%E3%83%B3/

デフォルトでは下記6世代保存

ERRORLOG、ERRORLOG.1 ~ ERRORLOG.6

--世代数を10に変更する場合

USE [master]
GO
EXEC xp_instance_regwrite N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\MSSQLServer\MSSQLServer', N'NumErrorLogs', REG_DWORD, 10
GO

--手動ログローテート

EXEC sp_cycle_errorlog ;
GO