AI エージェント向け: ドキュメントインデックスは https://www.mongodb.com/ja-jp/docs/llms.txt で利用できます。すべてのページの markdown バージョンは、いずれかの URL パスに .md を追加することで利用できます。
Docs Menu

logRotate(データベースコマンド)

logRotate

The logRotate command is an administrative command that allows you to rotate the MongoDB server log and/or audit log to prevent a single logfile from consuming too much disk space.

You must issue the logRotate command against the admin database.

このコマンドは、次の環境でホストされている配置で使用できます。

  • MongoDB Enterprise: サブスクリプションベースの自己管理型 MongoDB バージョン

  • MongoDB Community: ソースが利用可能で、無料で使用できる自己管理型の MongoDB のバージョン

重要

This command is not supported in MongoDB Atlas clusters. For information on Atlas support for all commands, see Unsupported Commands.

このコマンドの構文は、次のとおりです。

db.adminCommand(
{
logRotate: <integer or string>,
comment: <string>
}
)

このコマンドは、次のフィールドを使用します。

フィールド
タイプ
説明

logRotate

整数または文字列

ローテーションするログは、次のように表示されます。

  • 1 -- サーバーログと監査ログの両方をローテーション

  • "server" -- サーバーログのみをローテーション

  • "audit" -- 監査ログのみをローテーション

comment

string

任意。ログローテーション時にサーバーがログファイルと監査ファイルに記録するメッセージ。

SIGUSR1 シグナルを mongod プロセスに送信してログをローテーションすることもできます。

たとえば、実行中の mongod インスタンスのプロセス ID(PID)が 2200 の場合、次のコマンドは Linux 上でそのインスタンスのログファイルをローテーションします。

kill -SIGUSR1 2200
  • Your mongod instance needs to be running with the --logpath [file] option in order to use logRotate

  • 監査ログをローテーションするには、監査を有効にする必要があります。

The systemLog.logRotate setting or --logRotate option specify logRotate's behavior.

When systemLog.logRotate or --logRotate are set to rename, logRotate renames the existing log file by appending the current timestamp to the filename. The appended timestamp has the following form:

<YYYY>-<mm>-<DD>T<HH>-<MM>-<SS>

Then logRotate creates a new log file with the same name as originally specified by the systemLog.path setting to mongod or mongos.

When systemLog.logRotate or --logRotate are set to reopen, logRotate follows the typical Linux/Unix behavior, and simply closes the log file then reopens a log file with the same name. With reopen, mongod expects that another process renames the file prior to the rotation, and that the reopen results in the creation of a new file.

次の例では、サーバーログと監査ログの両方をローテーションしています。

db.adminCommand( { logRotate: 1 } )

次の例では、監査ログのみをローテーションし、ローテーション時にログファイルにカスタムメッセージを提供します。

db.adminCommand( { logRotate: "audit", comment: "Rotating audit log" } )