How to reduce the Cloud SQL Logging cost in GCP?

131 Views Asked by At

I am currently checking for an option to reduce Cloud SQL logging cost (Cloud Logging cost in GCP). Currently the Cloud SQL instance is writing millions of log entries in stackdriver per day. Out of this 99% of the entries are INFO level. How can I avoid the INFO level entries that Cloud SQL generates in Cloud Logging and make only entries above INFO to be logged? Is there a configuration that I can make at Cloud SQL level or at Cloud Logging Level?

1

There are 1 best solutions below

0
On BEST ANSWER

You can control the Google Cloud SQL logging level via log_min_messages.

Controls which message levels are written to the server log. Valid values are DEBUG5, DEBUG4, DEBUG3, DEBUG2, DEBUG1, INFO, NOTICE, WARNING, ERROR, LOG, FATAL, and PANIC. Each level includes all the levels that follow it. The later the level, the fewer messages are sent to the log. The default is WARNING. Note that LOG has a different rank here than in client_min_messages. Only superusers and users with the appropriate SET privilege can change this setting.

I recommend changing database flags via the Google Cloud Console interface link.

  • In the Google Cloud console, select the project that contains the Cloud SQL instance for which you want to set a database flag.
  • Open the instance and click Edit.
  • Scroll down to the Flags section.
  • To set a flag that has not been set on the instance before, click Add item, choose the flag from the drop-down menu, and set its value.
  • Click Save to save your changes.
  • Confirm your changes under Flags on the Overview page.

This example uses the Google Cloud CLI:

gcloud sql instances patch INSTANCE_NAME --database-flags=log_min_messages=WARNING

This command will overwrite all database flags previously set. To keep those and add new ones, include the values for all flags you want set on the instance; any flag not specifically included is set to its default value. For flags that do not take a value, specify the flag name followed by an equals sign ("=").

Postgres documentation

Google Cloud SQL: Configure database flags