Triage and Remediation
- Remediation
Remediation
Using Console
Using Console
To remediate the misconfiguration “PostgreSQL Log Statement Stats Flag Should Be Set Appropriately” for GCP using GCP console, you can follow the below steps:
- Open the Cloud SQL instances page in the GCP console.
- Select the instance for which you want to remediate the misconfiguration.
- Click on the “Edit” button at the top of the page.
- In the “Flags” section, click on the “Add item” button.
- Enter the flag name “log_statement_stats” and set its value to “on”.
- Click on the “Save” button to save the changes.
Using CLI
Using CLI
To remediate the PostgreSQL Log Statement Stats Flag misconfiguration in GCP using GCP CLI, follow these steps:
- Open the Cloud Shell in your GCP project.
-
Run the following command to list all the instances in your project:
- Identify the instance that has PostgreSQL database engine.
-
Run the following command to update the PostgreSQL flags for the identified instance:
Replace
[INSTANCE_NAME]with the name of the identified instance. -
Verify the PostgreSQL flags by running the following command:
Replace
[INSTANCE_NAME]with the name of the identified instance. The output of the command should show that thelog_statement_statsflag is set toon.
Using Python
Using Python
To remediate the PostgreSQL Log Statement Stats Flag misconfiguration in GCP using Python, follow these steps:By following these steps, you will have successfully remediated the PostgreSQL Log Statement Stats Flag misconfiguration in GCP using Python.
- Install the
google-cloud-secret-managerandgoogle-cloud-secret-managerlibraries using pip:
- Authenticate to GCP using a service account:
- Retrieve the PostgreSQL instance connection string and credentials from GCP Secret Manager:
- Connect to the PostgreSQL instance using the
psycopg2library:
- Set the
log_statement_statsparameter toon:
- Close the database connection:
Using Terraform
Using Terraform
terraform plan should show an in-place update to settings.0.database_flags for log_statement_stats (and removal/disablement of the other stats flags if you included them).
