# Query Console

Source: https://docs.ops0.com/docs/query-console

Ask questions about your infrastructure in plain English. The Query Console connects to your Oxid PostgreSQL backend and lets you explore resources, dependencies, costs, vulnerabilities, and project relationships without writing any code.

![ops0 Query Console showing the Schema Browser and SQL editor for a connected project](https://docs.ops0.com/images/query-console-overview.png)

---

## How It Works

Type a question in plain English. The Query Console translates it into a database query, runs it against your Oxid state backend, and returns the results.

**Example questions:**

- *"Show me all EC2 instances across my projects"*
- *"Which resources cost the most per month?"*
- *"What depends on my networking project?"*
- *"Show resources with critical vulnerabilities"*
- *"How many resources does each project manage?"*
- *"List all S3 buckets without encryption"*

No SQL knowledge required. Just describe what you want to know.

---

## What You Can Explore

- **Resources and State**: Browse all managed resources, their attributes, current state, and metadata across every project.

- **Dependencies**: See cross-resource and cross-project dependencies, module references, and terraform_remote_state links.

- **Cost Breakdown**: View cost estimates per resource, per project, or per cloud provider with cost overlays on results.

- **Vulnerabilities**: Surface Checkov findings and security issues alongside the resources they affect.

- **Project Connections**: See which projects share state, reference outputs from other projects, or deploy to the same accounts.

- **Resource Attributes**: Drill into any resource attribute like tags, regions, instance types, storage sizes, and configurations.

---

## Query Interface

| Component | Description |
|-----------|-------------|
| **Natural Language Input** | Type a question in plain English to explore your infrastructure |
| **Project Selector** | Scope queries to one or more Oxid-enabled projects |
| **Schema Browser** | Browse available tables, columns, and data types |
| **Cost Overlay** | Toggle cost data alongside query results |
| **Vulnerability Overlay** | Toggle vulnerability findings alongside query results |
| **Results Table** | Sortable, filterable results with pagination |

---

## Working with Results

| Feature | Description |
|---------|-------------|
| **Column Sorting** | Click column headers to sort ascending or descending |
| **Column Visibility** | Toggle which columns are shown |
| **Filtering** | Apply additional filters to narrow result rows |
| **Pagination** | Navigate through large result sets |
| **Row Selection** | Select rows for bulk operations |
| **Cost Column** | See estimated monthly cost per resource when cost overlay is enabled |
| **Vulnerability Column** | See severity and check details when vulnerability overlay is enabled |

---

## Saving and Sharing Queries

Save any query for quick access, share it with your team, or mark it as a favorite.

### Run Your Query
Type a question and get results.

### Click Save
Click the **Save** button in the toolbar.

### Name Your Query
Give it a descriptive name and optional description.

### Choose Visibility
Select whether the query is private or shared with your organization.

| Field | Description |
|-------|-------------|
| **Name** | Display name for the saved query |
| **Description** | Optional description of what the query does |
| **Projects** | Which projects the query targets |
| **Favorite** | Mark as favorite for quick access in the sidebar |
| **Usage Count** | How many times the query has been run |
| **Last Used** | When the query was last executed |

---

## Exporting Results

| Format | Use Case |
|--------|----------|
| **CSV** | Spreadsheet analysis, reporting, sharing with stakeholders |
| **JSON** | Integration with other tools, scripting, automation |

Click the **Export** button in the results toolbar to download the current result set.

---

## Sidebar Navigation

| Section | Description |
|---------|-------------|
| **Recent Queries** | Your most recently executed queries |
| **Favorites** | Queries you have marked as favorites |
| **Shared Queries** | Queries shared by your team |
| **Projects** | Browse queries grouped by project |

---

## Cost and Vulnerability Overlays

### Cost Overlay

When enabled, the Cost Overlay adds an estimated monthly cost column to query results. Costs are pulled from the deployment metadata stored by Oxid — specifically the `costEstimate` values written to state after each apply. Costs are aggregated by resource address, module prefix, and array index so each row in results maps to its corresponding resource cost.

### Vulnerability Overlay

When enabled, the Vulnerability Overlay adds a severity column showing Checkov and Trivy findings for each resource. The overlay reads from the `vulnerabilityScan` metadata stored alongside each resource in the Oxid state. Findings are summarised as a severity distribution (critical / high / medium / low).

Both overlays persist when you save a query — the `showPrices`, `showVulnerabilities`, and `showIncidents` flags are stored per saved query.

---

## Blast Radius Analysis

The **Blast Radius** analysis shows the impact of changing or removing a specific resource — which other resources depend on it and could be affected.

### Select a resource
Run a query and click on a resource row in the results.

### Click Blast Radius
Click the **Blast Radius** button in the resource detail panel.

### Review the dependency graph
ops0 runs `oxid blast-radius` against the selected resource and returns:
- Direct dependencies (resources this one depends on)
- Dependents (resources that depend on this one)
- Estimated blast radius score (severity: low / medium / high / critical)

Use blast radius analysis before making changes to shared infrastructure (VPCs, shared databases, IAM roles) to understand the scope of impact.

---

## Query Limits

| Limit | Value |
|-------|-------|
| **Max rows returned** | 1,000 rows per query |
| **Query timeout** | 30 seconds |
| **Write operations** | Blocked — SELECT only (DROP, DELETE, ALTER, INSERT, UPDATE all rejected) |

If your question returns more than 1,000 rows, the Query Console shows the first 1,000 and indicates that results were truncated. Refine your question to be more specific, or use the filter controls to narrow the result set.

---

## Requirements

The Query Console requires Oxid to be enabled on at least one project. Oxid stores your IaC state in a PostgreSQL database, which is what the Query Console reads from.

**Oxid Required**

Only projects using Oxid as their state backend appear in the Query Console. See [Oxid](https://docs.ops0.com/docs/iac/oxid) to enable Oxid on a project.

---

## Troubleshooting

No Results Returned

Ensure Oxid is enabled on the project and at least one deployment has completed. The Query Console reads from the Oxid PostgreSQL database, which is populated after a successful apply.

Tables Not Showing in Schema Browser

Tables are created during the first Oxid sync. Run a deployment or trigger an Oxid sync to populate the schema.

Query Timeout (30 seconds)

Queries time out after 30 seconds. Ask a more specific question, reduce the number of selected projects, or add filters to narrow the result set.

---

## Next Steps

- [IaC Projects](https://docs.ops0.com/docs/iac/projects): Create and manage IaC projects with Oxid backend.

- [Variable Graph](https://docs.ops0.com/docs/iac/variable-graph): Visualize cross-project dependencies.

- [Cost Estimation](https://docs.ops0.com/docs/iac/deployments/cost): Understand how costs are estimated per resource.

- [Deployments](https://docs.ops0.com/docs/iac/deployments): Deploy infrastructure and populate state for querying.
