apiVersion:alloydbomni.dbadmin.goog/v1kind:DBClustermetadata:name:DB_CLUSTER_NAMEspec:...primarySpec:...parameters:log_rotation_size:"400000"# 400 MBlog_rotation_age:"0"# Set to 0 to disable
記錄輪替時間長度範例
下列範例會將記錄設為每 24 小時輪替一次:
apiVersion:alloydbomni.dbadmin.goog/v1kind:DBClustermetadata:name:DB_CLUSTER_NAMEspec:...primarySpec:...parameters:log_rotation_size:"0"# Set to 0 to disablelog_rotation_age:"1440"# 24 hours * 60 minutes = 1 day
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-08-17 (世界標準時間)。"],[[["\u003cp\u003eAlloyDB Omni diagnostic logs, including \u003ccode\u003epostgresql.audit\u003c/code\u003e and \u003ccode\u003epostgresql.log\u003c/code\u003e, are located in the \u003ccode\u003e/obs/diagnostic/\u003c/code\u003e directory and rotate to prevent them from becoming too large.\u003c/p\u003e\n"],["\u003cp\u003eWhen a log file rotates, it is copied to \u003ccode\u003e/obs/diagnostic/archive/\u003c/code\u003e, the original file is emptied, and new log information starts writing to the emptied file.\u003c/p\u003e\n"],["\u003cp\u003eLog rotation occurs by default when a log file reaches 200 MB in size, but can be configured to rotate based on file size or age by adjusting the \u003ccode\u003elog_rotation_size\u003c/code\u003e and \u003ccode\u003elog_rotation_age\u003c/code\u003e parameters.\u003c/p\u003e\n"],["\u003cp\u003eArchived log files are compressed using Gzip and retained for 7 days, after which they are automatically removed, except for the file that was archived during the most recent rotation.\u003c/p\u003e\n"],["\u003cp\u003eTo collect session and object access logs in the \u003ccode\u003epostgresql.audit\u003c/code\u003e file, you need to enable the \u003ccode\u003epgaudit\u003c/code\u003e database parameter by adding \u003ccode\u003ealloydb.enable_pgaudit: "on"\u003c/code\u003e to the \u003ccode\u003eparameters\u003c/code\u003e section of the \u003ccode\u003ev1_dbcluster_parameters.yaml\u003c/code\u003e file.\u003c/p\u003e\n"]]],[],null,["# Configure AlloyDB Omni log rotation\n\nSelect a documentation version: Current (16.8.0)keyboard_arrow_down\n\n- [Current (16.8.0)](/alloydb/omni/current/docs/configure-log-rotation)\n- [16.8.0](/alloydb/omni/16.8.0/docs/configure-log-rotation)\n- [16.3.0](/alloydb/omni/16.3.0/docs/configure-log-rotation)\n- [15.12.0](/alloydb/omni/15.12.0/docs/configure-log-rotation)\n- [15.7.1](/alloydb/omni/15.7.1/docs/configure-log-rotation)\n- [15.7.0](/alloydb/omni/15.7.0/docs/configure-log-rotation)\n\n\u003cbr /\u003e\n\nThis document describes how to configure rotation of AlloyDB Omni diagnostic logs when you use the AlloyDB Omni Kubernetes operator.\n\n\u003cbr /\u003e\n\nThe following log files are located in the `/obs/diagnostic/`\ndirectory:\n\n- `postgresql.audit`: This log file collects session and object access audit\n logs. To collect audit logs, you need to\n [enable audit logs](#enable-audit-logs).\n\n- `postgresql.log`: This log file collects PostgreSQL server logs. These logs\n are always collected and don't need to be enabled.\n\nWhen a log file rotates, the following occurs:\n\n1. The log file is copied to the `/obs/diagnostic/archive/` directory. If a log\n file with the same name exists in that directory, then it's overwritten.\n\n2. The contents of the original rotated log file are deleted so that the file\n is empty.\n\n3. Log information immediately begins writing to the empty rotated log file.\n Log information is written to the log file until the file reaches a size or\n age threshold, at which point it rotates again. Logs rotate so that they\n don't become too large.\n\nBy default, the rotation setting is for each log file to rotate when its size\nreaches 200 MB. The default rotation doesn't include an age setting.\n\nArchived files are retained for 7 days. Archived files that are older\nthan 7 days are automatically removed, except for the file that was archived\nduring the last rotation. For example, if `log_rotation_age` is older than 7 days,\nthen the archived file reaches the 7-day threshold before the rotation of the\ncurrent file. In this case, this archived file isn't removed until the next\nrotation generates a new archived file.\n\nEach rotated log filename follows this format: `postgresql-%Y-%m-%d_%H%M%S.log`.\nThe timestamp is determined at the time of log rotation and is expressed in\nCoordinated Universal Time (UTC). For example, if the log is rotated at\n13:01:02 of 12/20/2024 UTC, the archived filename is\n`postgresql-2024-12-20_130102.log`.\n\nEach archived file is individually compressed using the Gzip file format.\n\nEnable audit logs\n-----------------\n\nFor session and object access logs to be collected in the `postgresql.audit`\nfile, you need to enable the [`pgaudit`](https://github.com/pgaudit/pgaudit)\ndatabase parameter. To enable [`pgaudit`](https://github.com/pgaudit/pgaudit),\nadd the following line to the `parameters` section of the\n[`v1_dbcluster_parameters.yaml`](https://github.com/GoogleCloudPlatform/alloydb-omni-samples/blob/main/samples/v1_dbcluster_parameters.yaml)\nfile under `Secret`: \n\n alloydb.enable_pgaudit: \"on\"\n\nThe following is an example of this might look like: \n\n apiVersion: v1\n kind: Secret\n ...\n apiVersion: alloydbomni.dbadmin.goog/v1\n kind: DBCluster\n metadata:\n name: \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003eDB_CLUSTER_NAME\u003c/span\u003e\u003c/var\u003e\n spec:\n databaseVersion: \"16.8.0\"\n primarySpec:\n ...\n parameters:\n ...\n alloydb.enable_pgaudit: \"on\"\n\nFor more information, see `pgaudit` in\n[Supported database extensions](/alloydb/omni/current/docs/reference/extensions),\nand [PostgreSQL Auditing Extension](https://www.pgaudit.org/).\nPostgreSQL server logs are always collected in the `postgresql.log` file and\ndon't require enabling [`pgaudit`](https://github.com/pgaudit/pgaudit).\n\nView the path of the audit log file\n-----------------------------------\n\nThe SQL function `alloydb_audit_current_logfile` can be used to view the path of the audit log file. If auditing is disabled, then the result is `NULL`. \n\n SELECT alloydb_audit_current_logfile();\n\n alloydb_audit_current_logfile\n ----------------------------------------------------\n /var/log/pglogs/postgresql-2025-03-28_042024.audit\n\nConfigure log rotation\n----------------------\n\nIf you want more control over when logs rotate, configure a maximum file size, a\nduration between log rotations, or both. The duration between log rotations is\nalso called the age of the log. If you use both settings, then each log rotates\nwhen it reaches one of the thresholds.\n\nTo configure log rotation, you set one or both of the following parameters in\nthe `parameters` section of the `DBCluster` manifest:\n\n- `log_rotation_size`: \"\u003cvar translate=\"no\"\u003eSIZE_IN_KB\u003c/var\u003e\"\n- `log_rotation_age`: \"\u003cvar translate=\"no\"\u003eAGE_IN_MINUTES\u003c/var\u003e\"\n\nTo disable one of the log rotation settings, set it to zero (`\"0\"`).\nTo retain the default setting that rotates logs when their file size\nreaches 200 MB, don't set either parameter.\n\n### Log rotation maximum log size and duration example\n\nThe following sample sets logs to rotate when their file size reaches\n400 MB or when the time between log rotations reaches one day, whichever\nhappens first: \n\n apiVersion: alloydbomni.dbadmin.goog/v1\n kind: DBCluster\n metadata:\n name: \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003eDB_CLUSTER_NAME\u003c/span\u003e\u003c/var\u003e\n spec:\n ...\n primarySpec:\n ...\n parameters:\n log_rotation_size: \"400000\" # 400 MB\n log_rotation_age: \"1440\" # 24 hours * 60 minutes = 1 day\n\n### Log rotation maximum log size example\n\nThe following sample sets logs to rotate when their file size reaches\n400 MB: \n\n apiVersion: alloydbomni.dbadmin.goog/v1\n kind: DBCluster\n metadata:\n name: \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003eDB_CLUSTER_NAME\u003c/span\u003e\u003c/var\u003e\n spec:\n ...\n primarySpec:\n ...\n parameters:\n log_rotation_size: \"400000\" # 400 MB\n log_rotation_age: \"0\" # Set to 0 to disable\n\n### Log rotation duration example\n\nThe following sample sets logs to rotate once every 24 hours: \n\n apiVersion: alloydbomni.dbadmin.goog/v1\n kind: DBCluster\n metadata:\n name: \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003eDB_CLUSTER_NAME\u003c/span\u003e\u003c/var\u003e\n spec:\n ...\n primarySpec:\n ...\n parameters:\n log_rotation_size: \"0\" # Set to 0 to disable\n log_rotation_age: \"1440\" # 24 hours * 60 minutes = 1 day\n\nWhat's next\n-----------\n\n- [Manage and monitor AlloyDB Omni](/alloydb/omni/current/docs/run-connect)\n- [Generate and diagnose AlloyDB Omni dump files](/alloydb/omni/current/docs/manage-dump-files)\n- [Learn about automatic memory management](/alloydb/omni/current/docs/automatic-memory-management)"]]