Storage
Mastra sets the project's default storage from a storage.ts file directly under src/mastra/. The file default-exports a store, which replaces the built-in in-memory store used for memory, workflows, observability, and other storage domains.
Use this page for the file-based convention. For backend choice, storage domains, retention, and provider details, see storage overview.
QuickstartQuickstart的直接链接
Use LibSQLStore for a local file-backed store:
import { LibSQLStore } from '@mastra/libsql'
export default new LibSQLStore({
id: 'mastra-storage',
url: 'file:./mastra.db',
})
Mastra registers the store before file-based agents and workflows, so storage-dependent primitives bind to this store instead of the default in-memory store.
Production backendsProduction backends的直接链接
storage.ts can export any Mastra storage adapter, such as LibSQL, PostgreSQL, or MongoDB. For setup patterns, provider support, and schema details, see storage overview, observability signal support, and the storage reference.
Precedence with codePrecedence with code的直接链接
Code-registered storage wins over storage.ts. Use storage.ts when one project-wide store is enough. Use code registration when setup depends on runtime wiring in src/mastra/index.ts.