Skip to content
SPL // Splunk

Using the dbxquery Command

KGI Avatar
 

Written by: Carlos Diez | Last Updated:

 
June 12, 2025
 
Search Command Of The Week: dbxquery
 
 

Originally Published:

 
June 12, 2025

The Splunk Search Processing Language (SPL) is a powerful tool for querying, transforming, and visualizing machine data. It serves as the backbone of every search in Splunk, whether simple or complex. However, data isn’t always inside Splunk indexes. In many environments, critical data resides in external databases, such as Microsoft SQL Server, Oracle, or MySQL. 

This is where the dbxquery command becomes essential. It allows users to pull structured data from external relational databases directly into Splunk search pipelines. Practical use cases include joining threat intel stored in external systems, correlating ticketing records with endpoint logs, or validating data integrity between systems. 

Limitation in the Splunk Cloud Enviornment

While dbxquery is highly effective in on-premises environments, users migrating to Splunk Cloud should be aware that there are architectural and security restrictions that bring forth additional considerations when using DB Connect to access external database information.  

For a deeper dive into this limitation and alternative strategies, check out our earlier post: 

Benefits of Using dbxquery

The dbxquery command brings unique value to day-to-day Splunk operations. Here are three key benefits: 

  • Real-Time Access to External Data: Retrieve the latest data without having to schedule ingestion jobs or replicate databases into Splunk. 
  • On-Demand Data Correlation: Enhance your existing Splunk searches by joining them with business data such as inventory, HR systems, or CMDB entries. 
  • Reduced Storage Overhead: Query external databases directly without adding ingestion volume or consuming additional license usage. 

Prerequsities for Using dbxquery

Before you can run the dbxquery command, there are several setup steps required. This is a high-level overview. For detailed implementation, users should contact their Splunk Administrator to confirm access and configuration. 

  • Install the Splunk DB Connect app: DB Connect must be installed on a supported search head or heavy forwarder. 
  • Define a database connection: Set up a database connection object using the app UI. This includes database type, hostname, port, and JDBC configuration. 
  • Upload JDBC drivers: The correct JDBC driver must be uploaded through DB Connect for each type of database you intend to query. 
  • Create database identities: Define credentials used for authentication to the database and assign them to the connection. 
  • Assign permissions: Make sure your Splunk role has access to use DB Connect and the dbxquery command. 

Basic Syntax

Using dbxquery starts with specifying the connection and a valid SQL query. The connection parameter refers to a database connection defined and configured within the Splunk DB Connect app. This connection includes the database type, host, port, credentials, and any additional JDBC settings required to establish communication with the external system. Here’s the core structure: 

				
					| dbxquery connection="your_connection_name" query="SELECT * FROM your_table LIMIT 10" 
				
			

You can include additional options like timeout, maxrows, and macros in the query if necessary. Always enclose your SQL query in double quotes. 

Practical Use Cases

Example #1: Asset Lookup from CMDB

Use Case: A security analyst wants to retrieve asset owner data from a CMDB stored in a MySQL database and correlate it with firewall traffic logs stored in the Network_Traffic data model.

				
					| dbxquery connection="cmdb_mysql" query="SELECT hostname, owner FROM assets" 
| lookup local=true host OUTPUT owner 
| tstats count from datamodel=Network_Traffic.All_Traffic where All_Traffic.dest!=null by All_Traffic.dest 
				
			

Step-by-Step Explanation: 

  • The first line queries the assets table in the CMDB to retrieve hostname and owner fields using a configured DB Connect connection. 
  • The second line uses a local lookup to match the host field from Splunk logs with the hostname from the external query, appending the corresponding owner value. 
  • The third line runs a tstats search on the Network_Traffic data model to count all network events grouped by destination IP, where a destination exists. 

Outcome: You get a dataset of network destinations along with their corresponding asset owners, helping attribute network activity to responsible parties. 

Example #2: Incident Enrichment with Ticketing Data

Use Case: You want to enrich alerts in Splunk with ticket information from an external incident tracking system (e.g., ServiceNow). 

				
					| dbxquery connection="ticketing_db" query="SELECT ticket_id, system_name, status FROM incidents WHERE status='Open'" 
| rename system_name as host 
| join host 
    [ search index=security sourcetype=alert_summary | stats count by host ] 
				
			

Step-by-Step Explanation: 

  • The dbxquery command pulls open incident tickets from the external system, returning the ticket ID, system name, and status. 
  • The rename command standardizes the field name (system_name to host) for easier correlation. 
  • The join operation connects this external data to internal alert records based on the host field, enriching the results with ticket information. 

Outcome: This search identifies alerts that already have associated open incident tickets, helping prioritize response and reduce duplicate investigations. 

Example #3: Querying User Access Logs from External DB

Use Case: A compliance team needs to validate that users listed in external login records also appear in internal Splunk authentication logs. 

				
					| dbxquery connection="oracle_access" query="SELECT username, login_time FROM user_access WHERE login_time > CURRENT_DATE - 1" 
| rename username as user 
| search index=authentication sourcetype=windows:security user=* 
| stats count by user, login_time
				
			

Step-by-Step Explanation: 

  • The dbxquery command retrieves login activity from the last 24 hours from the user_access table in Oracle. 
  • rename is used to align the username field with the user field used in Splunk’s internal logs. 
  • The search command filters for authentication-related events involving users. 
  • stats aggregates results by user and login time to show how frequently users are authenticated. 

Outcome: The search enables audit teams to confirm that users logging into critical systems are also visible in internal authentication logs, ensuring monitoring coverage and compliance.** The resulting dataset enables the compliance team to verify that externally recorded user access matches internal system authentication events. 

Conclusion: Why dbxquery Matters

The dbxquery command offers a flexible, efficient, and lightweight way to access external databases from within Splunk. It is particularly powerful for enriching data and building dashboards without increasing ingestion volume. While not ideal for every use case, it excels in on-demand, correlation-focused workflows. 

Summary Points:

  • dbxquery bridges Splunk with external relational databases via SQL. 
  • It enables real-time data correlation without increasing your license usage. 
  • Ideal for enriching searches with asset, user, or incident data stored outside Splunk.

To access more Splunk searches, check out Atlas Search Library, which is part of the Atlas Platform. Specifically, Atlas Search Library offers a curated list of optimized searches. These searches empower Splunk users without requiring SPL knowledge. Furthermore, you can create, customize, and maintain your own search library. By doing so, you ensure your users get the most from using Splunk.

Atlas Search Library
Helpful? Don't forget to share this post!
LinkedIn
Reddit
Email
Facebook