---
title: Transactions
sort: 140
section-id: query-language
keywords: transactions, ACID, isolation levels, MVCC, BEGIN, COMMIT, ROLLBACK
description: ACID transactions in NeuralDB — isolation levels, MVCC, savepoints, and advisory locks
language: en
---

# Transactions

NeuralDB provides full ACID transactions with MVCC. Unlike most vector databases, NeuralDB guarantees atomicity across both relational and vector data.

## Basic Transaction Syntax

```sql
BEGIN;
INSERT INTO documents (content, embedding) VALUES ($1, $2);
UPDATE document_stats SET total_count = total_count + 1;
COMMIT;
```

## Isolation Levels

```sql
BEGIN;
SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
-- each statement sees only rows committed before it
COMMIT;

BEGIN ISOLATION LEVEL REPEATABLE READ;
-- reads are stable throughout the transaction
COMMIT;

BEGIN ISOLATION LEVEL SERIALIZABLE;
-- may raise: ERROR: could not serialize access
COMMIT;
```

## Savepoints

```sql
BEGIN;
INSERT INTO documents (content, embedding) VALUES ($1, $2);
SAVEPOINT after_insert;
UPDATE document_stats SET count = count + 1 WHERE id = $3;
ROLLBACK TO SAVEPOINT after_insert;
UPDATE document_stats SET count = count + 1 WHERE id = $4;
COMMIT;
```

## Vector Transactions

```sql
BEGIN;
INSERT INTO documents (id, content, embedding) VALUES ($1, $2, $3);
-- If ROLLBACK, neither row nor index entry exists
ROLLBACK;
```

## Advisory Locks

```sql
SELECT pg_advisory_lock(42);
SELECT pg_try_advisory_lock(42);  -- returns boolean
SELECT pg_advisory_unlock(42);
SELECT pg_advisory_xact_lock(42); -- auto-released at commit/rollback
```
