Save, Share, and Export SQL Queries

You can save a SQL query at any point and continue working on it at a later time. You may also want to save a completed query and share the query as a search widget for future use by you or other users.

If you’ve created the widget based on a fixed time range, then every time that you open the widget, it will show the results for the time range that you specified in the search. By default, if you’ve created the widget for a relative time range (say the last 7 days), then every time that you open the widget, it will show the up-to-date results as per the time selector (Last 7 days). When the widget is referenced on a dashboard, it will reflect the page time selector setting.

Prerequisites:

The SQL Explorer Action menu allows you to save and share your SQL searches with others.

Save a Completed Search and Add It to a Dashboard

To save a SQL query and add it to a dashboard:

  1. From the Actions menu, select Save. The Save Search dialog displays.
  2. Select a compartment in which to save the search.
    Note

    There is no association between the selected compartment of the saved search and the underlying data being queried.
  3. Enter a Name and Description for the widget.

    Optionally, you can save the search widget and add it to a dashboard.

  4. Click the Add to dashboard option.
  5. Chose whether you want to add the widget to an existing dashboard (select the Dashboard Compartment and specific Dashboard) or create a new dashboard and supply the required information.
    Note

    Ops Insights provides the following out-of-box dashboards for Exadata:
    • Exadata Cell Dashboard - Hourly

      Hourly granularity dashboard for cell disk metrics.

    • Exadata IORM Dashboard - Hourly

      Hourly granularity dashboard for Exadata IORM-related metrics.

  6. Click Save.

Open a Previously Saved or Predefined Search

  1. From the Actions menu, select Open. The Open Search dialog displays.
  2. Choose a previously saved search or one of the predefined search widgets that comes with SQL Explorer.
  3. Click Open.

Delete a Saved Search

  1. From the Actions menu, select Delete. The Delete Search dialog displays.
  2. Choose a previously saved search.
  3. Click Delete.

Important: If you delete a saved search widget that is currently referenced by an existing dashboard, be aware that it's not automatically deleted from the dashboard. This will result in an error when accessing the dashboard.

Note

You cannot delete a predefined out-of-box search.

Create a Saved Search Query from an Existing One

You can create a customized search from an existing one using the Save As option.

  1. From the Actions menu, select Open. The Open Search dialog displays.
  2. Choose a previously saved or predefined search from the list.
  3. Click Open. The search criteria is displayed in SQL Explorer.
  4. Update the search criteria as needed.
  5. From the Actions menu, select Save As.
  6. Enter a new name for the updated search.
  7. Click Save.

Update the Name and Description of an Existing Search

While developing a SQL query, you may want to change the name and associated descriptive information of the search widget You can use the Edit option to make these changes.

  1. From the Actions menu, select Open if you are updating an existing search widget. The Open Search dialog displays.
  2. Select a compartment where the search widget resides.
    Note

    There is no association between the selected compartment of the saved search and the underlying data being queried.
  3. Select a search widget and click Open to display the search in SQL Explorer.
  4. From the Actions menu, select Edit. The Edit Search dialog displays.
  5. Enter a New Search Name and/or New Search Description.
  6. Click Edit to save the changes.

Create a New Search

To clear existing search criteria and start a new search, select Create New from the Actions menu.

Export Data

To export the data obtained from a search click on Export to CSV on the Saved Search menu. Data export has limitation that only 10,000 rows maximum can be fetched for a single query (using limit=1000, and pages=10). Alternatively you can export data via CLI (command line interface). Exporting via CLI is quite powerful and easy to use, see the sample below on how to obtain data using the CLI:
  • Sample using a JSON file:
    oci opsi
    opsi-data-objects query-data-templatized-query 
    --from-json file://./<file name>
    --compartment-id <compartment id>
    --limit 1000
    Where the JSON file contains the following:
    {
       "dataObjectIdentifier":"opsidataobject.dbinsights.f0819908-5ae3-4cb5-8a81-80a4ba888881",
       "query":{
          "queryType":"TEMPLATIZED_QUERY",
          "selectList":[
             "DB_DISPLAY_NAME, CDB_NAME, EXADATA_DISPLAY_NAME, VMCLUSTER_NAME, CPU_UTILIZATION, ROLLUP_TIME_UTC"
          ],
          "whereConditionsList":[
              
          ],
          "groupByList":[
              
          ],
          "havingConditionsList":[
              
          ],
          "orderByList":[
             "ROLLUP_TIME_UTC ASC"
          ],
          "timeFilters":{
             "timeStart":"2024-01-05T00:00:00.000Z",
             "timeEnd":"2024-01-12T00:00:00.000Z"
          }
       },
       "resourceFilters":{
          "compartmentIdInSubtree":false
       }
    }
  • Sample calling the query directly within the CLI command:
    oci opsi
    opsi-data-objects query-data-templatized-query 
    --compartment-id <compartment id>
    --data-object-identifier <data object id>
    --query-select-list '["DB_DISPLAY_NAME, CDB_NAME,EXADATA_DISPLAY_NAME, VMCLUSTER_NAME, CPU_UTILIZATION, ROLLUP_TIME_UTC"]'
    --query-order-by-list '["ROLLUP_TIME_UTC ASC"]'
    --limit 1000