Stay organized with collections Save and categorize content based on your preferences.
This page describes how to find and use Cloud Logging to view and query logs for your Cloud SQL instance.
Cloud SQL uses Cloud Logging. See the cloud logging documentation for complete information and review the Cloud SQL sample queries.
View logsTo view logs for your Cloud SQL instance log entries:
ConsoleIn the Google Cloud console, go to the Cloud Logging page.
Use the gcloud logging
command to view log entries. In the example below, replace PROJECT_ID
. The limit
flag is an optional parameter that indicates the maximum number of entries to return.
gcloud logging read "resource.type=cloudsql_database" \ --project=PROJECT-ID \ --limit=10 \ --format=jsonView instance operations log
You can view the logs for an instance in the Operations pane. The Operations pane logs every operation performed on the instance with the following information:
If the operation fails, you can use the message to troubleshoot the problem.
To view an instance operations log:
In the Google Cloud console, go to the Cloud SQL Instances page.
The operations log does not include operations performed using external management tools, such as the psql client. Only user management and password change operations performed using the Google Cloud console,
gcloud
command-line tool, or the Cloud SQL Admin API appear in the operations log.
View application logsApplications that connect to Cloud SQL store their logs in different locations.
App Engine (flexible environment)In Compute > App Engine > Services:
In the Operations > Logging > Logs explorer section of Google Cloud console, use the following query:
resource.type="gae_app"
resource.labels.module_id="default"
Cloud Run
View the logs in the Cloud Run Logs Explorer section of the Google Cloud console. Note that Cloud Run reports only error messages from the Cloud SQL Auth Proxy. Use a query like the following:
resource.type="cloud_run_revision"
resource.labels.service_name="$SERVICE_NAME"
resource.labels.revision_name="$REVISION_NAME"
Cloud SQL Auth Proxy
In Operations > Logging > Logs explorer, use the following query:
log_id("appengine.googleapis.com/cloud-sql-proxy")
View audit logs
You can view the following types of audit logs for your Cloud SQL instances:
For more information about viewing Admin Activity, Data Access, and System Event audit logs, see View logs.
PricingFor more information about Cloud Logging pricing, see Cloud Logging pricing summary.
Troubleshoot Issue Troubleshooting Logging uses a lot of CPU and memory on your Cloud SQL instance. Logging needs to be tuned.The log_statement
flag can be set to none and the logging_collector
flag can be set to off. If logging is still occurring, there may be other log-related flags that can be tuned. You can edit the instance to modify these flags.
For example, a user was deleted but you can't find out who did it. The logs show the operation started but don't provide any more information. You must enable audit logging for detailed and personal identifying information (PII) like this to be logged.
Log files are hard to read. You'd rather view the logs as json or text.You can use thegcloud logging read
command along with linux post-processing commands to download the logs.
To download the logs as JSON:
gcloud logging read \ "resource.type=cloudsql_database \ AND logName=projects/PROJECT_ID \ /logs/cloudsql.googleapis.com%2FLOG_NAME" \ --format json \ --project=PROJECT_ID \ --freshness="1d" \ > downloaded-log.json
To download the logs as TEXT:
gcloud logging read \ "resource.type=cloudsql_database \ AND logName=projects/PROJECT_ID \ /logs/cloudsql.googleapis.com%2FLOG_NAME" \ --format json \ --project=PROJECT_ID \ --freshness="1d"| jq -rnc --stream 'fromstream(1|truncate_stream(inputs)) \ | .textPayload' \ --order=asc > downloaded-log.txtQuery logs are not found in PostgreSQL logs. You need to enable the pgaudit flags.
gcloud sql connect INSTANCE_NAME
CREATE EXTENSION pgaudit;
gcloud sql instances patch INSTANCE_NAME \ --database-flags=cloudsql.enable_pgaudit=on,pgaudit.log=all
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-07-02 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-07-02 UTC."],[],[]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4