DuckDB
DuckDB is an embedded, in-process analytical database. The @mastra/duckdb package provides an OLAP-backed observability store for local development, suitable for traces, logs, metrics, scores, and feedback without running an external service.
For vector search, see the DuckDB vector store reference, which is a separate API in the same package.
When to use DuckDBWhen to use DuckDB的直接链接
Local development of observability features. DuckDB is embedded and file-based, so it doesn't require a server and starts instantly. It supports the same observability signals as ClickHouse, which makes it useful for testing dashboards and trace exploration before deploying to a production backend.
DuckDB currently implements only the observability domain. Pair it with another storage adapter (such as LibSQL) for memory and workflows in a composite storage setup.
DuckDB is for development and not recommended for production. It runs in-process, persists to a single local file, and doesn't work on platforms with ephemeral filesystems (such as Railway, Fly.io, Render, Heroku, or serverless containers). For production observability, use ClickHouse.
InstallationInstallation的直接链接
- npm
- pnpm
- Yarn
- Bun
npm install @mastra/duckdb@latest
pnpm add @mastra/duckdb@latest
yarn add @mastra/duckdb@latest
bun add @mastra/duckdb@latest
UsageUsage的直接链接
As the observability domain in a composite storeAs the observability domain in a composite store的直接链接
This is the standard local-development setup. LibSQL handles the other domains, and DuckDB handles observability.
import { Mastra } from '@mastra/core'
import { MastraCompositeStore } from '@mastra/core/storage'
import { LibSQLStore } from '@mastra/libsql'
import { DuckDBStore } from '@mastra/duckdb'
import { Observability, MastraStorageExporter } from '@mastra/observability'
export const mastra = new Mastra({
storage: new MastraCompositeStore({
id: 'composite-storage',
default: new LibSQLStore({
id: 'mastra-storage',
url: 'file:./mastra.db',
}),
domains: {
observability: new DuckDBStore().observability,
},
}),
observability: new Observability({
configs: {
default: {
serviceName: 'mastra',
exporters: [new MastraStorageExporter()],
},
},
}),
})
The .observability accessor returns the observability domain store directly. The equivalent generic form uses getStore(), which works for any composite-style storage adapter:
const observability = await new DuckDBStore().getStore('observability')
StandaloneStandalone的直接链接
When you need only observability storage outside the Mastra composite, instantiate DuckDBStore directly and access the observability domain:
import { DuckDBStore } from '@mastra/duckdb'
const duckdb = new DuckDBStore({ path: './traces.duckdb' })
const observability = duckdb.observability
await observability.init()
In-memory databaseIn-memory database的直接链接
Pass :memory: to use an ephemeral DuckDB instance. Data is lost when the process exits, which is appropriate for unit tests and short-lived scripts.
const duckdb = new DuckDBStore({ path: ':memory:' })
ConfigurationConfiguration的直接链接
DuckDBStore optionsduckdbstore-options的直接链接
id?:
path?:
:memory: for an ephemeral in-memory database.memoryLimit?:
threads?:
Lower-level typesLower-level types的直接链接
@mastra/duckdb also exports DuckDBConnection for sharing a single underlying database across multiple Mastra storage instances, and the corresponding DuckDBStorageConfig type. Most applications won't need these directly.
Supported domainsSupported domains的直接链接
DuckDB currently implements one storage domain:
| Domain | Supported |
|---|---|
observability | Yes |
memory | No |
workflows | No |
scores | No |
agents | No |
For a full storage solution, compose DuckDBStore with an adapter that covers the missing domains (most commonly LibSQL for local development).
InitializationInitialization的直接链接
When passed to Mastra through MastraCompositeStore, the observability domain initializes itself on first use. To run initialization explicitly outside of Mastra, call init() on the observability store:
import { DuckDBStore } from '@mastra/duckdb'
const duckdb = new DuckDBStore({ path: './traces.duckdb' })
await duckdb.observability.init()
Observability strategyObservability strategy的直接链接
DuckDB supports the event-sourced strategy used by MastraStorageExporter, which buffers spans in memory and writes completed events in batches. This is appropriate for development-scale traffic. For high-volume production workloads, see MastraStorageExporter storage provider support.
RelatedRelated的直接链接
- Storage overview
- Composite storage
- ClickHouse storage: Production observability backend
- DuckDB vector store: Vector search using the same package
- Observability overview