Save or share SQL queries

This document describes how to save and share queries that you create inLog Analytics.

For information about how to chart your queries or and sample queries,see the documents listed in theWhat's next section of this document.

Before you begin

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.create permission.Learn how to grant roles.
    Note: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.

    Go to project selector

  3. Verify that billing is enabled for your Google Cloud project.

  4. Enable the Observability API.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enable permission.Learn how to grant roles.

    Enable the API

  5. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.create permission.Learn how to grant roles.
    Note: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.

    Go to project selector

  6. Verify that billing is enabled for your Google Cloud project.

  7. Enable the Observability API.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enable permission.Learn how to grant roles.

    Enable the API

  8. To get the permissions that you need to load theLog Analytics page, write, run, and save privatequeries, ask your administrator to grant you the following IAM roles:

    • Observability View Accessor (roles/observability.viewAccessor) on the observability views that you want to query. This role supports IAM conditions, which let you restrict the grant to a specific view. If you don't attach a condition to the role grant, then the principal can access all observability views. Observability views are in Public Preview.
    • Observability Analytics User (roles/observability.analyticsUser) on your project. This role contains the permissions required to save and run private queries, and to run shared queries.
    • Logs Viewer (roles/logging.viewer) on your project.
    • Logs View Accessor (roles/logging.viewAccessor) on the project that stores the log views that you want to query.

    For more information about granting roles, seeManage access to projects, folders, and organizations.

    You might also be able to get the required permissions throughcustom roles or otherpredefined roles.

    Note: If you want to create and manage shared queries, then the previous IAM roles aren't sufficient. To create and manage shared queries, your IAM roles must include thelogging.queries.{share, updateShared, deleteShared} permissions.

Save a query

All queries that you run are automatically saved for30 days and are accessible by selecting theRecent tabon theLog Analytics page. You can search, view, run, and share thequeries that are listed on theRecent tab.

If you want to keep a query available for future use, annotate it withinformation that is useful to you, or let teammates view and run your query,then save the query. You can search and sort your saved queries by theirname, their description, and their visibility label. You can also editand delete these queries. Queries that you save are retained until you deletethem.

You can save 10,000 queries per Google Cloud project.

Console

To save a query, do the following:

  1. In the Google Cloud console, go to theLog Analytics page:

    Go toLog Analytics

    If you use the search bar to find this page, then select the result whose subheading isLogging.

  2. Populate theQuery pane with a query.

    You can populate theQuery pane by entering a new query,by selecting a query from theRecent tab, or byselecting a query from theSaved tab.

    Your query can include any valid view, multiple views, andanalytics views.

    When the query in theQuery pane is valid,theSave is enabled.

  3. ClickSave, selectSave query,and complete theName andDescription fields.The values you set for these fields are shown on theSaved tab.

  4. Optional: To let everyone with access to theLog Analytics page for the Google Cloud project view and run yoursaved query, enable theShare with project toggle.

    By default, this toggle is disabled and the visibility is restricted to you.

  5. ClickSave query.

  6. Optional: To view, sort, and run saved queries that are visible to you,select theSaved tab.

    You can sort and filter your saved queries by their name, description, andvisibility label. You can also filter by the contents of the query.

You can edit and delete queries that you created by using options ontheSaved tab:

  • To edit a query,clickMore Options and selectEdit.You can modify the values for theName andDescription fields; however, the query itself can't bemodified.

  • To delete a saved query,clickMore Options and selectDelete.

Share a query

You can share a saved query with everyone that has access to yourGoogle Cloud project. However, the principal's IAM roles determinewhether the query can be run and the data that the query returns.

Console

When troubleshooting a problem, or when you see anomalous results, you mightwant to share a query and its results with a teammate. When you are viewingquery results on theLog Analytics page, you can copy a URL that,when opened, displays the query you ran and its results.

To share a query and results with a teammate, do the following:

  1. In the Google Cloud console, go to theLog Analytics page:

    Go toLog Analytics

    If you use the search bar to find this page, then select the result whose subheading isLogging.

  2. Populate theQuery pane with a query and then clickRun query.

    You can populate theQuery pane by entering a new query,by selecting a query from theRecent tab, or byselecting a query from theSaved tab.

  3. ClickShare link.

  4. Send the link to your teammate.

    When your teammate opens the link, theLog Analytics page opens anddisplays, but doesn't run, the query. Your teammate must manually run thequery.

    TheLog Analytics page displays a warning dialog when the query runs on theBigQuery engine and the queried resources aren't in the sameownership boundary. Ownership boundaries are determined by several factors,one of which is the hierarchy of the resources the query uses.

    To open the URL successfully, your teammate's IAM roleon the Google Cloud project must include the permissions required to view theLog Analytics page.

View and run recent or saved queries

To view or re-run a query, select theRecent tabon theLog Analytics page and find the query:

  • To run the query, clickRun.
  • To view the query, use the options in theMore Options menu.

To view, edit, or run a saved query, select theSaved tabon theLog Analytics page and find the query:

  • To run the query, clickRun.
  • To edit, view, or delete the query, use the options in theMore Options menu.

What's next

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 2026-02-19 UTC.