# 6.2.8 Ensure the 'cloudsql.enable_pgaudit' Database Flag for Each Cloud SQL PostgreSQL Instance Is Set to 'on' for Centralized Logging (Automated)

- Source: https://support.icompaas.com/support/solutions/articles/62000233039-6-2-8-ensure-the-cloudsql-enable-pgaudit-database-flag-for-each-cloud-sql-postgresql-instance-is-se
- Section: [Solutions](https://support.icompaas.com/support/solutions) › [GCP Benchmarks](https://support.icompaas.com/support/solutions/62000112667) › [GCP Knowledge Bases](https://support.icompaas.com/support/solutions/folders/62000169178)
- Last updated: 2026-05-29
- Publisher: iCompaas, Inc. (https://www.icompaas.com)

Profile Applicability:

-   Level 1

Description:

The cloudsql.enable\_pgaudit database flag enables database auditing in PostgreSQL using the open-source pgAudit extension. This flag facilitates centralized logging, allowing detailed session and object logging for compliance with regulatory and organizational standards. Enabling this flag ensures the audit logs are sent to Google Logs Explorer for centralized access.

Rationale:

By enabling the cloudsql.enable\_pgaudit flag, PostgreSQL audit logs are collected in a centralized location, simplifying compliance with government, financial, and ISO standards. It provides robust monitoring of security events, allowing organizations to mitigate risks and ensure visibility into database activity. This is particularly useful for tracking security events and managing data access logs.

Impact:

-   Storage Overhead: Enabling pg Audit may lead to increased data storage requirements.
    
-   Instance Restart: Applying the flag requires a restart of the PostgreSQL instance.
    
-   Flag Overwrites: Enabling this flag via CLI overwrites any previously configured flags unless explicitly re-applied.
    
-   It is recommended to enable the flag during periods of low usage to minimize disruptions.
    

Default Value:

By default, the cloudsql.enable\_pg audit flag is set to off, and the pgAudit extension is not enabled.

Audit Steps:

#### Verify the cloudsql.enable\_pgaudit Flag:

##### Using Google Cloud Console:

1.  Navigate to [Cloud SQL Instances](https://console.cloud.google.com/sql/instances).
    

                     ![](https://support.icompaas.com/assets/kb/ed1e2924d778cd2d.png)

2.  Select the PostgreSQL instance to open the Overview page.
    

     ![](https://support.icompaas.com/assets/kb/28bf8c32c97c63f8.png)

3.  Under Configuration > Flags, verify that the cloudsql.enable\_pgaudit flag is set to on.
    

       ![](https://support.icompaas.com/assets/kb/bb985d76854a9a39.png)

##### Using Google Cloud CLI:

Run the following command:

gcloud sql instances describe \[INSTANCE\_NAME\] --format="json" | jq '.settings.databaseFlags\[\] | select(.name=="cloudsql.enable\_pgaudit")|.value'

1.  Ensure the returned value is on.
    

Verify the pgAudit Extension Installation:

1.  Connect to the PostgreSQL instance via a SQL client or psql.
    

Run the following command:

SELECT \* FROM pg\_extension;

2.  Confirm that pgAudit is listed in the results.
    

Verify Logs in Logs Explorer:

1.  Navigate to Logs Explorer in the Google Cloud Console.
    

Run the following query:

resource.type="cloudsql\_database"  
logName="projects/\[PROJECT\_ID\]/logs/cloudaudit.googleapis.com%2Fdata\_access"  
protoPayload.request.@type="type.googleapis.com/google.cloud.sql.audit.v1.PgAuditEntry"

2.  Confirm that logs are being correctly collected and displayed.
    

Remediation Steps:

#### Enable the cloudsql.enable\_pgaudit Flag:

##### Using Google Cloud Console:

1.  Go to [Cloud SQL Instances](https://console.cloud.google.com/sql/instances).
    

                ![](https://support.icompaas.com/assets/kb/d54b47298559d3c1.png)

2.  Select the PostgreSQL instance and click Edit.
    

      ![](https://support.icompaas.com/assets/kb/1983a43f1ae8d526.png)

3.  Scroll down to the Flags section.
    

                   ![](https://support.icompaas.com/assets/kb/e1b166f6d17649b2.png)

4.  Click Add Item and set the flag:
    

                ![](https://support.icompaas.com/assets/kb/47516585dbcc8349.png)

-   Name: cloudsql.enable\_pgaudit 
    
-   Value: on
    

   ![](https://support.icompaas.com/assets/kb/ca5230e51748a570.png)

5.  Click Save and confirm the changes.
    

                     ![](https://support.icompaas.com/assets/kb/c8ea4fab9c6dc714.png)

6.  Restart the instance to apply the changes.
    

           ![](https://support.icompaas.com/assets/kb/b891d5b4e34f3f8e.png)

##### Using Google Cloud CLI:

Run the following command:

gcloud sql instances patch \[INSTANCE\_NAME\] --database-flags cloudsql.enable\_pgaudit=on

1.  Restart the instance for the changes to take effect.
    

Install the pgAudit Extension:

1.  Connect to the PostgreSQL instance via a SQL client or psql.
    

Run the following command as a superuser:

CREATE EXTENSION pgaudit;

Customize Audit Logging (Optional):

-   To enable logging for all databases:
    
    -   From Console: Set pgaudit.log=all in the Flags section.
        
        gcloud sql instances patch \[INSTANCE\_NAME\] --database-flags cloudsql.enable\_pgaudit=on,pgaudit.log=all
        

Backout Plan:

Step 1: Disable pgAudit If Necessary

gcloud sql instances patch <INSTANCE\_NAME> --database-flags cloudsql.enable\_pgaudit=off

Restart the instance to apply changes:

gcloud sql instances restart <INSTANCE\_NAME>

Step 2: Notify Security Teams

-   Inform security teams before disabling pgAudit.
    

Step 3: Restore from Backup (If Necessary)

-   If pgAudit causes failures, restore the PostgreSQL instance from a **backup.**
    

References:

1.  [Google Cloud SQL PostgreSQL Flags Documentation](https://cloud.google.com/sql/docs/postgres/flags#list-flags-postgres)
    
2.  [Enable pgAudit on Cloud SQL](https://cloud.google.com/sql/docs/postgres/pg-audit#enable-auditing-flag)
    
3.  [Customizing pgAudit Logging](https://cloud.google.com/sql/docs/postgres/pg-audit#customizing-database-audit-logging)
    
4.  [Audit Logging Configuration](https://cloud.google.com/logging/docs/audit/configure-data-access#configconsole-enable)
    

Additional Information:

-   Restart Required: Configuring the cloudsql.enable\_pgaudit flag requires restarting the PostgreSQL instance.
    
-   Centralized Logging: Logs collected via the pgAudit extension can be centrally managed in Google Logs Explorer for enhanced visibility and forensic analysis.
    

CIS Controls:

<table style="border:none;border-collapse:collapse"><colgroup style="font-family:&quot;Helvetica Neue&quot;"><col style="font-family:&quot;Helvetica Neue&quot;"><col style="font-family:&quot;Helvetica Neue&quot;"><col style="font-family:&quot;Helvetica Neue&quot;"><col style="font-family:&quot;Helvetica Neue&quot;"><col style="font-family:&quot;Helvetica Neue&quot;"></colgroup><tbody><tr style="height:40pt;font-family:&quot;Helvetica Neue&quot;"><td style="padding:5pt;overflow:hidden;overflow-wrap:break-word;font-family:&quot;Helvetica Neue&quot;;font-size:14px"><p dir="ltr" style="line-height:1.38;text-align:justify;margin-bottom:0pt;font-family:&quot;Helvetica Neue&quot;;font-size:14px"><span style="font-family:Helvetica Neue"><span style="font-size:14px"><span style="color:rgb(0, 0, 0);font-weight:700">Control</span></span></span></p></td><td style="padding:5pt;overflow:hidden;overflow-wrap:break-word;font-family:&quot;Helvetica Neue&quot;;font-size:14px"><p dir="ltr" style="line-height:1.38;text-align:justify;margin-bottom:0pt;font-family:&quot;Helvetica Neue&quot;;font-size:14px"><span style="font-family:Helvetica Neue"><span style="font-size:14px"><span style="color:rgb(0, 0, 0);font-weight:700">Description</span></span></span></p></td><td style="padding:5pt;overflow:hidden;overflow-wrap:break-word;font-family:&quot;Helvetica Neue&quot;;font-size:14px"><p dir="ltr" style="line-height:1.38;text-align:justify;margin-bottom:0pt;font-family:&quot;Helvetica Neue&quot;;font-size:14px"><span style="font-family:Helvetica Neue"><span style="font-size:14px"><span style="color:rgb(0, 0, 0);font-weight:700">IG 1</span></span></span></p></td><td style="padding:5pt;overflow:hidden;overflow-wrap:break-word;font-family:&quot;Helvetica Neue&quot;;font-size:14px"><p dir="ltr" style="line-height:1.38;text-align:justify;margin-bottom:0pt;font-family:&quot;Helvetica Neue&quot;;font-size:14px"><span style="font-family:Helvetica Neue"><span style="font-size:14px"><span style="color:rgb(0, 0, 0);font-weight:700">IG 2</span></span></span></p></td><td style="padding:5pt;overflow:hidden;overflow-wrap:break-word;font-family:&quot;Helvetica Neue&quot;;font-size:14px"><p dir="ltr" style="line-height:1.38;text-align:justify;margin-bottom:0pt;font-family:&quot;Helvetica Neue&quot;;font-size:14px"><span style="font-family:Helvetica Neue"><span style="font-size:14px"><span style="color:rgb(0, 0, 0);font-weight:700">IG 3</span></span></span></p></td></tr><tr style="height:40pt;font-family:&quot;Helvetica Neue&quot;"><td style="padding:5pt;overflow:hidden;overflow-wrap:break-word;font-family:&quot;Helvetica Neue&quot;;font-size:14px"><p dir="ltr" style="line-height:1.38;margin-bottom:0pt;font-family:&quot;Helvetica Neue&quot;;text-align:left;font-size:14px"><span style="font-family:Helvetica Neue"><span style="font-size:14px"><span style="color:rgb(0, 0, 0)">8.5 Collect Detailed Audit Logs</span></span></span></p></td><td style="padding:5pt;overflow:hidden;overflow-wrap:break-word;font-family:&quot;Helvetica Neue&quot;;font-size:14px"><p dir="ltr" style="line-height:1.38;margin-bottom:0pt;font-family:&quot;Helvetica Neue&quot;;text-align:left;font-size:14px"><span style="font-family:Helvetica Neue"><span style="font-size:14px"><strong><span style="color:rgb(0, 0, 0);font-weight:400">Configure detailed audit logging for enterprise assets containing sensitive data for forensic investigations.</span></strong></span></span></p></td><td style="padding:5pt;overflow:hidden;overflow-wrap:break-word;font-family:&quot;Helvetica Neue&quot;;font-size:14px"><p dir="ltr" style="line-height:1.38;margin-bottom:0pt;font-family:&quot;Helvetica Neue&quot;;text-align:left;font-size:14px"><span style="font-family:Helvetica Neue"><span style="font-size:14px"><strong><span style="color:rgb(0, 0, 0);font-weight:400">✅</span></strong></span></span></p></td><td style="padding:5pt;overflow:hidden;overflow-wrap:break-word;font-family:&quot;Helvetica Neue&quot;;font-size:14px"><p dir="ltr" style="line-height:1.38;margin-bottom:0pt;font-family:&quot;Helvetica Neue&quot;;text-align:justify;font-size:14px"><span style="font-family:Helvetica Neue"><span style="font-size:14px"><strong><span style="color:rgb(0, 0, 0);font-weight:400">✅</span></strong></span></span></p></td><td style="padding:5pt;overflow:hidden;overflow-wrap:break-word;font-family:&quot;Helvetica Neue&quot;;font-size:14px"><div style="text-align:justify;font-size:14px"><span style="font-family:Helvetica Neue"><span style="font-size:14px"><strong><br style="font-family:&quot;Helvetica Neue&quot;"></strong></span></span></div></td></tr><tr style="height:40pt;font-family:&quot;Helvetica Neue&quot;"><td style="padding:5pt;overflow:hidden;overflow-wrap:break-word;font-family:&quot;Helvetica Neue&quot;;font-size:14px"><p dir="ltr" style="line-height:1.38;margin-bottom:0pt;font-family:&quot;Helvetica Neue&quot;;text-align:left;font-size:14px"><span style="font-family:Helvetica Neue"><span style="font-size:14px"><span style="color:rgb(0, 0, 0)">8.9 Centralize Audit Logs</span></span></span></p></td><td style="padding:5pt;overflow:hidden;overflow-wrap:break-word;font-family:&quot;Helvetica Neue&quot;;font-size:14px"><p dir="ltr" style="line-height:1.38;margin-bottom:0pt;font-family:&quot;Helvetica Neue&quot;;text-align:left;font-size:14px"><span style="font-family:Helvetica Neue"><span style="font-size:14px"><strong><span style="color:rgb(0, 0, 0);font-weight:400">Aggregate audit logs in a central management system for streamlined analysis and security oversight.</span></strong></span></span></p></td><td style="padding:5pt;overflow:hidden;overflow-wrap:break-word;font-family:&quot;Helvetica Neue&quot;;font-size:14px"><p dir="ltr" style="line-height:1.38;margin-bottom:0pt;font-family:&quot;Helvetica Neue&quot;;text-align:left;font-size:14px"><span style="font-family:Helvetica Neue"><span style="font-size:14px"><strong><span style="color:rgb(0, 0, 0);font-weight:400">✅</span></strong></span></span></p></td><td style="padding:5pt;overflow:hidden;overflow-wrap:break-word;font-family:&quot;Helvetica Neue&quot;;font-size:14px"><p dir="ltr" style="line-height:1.38;margin-bottom:0pt;font-family:&quot;Helvetica Neue&quot;;text-align:justify;font-size:14px"><span style="font-family:Helvetica Neue"><span style="font-size:14px"><strong><span style="color:rgb(0, 0, 0);font-weight:400">✅</span></strong></span></span></p></td><td style="padding:5pt;overflow:hidden;overflow-wrap:break-word;font-family:&quot;Helvetica Neue&quot;;font-size:14px"><div style="text-align:justify;font-size:14px"><span style="font-family:Helvetica Neue"><span style="font-size:14px"><strong><br style="font-family:&quot;Helvetica Neue&quot;"></strong></span></span></div></td></tr><tr style="height:54.25pt;font-family:&quot;Helvetica Neue&quot;"><td style="padding:5pt;overflow:hidden;overflow-wrap:break-word;font-family:&quot;Helvetica Neue&quot;;font-size:14px"><p dir="ltr" style="line-height:1.38;margin-bottom:0pt;font-family:&quot;Helvetica Neue&quot;;text-align:left;font-size:14px"><span style="font-family:Helvetica Neue"><span style="font-size:14px"><span style="color:rgb(0, 0, 0)">6.3 Enable Detailed Logging</span></span></span></p></td><td style="padding:5pt;overflow:hidden;overflow-wrap:break-word;font-family:&quot;Helvetica Neue&quot;;font-size:14px"><p dir="ltr" style="line-height:1.38;margin-bottom:0pt;font-family:&quot;Helvetica Neue&quot;;text-align:left;font-size:14px"><span style="font-family:Helvetica Neue"><span style="font-size:14px"><strong><span style="color:rgb(0, 0, 0);font-weight:400">Enable detailed system logging, capturing event source, timestamps, and other elements for investigation and troubleshooting.</span></strong></span></span></p></td><td style="padding:5pt;overflow:hidden;overflow-wrap:break-word;font-family:&quot;Helvetica Neue&quot;;font-size:14px"><p dir="ltr" style="line-height:1.38;margin-bottom:0pt;font-family:&quot;Helvetica Neue&quot;;text-align:left;font-size:14px"><span style="font-family:Helvetica Neue"><span style="font-size:14px"><strong><span style="color:rgb(0, 0, 0);font-weight:400">✅</span></strong></span></span></p></td><td style="padding:5pt;overflow:hidden;overflow-wrap:break-word;font-family:&quot;Helvetica Neue&quot;;font-size:14px"><p dir="ltr" style="line-height:1.38;margin-bottom:0pt;font-family:&quot;Helvetica Neue&quot;;text-align:justify;font-size:14px"><span style="font-family:Helvetica Neue"><span style="font-size:14px"><strong><span style="color:rgb(0, 0, 0);font-weight:400">✅</span></strong></span></span></p></td><td style="padding:5pt;overflow:hidden;overflow-wrap:break-word;font-family:&quot;Helvetica Neue&quot;;font-size:14px"><div style="text-align:justify;font-size:14px"><span style="font-family:Helvetica Neue"><span style="font-size:14px"><strong><br style="font-family:&quot;Helvetica Neue&quot;"></strong></span></span></div></td></tr><tr style="height:40pt"><td style="padding:5pt;overflow:hidden;overflow-wrap:break-word;font-family:&quot;Helvetica Neue&quot;;font-size:14px"><p dir="ltr" style="line-height:1.38;margin-bottom:0pt;font-family:&quot;Helvetica Neue&quot;;text-align:left;font-size:14px"><span style="font-family:Helvetica Neue"><span style="font-size:14px"><span style="color:rgb(0, 0, 0)">6.5 Central Log Management</span></span></span></p></td><td style="padding:5pt;overflow:hidden;overflow-wrap:break-word;font-family:&quot;Helvetica Neue&quot;;font-size:14px"><p dir="ltr" style="line-height:1.38;margin-bottom:0pt;font-family:&quot;Helvetica Neue&quot;;text-align:left;font-size:14px"><span style="font-family:Helvetica Neue"><span style="font-size:14px"><strong><span style="color:rgb(0, 0, 0);font-weight:400">Use a central log management system to ensure logs are aggregated for comprehensive monitoring and review.</span></strong></span></span></p></td><td style="padding:5pt;overflow:hidden;overflow-wrap:break-word;font-family:&quot;Helvetica Neue&quot;;font-size:14px"><p dir="ltr" style="line-height:1.38;margin-bottom:0pt;font-family:&quot;Helvetica Neue&quot;;text-align:left;font-size:14px"><span style="font-family:Helvetica Neue"><span style="font-size:14px"><strong><span style="color:rgb(0, 0, 0);font-weight:400">✅</span></strong></span></span></p></td><td style="padding:5pt;overflow:hidden;overflow-wrap:break-word;font-family:&quot;Helvetica Neue&quot;;font-size:14px"><p dir="ltr" style="line-height:1.38;margin-bottom:0pt;font-family:&quot;Helvetica Neue&quot;;text-align:justify;font-size:14px"><span style="font-family:Helvetica Neue"><span style="font-size:14px"><strong><span style="color:rgb(0, 0, 0);font-weight:400">✅</span></strong></span></span></p></td><td style="padding:5pt;overflow:hidden;overflow-wrap:break-word;font-size:14px"><div style="text-align:justify;font-size:14px"><span style="font-family:Helvetica Neue"><span style="font-size:14px"><strong><br></strong></span></span></div></td></tr></tbody></table>

## Related compliance guidance

- [SOC 2 compliance: a practical implementation guide for cloud-native SaaS teams](https://support.icompaas.com/compliance/soc-2-trust-services-criteria): Configuration checks like this one are the technical half of a SOC 2 / ISO 27001 programme — the guide shows where they fit, what else an auditor expects, and how to evidence them.
- [ISO/IEC 27001:2022 compliance: a practical implementation guide](https://support.icompaas.com/compliance/iso-27001-2022): ISO 27001 Annex A.8 (technological controls) is where cloud hardening evidence lands; the guide shows how to run the ISMS around it.
