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-09-04 (世界標準時間)。"],[[["\u003cp\u003eThis guide outlines how to configure the rotation of diagnostic logs for AlloyDB Omni when using the Kubernetes operator, covering both \u003ccode\u003epostgresql.audit\u003c/code\u003e and \u003ccode\u003epostgresql.log\u003c/code\u003e files.\u003c/p\u003e\n"],["\u003cp\u003eLog rotation involves copying the current log file to an archive directory, clearing the original log, and beginning new log entries in the now-empty original log file, and by default, logs rotate when they reach 200 MB.\u003c/p\u003e\n"],["\u003cp\u003eArchived log files are compressed in Gzip format (\u003ccode\u003e.gz\u003c/code\u003e) and are retained for 7 days, with the exception of the file from the previous rotation, which is kept until the next rotation occurs.\u003c/p\u003e\n"],["\u003cp\u003eYou can customize log rotation by setting \u003ccode\u003elog_rotation_size\u003c/code\u003e and \u003ccode\u003elog_rotation_age\u003c/code\u003e parameters in the \u003ccode\u003eDBCluster\u003c/code\u003e manifest, or you can disable rotation by setting either parameter to \u003ccode\u003e"0"\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eTo enable the collection of session and object access audit logs, you need to enable the \u003ccode\u003epgaudit\u003c/code\u003e 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: 15.7.0keyboard_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\nEach archived file is individually compressed using the Gzip (`.gz`) file format.\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 previous 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 archived log filename follows this format: `postgresql-%Y-%m-%d_%H%M%S.log.gz`.\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.gz`.\n\nTo save an archived file permanently, you can copy it from the database container\nto your local directory using [`kubectl cp`](https://kubernetes.io/docs/reference/kubectl/generated/kubectl_cp/).\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: \"15.7.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/15.7.0/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\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/15.7.0/docs/run-connect)\n- [Generate and diagnose AlloyDB Omni dump files](/alloydb/omni/15.7.0/docs/manage-dump-files)\n- [Learn about automatic memory management](/alloydb/omni/15.7.0/docs/automatic-memory-management)"]]