---
title: "SurrealDB 4: the database and memory for every agent"
description: "SurrealDB 4 is a database for every agent: it speaks Postgres and MySQL, runs serverless on SurrealDB Earth, and keeps every 3.x record readable."
url: https://surrealdb.com/4
---

# The database and memory for every agent

SURREALDB 4

Starts on its first query. Speaks Postgres and MySQL.
Scales to zero instantly. Remembers in one query.

[Install SurrealDB 4](https://surrealdb.com/surrealdb/install) [Talk to our team](https://surrealdb.com/contact/sales)

**Compatibility.** PostgreSQL and MySQL clients connect over their own wire protocols, and MongoDB driver code runs through mql.js.

**Stability.** More than 240 fixes that no 3.x release contains, including more than 90 community bug reports that 3.x did not fix.

**Performance.** A rebuilt query core, with vector indexes built 7.4x faster and filtered vector search down from 27 ms to 1.1 ms.

ONE RELEASE, THREE FOUNDATIONS

## SurrealDB 4, SurrealDB Earth and SurrealDS. A database that speaks Postgres and MySQL, starts on its first query on Earth, confirms each write in two zones by default, and scales on demand.

[Install SurrealDB 4](https://surrealdb.com/surrealdb/install)

### [SurrealDB 4](https://surrealdb.com/surrealdb/benchmarks)

Indexed queries are projected at 22x faster than in 3.x. Full-table scans are 2.3x faster, and creates, reads, updates and deletes 42% faster, as measured with crud-bench on the same hardware.

22x faster

### [SurrealDB Earth](https://surrealdb.com/4?trk=public_profile__reactions-text#scale)

Serverless SurrealDB on Cloudflare, with thousands of isolated instances. Earth handles 10+ billion peak rows per second, fully transactional.

10+ billion

### [SurrealDS](https://surrealdb.com/4?trk=public_profile__reactions-text#scale)

Distributed storage on object storage, in SurrealDB Cloud multi-node clusters and Enterprise Edition. With the default two-zone policy, writes are acknowledged only after being stored on disks in both zones.

Two zones

RELIABILITY

## Compute is replaceable. Data stays durable. SurrealDS copies each write across failure domains before confirming it, and a new node recovers from the surviving copy. SurrealDB 4 adds 240+ fixes over 3.x.

[Read the release notes](https://surrealdb.com/releases)

240+ fixes

More than 240 fixes to the database are in SurrealDB 4 and in no 3.x release.

90+ bug reports

More than 90 community bug reports on GitHub are fixed in SurrealDB 4 and were not fixed in 3.x.

4,500+ test files

More than 4,500 SurrealQL test files run on every change.

Two zones

With the default two-zone policy, every SurrealDS write is acknowledged only after it is stored on disks in both zones, and a replacement node recovers from the surviving copy and object storage.

PERFORMANCE

## Faster at every size. A rebuilt query core in SurrealDB 4, with faster storage engines, indexes and graph traversals.

[See the benchmarks](https://surrealdb.com/surrealdb/benchmarks)

7.4x

A 1-million-vector, 768-dimension HNSW index built in 986 s instead of 7,290 s, in parallel batches on a 64-core server.

27 ms to 1.1 ms

A 1% filtered vector search, with SIMD scoring and an exact filtered tier read from the index itself.

24.5 to 9.4 min

Indexing 200,000 records of 4.2 KB with one full-text index, with index changes batched per transaction.

COMPATIBILITY

## Speaks Postgres and MySQL. PostgreSQL and MySQL clients, and code written for the MongoDB driver, reach the same records as SurrealQL, through one query planner.

[Read the release notes](https://surrealdb.com/releases) [Connect from JavaScript](https://surrealdb.com/connect/javascript)

PostgreSQL

PostgreSQL clients connect over the PostgreSQL wire protocol and run a defined subset of PostgreSQL SQL: joins, grouping, aggregates, inserts with ON CONFLICT, schema changes and transactions.

Copy

```
SELECT p.name,    pr.name AS productFROM person pJOIN bought b ON b.in = p.idJOIN product pr ON pr.id = b.outWHERE p.age > 30;
```

MySQL

MySQL clients connect over the MySQL wire protocol, and a defined subset of MySQL SQL runs through the same query planner as SurrealQL.

Copy

```
SELECT pr.name,    COUNT(*) AS buyersFROM bought bJOIN product pr ON pr.id = b.outGROUP BY pr.nameORDER BY buyers DESC;
```

MongoDB

mql.js 1.0 brings the MongoDB Node.js driver's API to SurrealDB, aggregation pipelines and Mongoose models included: change the import and the connection string.

Copy

```
import { MongoClient }    from "mql.js";const client =    new MongoClient(SURREALDB_URL);const people = client    .db("shop")    .collection("person");await people    .find({ age: { $gt: 30 } })    .toArray();
```

SCALE

## From zero to massive. Serverless databases that scale to zero when idle, thousands of isolated ones across Cloudflare, and clusters over very large datasets, all on SurrealDB.

[Explore SurrealDB Earth](https://surrealdb.com/earth)

Scales to zero when idle

A SurrealDB Earth database is serverless on Cloudflare's network: it starts with the first query, cold starts in ~300ms and scales to zero instantly when idle.

Thousands of instances

Earth runs thousands of isolated, persistent databases, one per user, customer or agent, with their capacity added together.

One query, many Workers

Earth splits a query across Workers and merges the answer, with every leg reading the same point in time.

Compute apart from storage

SurrealDS query nodes keep caches while data pages live in object storage, so a node joins without copying the dataset and no one shards by hand.

WHAT IT UNLOCKS

## Data infrastructure for AI agents at any scale. One agent, one database. Thousands of agents, thousands of databases. Large platforms, shared clusters. The data model stays the same at every step.

[Explore Agent Memory](https://surrealdb.com/agent-memory)

One agent

Gets its own SurrealDB Earth database, which keeps its state between runs and uses almost no compute while the agent is idle.

Thousands of agents

Get thousands of isolated databases across Cloudflare's network, each scaling on its own, so a busy agent takes more compute than a quiet one.

Large platforms

Run groups of agents on shared SurrealDB clusters that scale out, reading and writing the same memory in transactions.

START ON SURREALDB 4

## Run it today, wherever you build. Embedded in an application, on a laptop, in the browser, as a server or in SurrealDB Cloud, and as an upgrade from 3.x with every 3.x record still readable.

[Read the docs](https://surrealdb.com/docs/what-is-surrealdb)

[Install SurrealDB 4 Run SurrealDB 4 embedded in your application, on your laptop, in the browser or on your own servers.](https://surrealdb.com/surrealdb/install) [Start in the Cloud Deploy a managed SurrealDB 4 instance in SurrealDB Cloud, in the provider and region you choose.](https://studio.surrealdb.com/current/instances/deploy) [Start on Earth Run SurrealDB 4 serverless on Cloudflare's network, free to start: each database starts with the first query, cold starts in ~300ms and scales to zero instantly when idle.](https://surrealdb.com/earth) [Upgrade from 3.x Every 3.x record stays readable. The release notes list the few changes to check first.](https://surrealdb.com/releases)

## Your questions, answered

Can my Postgres or MySQL clients connect?

Yes. SurrealDB 4 speaks the PostgreSQL and MySQL wire protocols and accepts a defined subset of standard SQL, run by the same planner as SurrealQL. Joins, grouping, aggregates, ON CONFLICT, schema changes, transactions, non-recursive WITH queries (CTEs) and COPY in text and CSV all work. The information_schema and pg_catalog relations list the tables of the database, and recursive CTEs and window functions are refused, as is anything else outside the supported set, with a named error before a statement changes any data. The [MySQL protocol reference](https://surrealdb.com/docs/reference/rest-api/mysql-protocol) in the docs describes how MySQL clients connect.

Can MongoDB applications run on SurrealDB?

How many bugs does SurrealDB 4 fix?

What does the 10+ billion figure measure?

Will my 3.x data stay readable?

THE PLATFORM

## Everything an application and its agents know. Five surfaces, one engine.

Database

Document, graph, vector, time-series and relational in one engine.

![Five data models as dotted tiles: documents, graph, vector, time-series and relational](https://surrealdb.com/assets/static/platform-database.DUdumYDz.avif)

Read more

[Database](https://surrealdb.com/surrealdb)

Agent Memory

What an agent learns, with its source and its time, in the same engine.

![A timeline of remembered facts, each with its source](https://surrealdb.com/assets/static/platform-agent-memory.Cvv8D5Wl.avif)

Read more

[Agent Memory](https://surrealdb.com/agent-memory)

Cloud

Dedicated clusters by region, or serverless on SurrealDB Earth.

![Clusters in three regions on a world map, each running or scaling](https://surrealdb.com/assets/static/platform-cloud.--QZnaVi.avif)

Read more

[Cloud](https://surrealdb.com/cloud)

Studio

Query, explore and design the schema from the browser.

![A SurrealQL query in Studio and the schema graph under it](https://surrealdb.com/assets/static/platform-studio.7ykBFNLq.avif)

Read more

[Studio](https://surrealdb.com/studio)

MCP

Every model that speaks MCP reaches the database and the memory directly.

![Three models connected through MCP to the database and Agent Memory](https://surrealdb.com/assets/static/platform-mcp.D_oH0_wm.avif)

Read more

[MCP](https://surrealdb.com/mcp)

IN PRODUCTION

## Trusted at scale. Samsung, Nvidia, Verizon, Tencent, and Walmart run on SurrealDB.

14,000+

Developers building on SurrealDB Cloud

4M+

Developers building on SurrealDB worldwide

FROM THE TEAMS

> SurrealDB gives us a foundation where we can unify semantic search, knowledge graphs, and AI-driven decision making without stitching together multiple systems. Collapsing responsibility into SurrealDB has become our default engineering posture.

*Justin Foley*

VP of Engineering, Later

GET STARTED

## Build on SurrealDB 4. From zero to massive: scale, performance and reliability on one database, and the foundation for AI agents.

[Install SurrealDB 4](https://surrealdb.com/surrealdb/install) [Talk to our team](https://surrealdb.com/contact/sales)

```json
{"@context":"https://schema.org","@type":"Organization","@id":"https://surrealdb.com/#organization","name":"SurrealDB","url":"https://surrealdb.com","logo":"https://surrealdb.com/assets/static/logo.BG7_TG2b.svg","description":"SurrealDB is a database for every agent. It starts on its first query, scales to zero when idle, speaks Postgres and MySQL, and remembers in one query.","foundingDate":"2022","legalName":"SurrealDB Ltd","identifier":{"@type":"PropertyValue","propertyID":"GB-COH","value":"13615201"},"address":{"@type":"PostalAddress","streetAddress":"3rd Floor, 1 Ashley Road","addressLocality":"Altrincham","addressRegion":"Cheshire","postalCode":"WA14 2DT","addressCountry":"GB"},"contactPoint":[{"@type":"ContactPoint","contactType":"customer support","email":"support@surrealdb.com","url":"https://surrealdb.com/contact","availableLanguage":"English"},{"@type":"ContactPoint","contactType":"sales","email":"info@surrealdb.com","url":"https://surrealdb.com/contact","availableLanguage":"English"},{"@type":"ContactPoint","contactType":"security","email":"security@surrealdb.com","url":"https://surrealdb.com/.well-known/security.txt","availableLanguage":"English"},{"@type":"ContactPoint","contactType":"legal","email":"legal@surrealdb.com","url":"https://surrealdb.com/legal","availableLanguage":"English"}],"hasCertification":[{"@type":"Certification","name":"SOC 2 Type 2"},{"@type":"Certification","name":"GDPR"},{"@type":"Certification","name":"Cyber Essentials Plus"},{"@type":"Certification","name":"ISO 27001"}],"owns":[{"@type":"SoftwareApplication","name":"SurrealDB","url":"https://surrealdb.com/surrealdb"},{"@type":"SoftwareApplication","name":"Agent Memory","url":"https://surrealdb.com/agent-memory"}],"knowsAbout":["multi-model databases","document databases","graph databases","vector search","time-series databases","SurrealQL","Agent Memory","real-time databases","embedded databases","AI agent database","graph ontology","distributed database","knowledge graphs","distributed transaction protocols","highly-scalable databases"],"sameAs":["https://www.wikidata.org/wiki/Q124316308","https://github.com/surrealdb/surrealdb","https://twitter.com/surrealdb","https://www.youtube.com/@surrealdb","https://www.linkedin.com/company/surrealdb","https://discord.gg/surrealdb","https://www.reddit.com/r/surrealdb","https://www.instagram.com/surrealdb","https://medium.com/surrealdb","https://dev.to/surrealdb"]}
```

```json
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://surrealdb.com"},{"@type":"ListItem","position":2,"name":"4","item":"https://surrealdb.com/4"}]}
```

```json
{"@context":"https://schema.org","@type":"FAQPage","mainEntity":[{"@type":"Question","name":"Can my Postgres or MySQL clients connect?","acceptedAnswer":{"@type":"Answer","text":"Yes. SurrealDB 4 speaks the PostgreSQL and MySQL wire protocols and accepts a defined subset of standard SQL, run by the same planner as SurrealQL. Joins, grouping, aggregates, ON CONFLICT, schema changes, transactions, non-recursive WITH queries (CTEs) and COPY in text and CSV all work. The information_schema and pg_catalog relations list the tables of the database, and recursive CTEs and window functions are refused, as is anything else outside the supported set, with a named error before a statement changes any data. The MySQL protocol reference in the docs describes how MySQL clients connect."}},{"@type":"Question","name":"Can MongoDB applications run on SurrealDB?","acceptedAnswer":{"@type":"Answer","text":"JavaScript and TypeScript applications that use the MongoDB Node.js driver or Mongoose can, through mql.js 1.0, within its documented divergences. mql.js is a client library, so mongosh, Compass and drivers in other languages cannot connect through it."}},{"@type":"Question","name":"How many bugs does SurrealDB 4 fix?","acceptedAnswer":{"@type":"Answer","text":"SurrealDB 4 has more than 240 fixes to the database that no 3.x release contains, and it fixes more than 90 community bug reports on GitHub that 3.x did not fix."}},{"@type":"Question","name":"What does the 10+ billion figure measure?","acceptedAnswer":{"@type":"Answer","text":"Peak rows per second on SurrealDB Earth, on Cloudflare's network. Earth handles 10+ billion peak rows per second, fully transactional."}},{"@type":"Question","name":"Will my 3.x data stay readable?","acceptedAnswer":{"@type":"Answer","text":"Yes. Every 3.x record stays readable in SurrealDB 4. A few changes need attention when upgrading, such as rebuilding vector indexes, and the release notes list each one."}}]}
```
