View instance logs

MySQL  |  PostgreSQL  |  SQL Server

This page describes how to find and use Cloud Logging to view and query logsfor your Cloud SQL instance.

Cloud SQL uses Cloud Logging. See thecloud logging documentationfor complete information and review theCloud SQL sample queries.

View logs

To view logs for your Cloud SQL instance log entries:

Console

  1. In the Google Cloud console, go to theCloud Logging page.

    Go to Cloud Logging

  2. Select an existing Cloud SQL project at the top of the page.
  3. In the Query builder, add the following:
    • Resource: selectCloud SQL Database. In the dialog, select a Cloud SQL instance.
    • Log names: scroll to the Cloud SQL section and select appropriate log files for your instance. For example:
      • cloudsql.googleapis.com/postgres.log
    • Severity: select a log level.
    • Time range: select a preset or create a custom range.

gcloud

Use thegcloud loggingcommand to view log entries. In the example below, replacePROJECT_ID.Thelimitflag is an optional parameter that indicates the maximum number of entries toreturn.

gcloudloggingread"resource.type=cloudsql_database"\--project=PROJECT-ID\--limit=10\--format=json

View instance operations log

You can view the logs for an instance in theOperations pane.TheOperations pane logs every operation performed on theinstance with the following information:

  • The time the operation completed, reported in your local time zone.
  • The type of operation.
  • The status of the operation.
  • A message describing the outcome the operation.

If the operation fails, you can use the message to troubleshoot the problem.

To view an instance operations log:

  1. In the Google Cloud console, go to theCloud SQL Instances page.

    Go to Cloud SQL Instances

  2. To open theOverview page of an instance, click the instance name.
  3. ClickOperations to change to the pane showing the operation log.
Note: The operations log does not include operations performed usingexternal management tools, such as the psql client. Only user management andpassword change operations performed using the Google Cloud console,gcloudcommand-line tool, or the Cloud SQL Admin API appear in the operations log.

View application logs

Applications that connect to Cloud SQL store their logs in differentlocations.

App Engine (flexible environment)

InCompute > App Engine > Services:

  • In the list of services, find your service.
  • Click on theTools dropdown.
  • Selectlogs

In theOperations > 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 RunLogs Explorer section of theGoogle Cloud console. Note that Cloud Run reports only error messages fromthe 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

InOperations > 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:

  • Admin Activity: include administrator operations that write metadata or configuration information. You can't deactivate these logs.
  • Data Access: include administrator operations that read metadata or configuration information. These logs also include operations that read or write user-provided data. To receive Data Access audit logs, you mustenable them explicitly.
  • System Event: identify automated actions in Google Cloud that modify the configuration of resources. You can't deactivate these logs.

For more information about viewing Admin Activity, Data Access, and System Event audit logs, seeView logs.

Pricing

For more information about Cloud Logging pricing, seeCloud Logging pricing summary.

Troubleshoot

IssueTroubleshooting
Logging uses a lot of CPU and memory on your Cloud SQL instance.Logging needs to be tuned.

Thelog_statement flag can be set to none and thelogging_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.

Audit logs are not found.Data-Access logs are only written if the operation is an authenticated user-driven API call that creates, modifies, or reads user-created data, or if the operation accesses configuration files or metadata of resources.
Operations information is not found in logs.You want to find more information about an operation.

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 mustenable 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:

gcloudloggingread\"resource.type=cloudsql_database \AND logName=projects/PROJECT_ID \/logs/cloudsql.googleapis.com%2FLOG_NAME"\--formatjson\--project=PROJECT_ID\--freshness="1d"\>downloaded-log.json

To download the logs as TEXT:

gcloudloggingread\"resource.type=cloudsql_database \AND logName=projects/PROJECT_ID \/logs/cloudsql.googleapis.com%2FLOG_NAME"\--formatjson\--project=PROJECT_ID\--freshness="1d"|jq-rnc--stream'fromstream(1|truncate_stream(inputs)) \| .textPayload'\--order=asc>downloaded-log.txt
Query logs are not found in PostgreSQL logs.You need to enable the pgaudit flags.
  1. From a terminal, connect to your database:
    gcloudsqlconnectINSTANCE_NAME
  2. Run this command to create the extension:
    CREATEEXTENSIONpgaudit;
  3. Exit the database, and from a terminal run the following command:
    gcloudsqlinstancespatchINSTANCE_NAME\--database-flags=cloudsql.enable_pgaudit=on,pgaudit.log=all

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-07-14 UTC.