# Postgres in Sovaria
Source: https://sovaria.in/docs/postgres-basics

The Postgres version and extensions your project has, schemas, data types, keys and constraints, views, functions and triggers, what the plan limits, and which Postgres features behave differently through the API.

Every project has its own **PostgreSQL** database: **18** for new projects (asynchronous I/O, built-in `uuidv7()`), **16** for projects made before (Sovaria upgrades them one at a time; nothing changes for you until then). Everything you know about Postgres applies: SQL, schemas, constraints, views, functions, triggers, indexes and transactions. Sovaria adds the API, access policies and auth helpers around it.

## Extensions

About 30 extensions are available: `vector` for embeddings, `postgis` for geography, `pg_trgm` for fuzzy search, `pgcrypto`, `citext`, `pg_graphql`, `pg_stat_statements` and more. Turn them on under **Schema › Extensions**. [Extensions](https://sovaria.in/docs/database-extensions) lists each one, what it is for and which plan includes it; network and file extensions (`dblink`, `postgres_fdw`) aren't offered.

## Schemas, tables and the rest

- Your tables live in `public` by default; create more schemas to group them. The `auth` schema holds the auth helpers ([Auth helpers in SQL](https://sovaria.in/docs/auth-helpers)); don't create tables there.
- Use the types you need: `uuid` and `bigint generated always as identity` for keys, `timestamptz` for times, `jsonb` for flexible data, `numeric` for money, arrays, enums.
- Primary keys, foreign keys (with `on delete cascade` or `set null`), unique and check constraints and defaults all work, and the Table Editor sets most of them for you.
- Views (use `with (security_invoker = true)` so they respect row-level security) and materialized views are supported.
- SQL and PL/pgSQL functions, triggers and indexes: create and manage them under **Schema** — see [Database functions](https://sovaria.in/docs/database-functions), [Triggers](https://sovaria.in/docs/database-triggers) and [Indexes](https://sovaria.in/docs/database-indexes).

- [Database functions](https://sovaria.in/docs/database-functions): Logic that runs next to your data, callable over REST.
- [Triggers](https://sovaria.in/docs/database-triggers): Run a function on every insert, update or delete.
- [Indexes](https://sovaria.in/docs/database-indexes): Make lookups, joins and sorting fast.
- [Extensions](https://sovaria.in/docs/database-extensions): Vectors, geography, fuzzy search and more.

|  | Free | Pro | Ultra | Team | Enterprise |
|---|---|---|---|---|---|
| Tables | 100 | 2,000 | 10,000 | 50,000 | 200,000 |
| Views | 25 | 500 | 2,000 | 10,000 | 50,000 |
| Stored procedures | 20 | 500 | 2,000 | 10,000 | 50,000 |
| Triggers | 20 | 500 | 2,000 | 10,000 | 50,000 |
| Indexes | 100 | 10,000 | 30,000 | 100,000 | 500,000 |
| Schemas per database | 5 | 50 | 200 | 1,000 | 5,000 |
| Database disk | 500 MB | 8 GB | 25 GB | 100 GB | 1 TB |

## Schemas Sovaria manages

A few schemas in your project's database belong to Sovaria. They are part of **your** database — no other project can see them, and they hold nothing from other projects — but Sovaria creates and changes them, so don't create objects there or rely on what is inside.

| Schema | Holds | In the console |
|---|---|---|
| `auth` | The auth helpers you use in policies: `auth.uid()`, `auth.role()`, `auth.jwt()` ([Auth helpers in SQL](https://sovaria.in/docs/auth-helpers)). | Listed, read-only in the Table Editor. |
| `sovaria_internal` | Your plan's object limits (tables, functions, triggers, indexes…) and the check that enforces them on every schema change, from any client. | Hidden. Only Sovaria can change it. |
| `sovaria_trash` | Tables and column values deleted from the Table Editor, kept so [Version history: see, undo and restore changes](https://sovaria.in/docs/version-history) can bring them back. Sovaria may delete trash older than its undo window (30 days); after that the drop can't be undone. | Hidden. Undo a change to restore what is there. |

Sovaria also keeps a few helpers in your own schema for documents and [Table history (time travel)](https://sovaria.in/docs/table-history) (`sov_documents`, `sov_history`, `sov_as_of()`…). They don't count against your limits, and **Schema › Functions** hides them unless you choose to show them.

## Through the API

| Topic | How it works |
|---|---|
| One statement per request | `/api/v1/sql/query` runs one `SELECT`, `INSERT`, `UPDATE`, `DELETE` or `EXPLAIN`; schema changes belong in the SQL editor or migrations. |
| Values | Always as parameters (`$1`, `$2`…), never pasted into SQL. |
| Rows per query | Capped by plan (below); page through larger results. |
| Statement time | A default timeout per plan; a client may ask for more with `X-Statement-Timeout-Ms`, up to the plan's maximum. |
| Transactions across requests | `POST /api/v1/data/rel/transaction/begin`, then pass the `txid` and `commit` or `rollback` ([HTTP API: tables, migrations and history](https://sovaria.in/docs/rest-data)). |
| Session state | `set_config`, `SET ROLE` and changing the request's identity are refused. |

A query returns at most your plan's `sql.max_rows` rows, and the answer carries `"truncated": true` when there were more (the SQL editor says so). For a single `SELECT`, `WITH`, `VALUES` or `TABLE` statement whose parameters, if any, are text or null, your database sends at most one row more than that (to tell whether there were more); the statement still runs to the end there, so functions it calls behave as they would without the limit. Page with `LIMIT`/`OFFSET` or a keyset `WHERE`. Send `"read_only": true` with a query to have it run in a read-only transaction.

|  | Free | Pro | Ultra | Team | Enterprise |
|---|---|---|---|---|---|
| Rows one SQL query may return | 1,000 | 5,000 | 10,000 | 25,000 | 50,000 |
| Default SQL statement timeout (ms) | 3 s | 8 s | 15 s | 30 s | 60 s |
| Longest SQL statement timeout a client may request (ms) | 8 s | 30 s | 60 s | 120 s | 300 s |
| Concurrent database connections | 20 | 200 | 500 | 2,000 | 10,000 |

## Database errors

| Postgres error | Means |
|---|---|
| `23505 unique_violation` | A row with that value already exists. |
| `23503 foreign_key_violation` | The referenced row doesn't exist, or other rows still point to it. |
| `23502 not_null_violation` | A required column was empty. |
| `23514 check_violation` | A check constraint refused the value. |
| `42501 insufficient_privilege` / new row violates row-level security | A row-level security policy refused the row ([Row-level security and access](https://sovaria.in/docs/row-level-security)). |
| `57014 query_canceled` | The statement timeout stopped it — add an index or raise the timeout. |
| `42P01 undefined_table` (404 from `/rest/v1`) | Wrong table name or schema (names are case-sensitive when quoted), or the table was made in another environment: staging and branches have their own database, so create it in production too. |
