Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Um das pgAudit-Loggingverhalten zu konfigurieren, legen Sie das Flag pgaudit.log oder das Flag pgaudit.role fest:
Legen Sie pgaudit.log fest, um das Sitzungsprotokollieren zu aktivieren und zu konfigurieren. Sie können dieses Flag für eine Instanz, eine Datenbank oder eine Rolle festlegen, um den Umfang der Vorgänge zu definieren, die von pgAudit protokolliert werden. Sie legen das Flag auf einen Wert fest, der den Typ der Vorgänge definiert, die von pgAudit protokolliert werden.
Legen Sie pgaudit.role fest, um das Objekt-Logging zu aktivieren und zu konfigurieren. Dabei werden Anweisungen protokolliert, die sich auf bestimmte Beziehungen auswirken. Sie legen dieses Flag auf den Namen einer Rolle fest und gewähren dann Zugriff auf bestimmte Objekte, die protokolliert werden sollen. Der Kontoauszug enthält SELECT, INSERT, UPDATE, and
DELETE. pgAudit protokolliert alle Vorgänge, die der Kombination aus Zugriff und Objekt entsprechen, die von einem beliebigen Nutzer ausgeführt werden.
In den folgenden Abschnitten finden Sie Beispiele für die Optionen zum Festlegen des pgAudit-Logging-Verhaltens.
Informationen zu weiteren Funktionen der Erweiterung finden Sie in der pgAudit-Dokumentation.
Sitzungs-Audit-Logging für alle Datenbanken in einer Instanz konfigurieren
Wenn Sie die Prüfung für alle Datenbanken in einer Instanz konfigurieren möchten, legen Sie das Flag pgaudit.log auf Instanzebene fest.
Beispiel:
So aktivieren Sie die Prüfung für alle Vorgänge für alle Datenbanken in einer Instanz:
Sitzungs-Audit-Logging für eine bestimmte Datenbank konfigurieren
Sie können die Prüfung für eine bestimmte Datenbank konfigurieren, indem Sie das Flag pgaudit.log auf Datenbankebene festlegen.
So aktivieren Sie beispielsweise die Lese-/Schreibprüfung für eine Datenbank namens „finance“:
finance=> ALTER DATABASE finance SET pgaudit.log = 'read,write';
Sitzungs-Audit-Logging für einen einzelnen Nutzer konfigurieren
Sie können die Prüfung für einen bestimmten Nutzer aktivieren, indem Sie pgaudit.log auf Rollenebene festlegen.
So legen Sie beispielsweise die Prüfung für alle Datenbankvorgänge fest, die vom Nutzer Alice ausgeführt werden:
finance=> ALTER ROLE alice SET pgaudit.log = 'all';
Audit-Logging für Objekte konfigurieren
Die Prüfung für eine Beziehung ist weniger umfassend als die Prüfung für eine bestimmte Datenbank. Beim Prüfen einer Beziehung wird dem Parameter pgaudit.role eine spezielle Prüferrolle zugewiesen. Bei diesem Vorgang werden alle Objekte oder Beziehungen protokolliert, die dieser Rolle zugewiesen werden.
Beispiel:
So konfigurieren Sie die Prüfung für alle SELECT-Abfragen in der Beziehung „salary“ in der Mitarbeiterdatenbank:
employee=> CREATE ROLE auditor WITH NOLOGIN;employee=> ALTER DATABASE employee SET pgaudit.role = 'auditor';employee=> GRANT SELECT ON salary TO auditor;
Sie können auch nur einen Teil der Spalten für eine bestimmte Beziehung prüfen.
Beispiel:
So konfigurieren Sie das Audit-Logging, das nur erfolgt, wenn auf die Spalten income und tax_status über die Gehaltsbeziehung zugegriffen wird:
employee=> GRANT SELECT(income, tax_status) ON salary TO auditor;
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 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;"]]