An operations engineer is managing a production Cloud SQL for PostgreSQL database instance. To analyze query performance bottlenecks, the engineer needs to enable the `pg_stat_statements` extension and adjust database configuration flags. Modifying `shared_preload_libraries` requires a database restart to take effect. Which sequence of administrative actions must the engineer execute to properly apply this configuration using GCP standard practices?
- Execute `gcloud sql instances patch` specifying `--database-flags=shared_preload_libraries=pg_stat_statements`, allow the automatic restart to complete, and then connect to the database to run `CREATE EXTENSION pg_stat_statements;`.Answer
- BExport a service account private JSON key, upload the `pg_stat_statements` library file using `gcloud storage cp` directly into the underlying instance filesystem, and execute `gcloud sql instances restart`.
- CMigrate the PostgreSQL database tables to a Cloud Bigtable instance using `gcloud bigtable instances update` so that PostgreSQL extensions can be loaded dynamically without database downtime.
- DExecute `gsutil setmeta` on the underlying database storage bucket to set `shared_preload_libraries=pg_stat_statements`, then run `gcloud sql flags list` to refresh database settings.
Answer
The engineer must run `gcloud sql instances patch` with the `--database-flags` parameter specifying `shared_preload_libraries=pg_stat_statements`, wait for the instance to restart, and then execute `CREATE EXTENSION pg_stat_statements;` within a SQL client session.
In Cloud SQL for PostgreSQL, configuring database flags that alter preloaded shared libraries requires updating instance flags via `gcloud sql instances patch`. Cloud SQL handles the required instance restart automatically when static flags are modified. Once restarted, running `CREATE EXTENSION pg_stat_statements;` inside a SQL connection enables the extension features.
Step-by-Step Solution
Key Concept
Cloud SQL Database Flag Management and Extension Lifecycle