pgAudit 로깅 동작을 구성하려면 pgaudit.log 플래그 또는 pgaudit.role 플래그를 설정합니다.
pgaudit.log를 설정하여 세션 로깅을 사용 설정하고 구성합니다. 인스턴스, 데이터베이스 또는 역할에 이 플래그를 설정하여 pgAudit에서 로깅하는 작업의 범위를 정의할 수 있습니다. pgAudit에서 로깅하는 작업 유형을 정의하는 값으로 플래그를 설정합니다.
pgaudit.role를 설정하여 특정 관계에 영향을 미치는 문을 로깅하는 객체 로깅을 사용 설정하고 구성합니다. 이 플래그를 역할 이름으로 설정한 다음 로깅할 특정 객체에 대한 문 액세스 권한을 부여합니다. 명령문 액세스에는 SELECT, INSERT, UPDATE, and
DELETE가 포함됩니다. pgAudit은 모든 사용자가 실행한 액세스 및 객체의 조합과 일치하는 모든 작업을 로깅합니다.
데이터베이스 수준에서 pgaudit.log 플래그를 설정하여 특정 데이터베이스에 대해 감사를 구성할 수 있습니다.
예를 들어 데이터베이스 finance에 대해 읽기/쓰기 감사를 사용 설정하려면 다음을 실행합니다.
finance=> ALTER DATABASE finance SET pgaudit.log = 'read,write';
단일 사용자의 세션 감사 로깅 구성
역할 수준별로 pgaudit.log을 설정하여 특정 사용자에 대해 감사를 사용 설정할 수 있습니다.
예를 들어 Alice 사용자가 실행하는 모든 데이터베이스 작업에 대한 감사를 설정하려면 다음을 실행합니다.
finance=> ALTER ROLE alice SET pgaudit.log = 'all';
객체 감사 로깅 구성
관계에 대한 감사는 특정 데이터베이스에 대한 감사 범위보다 좁습니다. 관계에 대해 감사를 수행할 때는 시스템에서 고유한 감사 역할이 pgaudit.role 매개변수에 할당됩니다. 이 작업은 이 역할에 부여된 객체 또는 관계를 로깅합니다.
예를 들면 다음과 같습니다.
직원 데이터베이스 내 급여 관계의 모든 SELECT 쿼리에 대해 감사를 구성하려면 다음을 실행합니다.
employee=> CREATE ROLE auditor WITH NOLOGIN;employee=> ALTER DATABASE employee SET pgaudit.role = 'auditor';employee=> GRANT SELECT ON salary TO auditor;
또한 특정 관계에 대해 열 하위 집합을 감사할 수 있습니다.
예를 들면 다음과 같습니다.
income 및 tax_status 열에 salary 관계에서 액세스할 때만 감사 로깅이 발생하도록 구성하려면 다음을 실행합니다.
employee=> GRANT SELECT(income, tax_status) ON salary TO auditor;
[[["이해하기 쉬움","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(UTC)"],[[["\u003cp\u003e\u003ccode\u003epgaudit.log\u003c/code\u003e flag configures session logging, enabling you to audit operations at the instance, database, or role level by specifying the types of operations to log.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003epgaudit.role\u003c/code\u003e flag configures object logging, allowing you to log statements that affect specific relations by assigning a role and granting statement access to the desired objects.\u003c/p\u003e\n"],["\u003cp\u003eSession logging can be configured for all databases in an instance, a specific database, or a single user by setting the \u003ccode\u003epgaudit.log\u003c/code\u003e flag at the appropriate level.\u003c/p\u003e\n"],["\u003cp\u003eObject logging is set up by creating a custom auditor role, setting \u003ccode\u003epgaudit.role\u003c/code\u003e to the auditor role name, and then granting the role permissions on specific database relations and optionally, specific columns.\u003c/p\u003e\n"],["\u003cp\u003eOnly database users created via the Google Cloud console or \u003ccode\u003egcloud\u003c/code\u003e command can modify pgAudit settings, unlike users created with \u003ccode\u003eCREATE ROLE\u003c/code\u003e command.\u003c/p\u003e\n"]]],[],null,["# Configure logging behavior\n\nTo configure pgAudit logging behavior, you set the `pgaudit.log`\nflag or the `pgaudit.role` flag:\n\n- Set `pgaudit.log` to enable and configure session logging. You can\n set this flag on an instance, a database, or a role to define the scope of\n operations that the pgAudit logs. You set the flag to a value that defines\n the type of operations that the pgAudit logs.\n\n- Set `pgaudit.role` to enable and configure object logging, which\n logs statements that affect particular relations. You set this flag to the name\n of a role, and then grant statement access to specific objects that you want to\n be logged. The statement access includes `SELECT, INSERT, UPDATE, and\n DELETE`. pgAudit logs all operations that match the combination of\n access and object run by any user.\n\nThe following sections provide examples that show the options for setting\npgAudit logging behavior.\n| **Note:** Database users created through `CREATE ROLE` commands do not have the privilege to modify audit settings. Only database users created through the Google Cloud console and the gcloud command can modify audit settings.\n\nFor additional capabilities of the extension, review the\n[pgAudit documentation](https://github.com/pgaudit/pgaudit/blob/master/README.md/).\n\nConfigure session audit logging for all databases in an instance\n----------------------------------------------------------------\n\nTo configure auditing for all databases in an instance, set the\n`pgaudit.log` flag at the instance level.\n\nFor example:\n\n- To enable auditing for all operations on all databases in an instance: \n\n ```\n gcloud alloydb instances update my-instance \\\n --database-flags pgaudit.log=all[,flag2=value2...] \\\n --region=us-central1 \\\n --cluster=my-cluster \\\n --project=my-project\n ```\n- To enable auditing for only read and write operations on all databases in an instance: \n\n ```\n gcloud alloydb instances update my-instance \\\n --database-flags=^:^pgaudit.log=read,write[:flag2=value2...] \\\n --region=us-central1 \\\n --cluster=my-cluster \\\n --project=my-project\n ```\n\nNote the use of [alternate delimiter\nsyntax](/sdk/gcloud/reference/topic/escaping), which lets you use comma\ncharacters within a flag value.\n\nFor information about configuring database flags,\nsee [Configure database flags](/alloydb/docs/instance-configure-database-flags).\n\nConfigure session audit logging for a specific database\n-------------------------------------------------------\n\nYou can configure auditing for a specific database by setting the `pgaudit.log`\nflag at the database-level.\n\nFor example, to enable read/write auditing for a database, finance:\n\n`finance=\u003e ALTER DATABASE finance SET pgaudit.log = 'read,write';`\n\nConfigure session audit logging for a single user\n-------------------------------------------------\n\nYou can enable auditing for a specific user by setting the `pgaudit.log`\non a per role level.\n\nFor example, to set auditing for all database operations executed by the user,\nAlice:\n\n`finance=\u003e ALTER ROLE alice SET pgaudit.log = 'all';`\n\nConfigure object audit logging\n------------------------------\n\nAuditing for a relation is narrower than auditing for a specific database. When\nyou audit for a relation, the system assigns a unique auditor role to the\n`pgaudit.role` parameter. This operation logs any object or relation\nthat is granted to this role.\n\nFor example:\n\n- To configure auditing for all `SELECT` queries on the salary relation within the employee database: \n\n employee=\u003e CREATE ROLE auditor WITH NOLOGIN;\n employee=\u003e ALTER DATABASE employee SET pgaudit.role = 'auditor';\n employee=\u003e GRANT SELECT ON salary TO auditor;\n\nYou also can audit a subset of columns for a given relation.\n\nFor example:\n\n- To configure audit logging that occurs only when the `income` and `tax_status` columns are accessed from the salary relation: \n\n employee=\u003e GRANT SELECT(income, tax_status) ON salary TO auditor;"]]