Skip to main content

Triage and Remediation

Remediation

Using Console

To remediate the “PostgreSQL Log Connections Flag Should Be On” misconfiguration on GCP using the GCP console, follow these steps:
  1. Go to the GCP Console and select the project that contains the PostgreSQL instance that needs to be remediated.
  2. In the left navigation pane, select “SQL” under the “Storage” section.
  3. Select the PostgreSQL instance that needs to be remediated.
  4. Click on the “Edit” button at the top of the page.
  5. Scroll down to the “Flags” section and click on the “Add Flag” button.
  6. In the “Name” field, enter “log_connections”.
  7. In the “Value” field, enter “on”.
  8. Click on the “Save” button at the bottom of the page to apply the changes.
  9. Wait for a few minutes for the changes to take effect.
After completing these steps, the “PostgreSQL Log Connections Flag Should Be On” misconfiguration will be remediated for the PostgreSQL instance on GCP.

To remediate the PostgreSQL Log Connections Flag Should Be On misconfiguration for GCP using GCP CLI, follow these steps:
  1. Open the Cloud Shell in the GCP Console.
  2. Run the following command to list the available PostgreSQL instances in your project:
  3. Note down the instance name of the PostgreSQL instance you want to remediate.
  4. Run the following command to enable the log_connections flag for the PostgreSQL instance:
    Replace [INSTANCE_NAME] with the name of your PostgreSQL instance.
  5. Confirm that the log_connections flag has been enabled by running the following command:
    Replace [INSTANCE_NAME] with the name of your PostgreSQL instance. The output should show that the log_connections flag is set to “on”.
  6. Your PostgreSQL instance is now remediated with the log_connections flag enabled.
To remediate the PostgreSQL log connections flag misconfiguration in GCP using Python, follow these steps:
  1. Install the google-cloud-secret-manager and google-auth Python libraries using pip:
  2. Import the necessary libraries and authenticate to the GCP project:
    Replace /path/to/key.json with the path to your GCP service account key file.
  3. Retrieve the value of the postgres-config secret:
  4. Update the postgresql.conf file to enable logging of connections:
  5. Write the updated configuration back to the secret:
    This will update the postgres-config secret with the new configuration that enables logging of connections.
  6. Verify that the configuration was updated successfully by checking the postgresql.conf file on the PostgreSQL server.
    The output should be on.
Changing database_flags is an in‑place update for Cloud SQL (no Terraform resource replacement), but it may cause a brief restart of the instance and momentary connection disruption.To verify, terraform plan should show an update to google_sql_database_instance.POSTGRES_INSTANCE.settings[0].database_flags adding or changing a flag with name = "log_connections" and value = "on".