The Catalog
SynergyDB has no single catalog table. Schema metadata is a set of ordinary key-value records in the storage engine, in two families with different prefixes, owners and scopes:
| Family | Prefix | Scope | Written by | Holds |
|---|---|---|---|---|
| Security catalog |
__catalog:: (two colons) |
Global, outside every database namespace |
CatalogRepository (src/catalog/) |
Roles, memberships, password verifiers, databases, namespaces, RLS table classes and policies, bootstrap marker |
| SQL object catalog |
__catalog__: (two underscores) |
Per database namespace |
QueryEngine and wire handlers |
Tables, columns, constraints, indexes, views, types, functions, triggers, ACLs, wire-specific objects |
(source: src/catalog/repository.rs, key helpers; src/storage/namespaced.rs, CATALOG_PREFIX; src/query/engine.rs, execute_create_table)
Sequence and counter state sits beside the object catalog under __sequence__:, __seqopts__: and __autoincrement__:; see Sequences and auto-increment. Physical key encoding and the database prefix are on Keys and namespaces.
Namespaces
Every database gets a key prefix db:<name>\x1F. A NamespacedStorage view adds the prefix on every read and write, so the same __catalog__:table:users key exists independently in each database. An empty database name or default is normalized to postgres. (source: src/storage/namespaced.rs, NamespacedStorage::new, normalize_db)
CatalogRepository is constructed on the unprefixed StorageEngine, so its __catalog:: records are shared by all databases and all wires. Wire authentication (PostgreSQL, MySQL, gRPC, Gremlin and others) reads roles from it directly. (source: src/main.rs, CatalogRepository::new; src/auth/wire_auth.rs; src/protocol/postgres/auth.rs; src/protocol/mysql/auth.rs)
Global database-level records (__databases__, __db_dropped__, __db_owner__) are described on Keys and namespaces.
Security catalog (CatalogRepository)
Records
Every record is a bincode-encoded struct from src/catalog/system_tables.rs. Name indexes map a name to the 16-byte UUID of the record.
| Key | Value |
|---|---|
__catalog::pg_authid::{oid} |
AuthId (role) |
__catalog::pg_authid_name::{name} |
Role UUID |
__catalog::pg_auth_members::..., pg_auth_members_member::...
|
AuthMember and its by-member index |
__catalog::pg_database::{oid}, pg_database_name::{name}
|
Database and name index |
__catalog::pg_namespace::{oid}, pg_namespace_name::{db}::{name}
|
Namespace and name index |
__catalog::pg_class::{oid}, pg_class_name::{ns}::{name}
|
TableClass and name index |
__catalog::pg_policy::..., pg_policy_table::...
|
Policy and by-table index |
__catalog::pg_attribute..., pg_constraint..., pg_index..., pg_audit_log...
|
Key helpers and structs (Attribute, Constraint, IndexInfo, AuditLogEntry) exist; CatalogRepository has no methods that write them |
__catalog::__bootstrapped__ |
Bootstrap marker |
(source: src/catalog/repository.rs, key helpers; src/catalog/system_tables.rs, structs) Key formats are tested by test_key_formats. (source: src/catalog/system_tables.rs, test_key_formats)
Password material is kept in side records, one per role and format: __catalog__:mysqlpw:{oid}, __catalog__:scramsha256:{oid} and __catalog__:oracle12c:{oid}. They use the object-catalog prefix but, like the rest of this family, are written to the unprefixed global storage. They sit next to an Argon2id hash in the role's rolpassword. set_role_password writes all of them; clear_password_verifiers removes the side records. (source: src/catalog/repository.rs, set_role_password, set_password_verifiers, clear_password_verifiers) Authentication itself is described in the security guide.
Write ordering
create_role, create_database, create_namespace and the other create_* methods check the name index, then write the record and the name index as two separate put calls. A crash between them leaves a record without its name entry. update_role writes both keys in one write_batch; its comment says this is so cluster followers see them together. (source: src/catalog/repository.rs, create_role, update_role) Not verified: no test covers a crash between the two writes.
These writes do not go through the SQL transaction layer, so ROLLBACK does not undo role or policy changes. See Transactional DDL.
Row-level security records
RLS policies are Policy records attached to a TableClass in pg_class. The plan-level RLS injector reads them through get_rls_table_class and get_policies_for_table. (source: src/plan/rls_injector.rs, get_policies_for_table; src/catalog/repository.rs, get_rls_table_class)
Because the security catalog is global, RLS needs a stable database id per SQL database:
| Function | Behaviour |
|---|---|
is_default_rls_database |
postgres, synergydb, the empty name and default share one RLS database |
rls_database_oid |
Deterministic UUID derived with FNV hashing from the database name |
rls_namespace, rls_namespace_or_create
|
The namespace in which a table's RLS class lives |
rls_legacy_namespace |
Older layout, selected by SYNERGYDB_RLS_LEGACY_DATABASE
|
resolve_public_namespace |
Tries the preferred database, then synergydb, then postgres
|
(source: src/catalog/repository.rs, those functions)
Bootstrap
On first start bootstrap_if_needed builds a BootstrapConfig from the environment and, unless __catalog::__bootstrapped__ exists, creates:
- The superuser role from
SYNERGYDB_SUPERUSER(defaultpostgres), with its password set in every stored form. A generated password is written to a file in the data directory before the role exists, and is never printed. - The default database,
SYNERGYDB_DATABASEorsynergydb. - Namespaces
pg_catalogandpublic. - One namespace per entry of
PROTOCOL_SCHEMAS(next section). - Built-in roles
pg_read_all_data,pg_write_all_data,pg_database_owner,pg_signal_backend,pg_monitor. - The bootstrap marker.
(source: src/catalog/bootstrap.rs, BootstrapConfig::from_env, Bootstrap::run, create_default_roles) Tested by test_bootstrap_config_default, test_bootstrap_config_from_env, non_interactive_first_boot_generates_a_password_not_a_known_or_empty_one and configured_password_is_used_as_given_and_no_file_is_written. (source: src/catalog/bootstrap.rs, tests)
Protocol schemas and shadow tables
PROTOCOL_SCHEMAS reserves a namespace and a display oid for each non-SQL data model:
| Schema | Display oid |
|---|---|
mongo (mongo_default) |
13001 |
dynamo |
13002 |
graph |
13003 |
redis |
13004 |
memcached |
13005 |
es |
13006 |
(source: src/catalog/system_tables.rs, PROTOCOL_SCHEMAS) Tested by test_protocol_schema_lookup.
Not wired: bootstrap creates these namespaces empty. TableClass has a protocol_origin field and create_table_class_with_origin exists, but no wire handler creates tables with an origin; the code comments call this "Phase 2+". The shape helpers in src/catalog/compatibility.rs (for example is_mongo_shape) have no callers, as their module comment says. (source: src/catalog/bootstrap.rs, create_protocol_schemas; src/catalog/system_tables.rs, TableClass; src/catalog/compatibility.rs, module doc)
INTERNAL_SHADOW_TABLES lists the SQL tables that wires use as backing storage: _bolt_nodes, _bolt_relationships, _dynamo_items, _dynamo_tables, _es_documents, _flight_datasets, _gremlin_edges, _gremlin_vertices, _memcached_store, _prometheus_samples, _redis_store, _s3_buckets, _s3_objects. is_internal_shadow_table hides them from the PostgreSQL catalog views. (source: src/catalog/system_tables.rs, INTERNAL_SHADOW_TABLES, is_internal_shadow_table; src/protocol/postgres/catalog.rs)
SQL object catalog (__catalog__:)
Keys
Keys have the form __catalog__:<kind>:<name> inside a database namespace. Values are bincode unless noted.
| Kind | Content |
|---|---|
table |
Vec<(name, type, nullable)>, the column list; kept in this basic shape for compatibility |
constraints |
Vec<(name, type, nullable, primary_key, unique)> |
defaults, default_exprs
|
Column defaults |
checks |
CHECK constraints as expression ASTs |
unique_groups, uqindex
|
Multi-column unique constraints and unique indexes |
fks, fk
|
Foreign keys |
generated |
Generated columns |
citext, tablecase, typecase, collation
|
Case and collation handling |
pknum |
Marker for a single-column numeric primary key (see Keys and namespaces) |
index, secidx, ginidx, ftsidx, vecindex
|
Index definitions; see Indexes |
view, matview
|
View definitions |
enum, domain, composite, range
|
User types |
schema, schema_ns
|
Schemas |
function, triggers
|
Routines and triggers |
comment, reltext, keynames, extension, masked, autoinc_alias
|
Other per-object metadata |
relacl, colacl, dbacl, globalacl
|
Grants |
parents, children
|
Table inheritance |
columns |
Column records used by the PostgreSQL catalog views |
(source: src/query/engine.rs, execute_create_table and DDL handlers; src/query/constraints.rs; src/protocol/postgres/catalog.rs)
Several wires add their own kinds to the same family:
| Wire | Kinds or prefixes |
|---|---|
| SQL Server (TDS) |
__catalog__:tds_table, tds_ident, tds_proc, tds_procs, tds_routine, tds_routines, tds_dbobjs, tds_databases
|
| ClickHouse |
ch_tablemeta, ch_engine, ch_mv, ch_mvname, ch_buffer, ch_coltypes
|
| Snowflake |
sfstage, sffileformat, snowflake_warehouses
|
| Cassandra |
cqlks, cqltable
|
| Redis search | __redisft__: |
| InfluxDB |
__influx__:db:, __influx__:rp:
|
| Vector service | __vector__:c: |
| MongoDB | __collection_metadata__ |
| Neo4j Bolt |
_bolt_schema table |
(source: src/protocol/mssql/tsql.rs, meta_key, ident_key, proc_key, routine_key; ClickHouse, Snowflake and Cassandra protocol modules; src/vector/; src/protocol/bolt/mod.rs) The per-model key table on Keys and namespaces gives more detail.
CREATE TABLE
execute_create_table writes the table and constraints records, any unique_groups, checks, fks, generated, citext, tablecase, defaults and deferred default records, and an __autoincrement__:<table>:<column> counter initialized to bincode 0i64 for each SERIAL column. A table created inside a transaction is recorded so that ROLLBACK can drop it. (source: src/query/engine.rs, execute_create_table, created_in_txn)
relation_exists treats a name as taken when a table, view or matview record exists for it. (source: src/query/engine.rs, relation_exists)
Writes and rollback
Catalog records are written straight to storage, outside the transaction's write buffer, so a new object is visible to the rest of its transaction at once. Two mechanisms make them roll back: inside an explicit transaction, DDL statements run with the namespaced storage's undo log recording the prior value of every key they write, and function, domain and type records written through ddl_catalog_write keep their own prior-value list, restored by apply_ddl_undo. Details and limits are on Savepoints and transactional DDL. (source: src/storage/namespaced.rs, record_before_write; src/query/engine.rs, ddl_catalog_write, apply_ddl_undo) Tested by rollback_undoes_index_view_sequence_and_constraint.
Schema versioning and caching
There is no stored schema version number. The storage engine keeps an in-memory catalog_epoch (an AtomicU64 starting at 1 at every open). NamespacedStorage increments it on every write to a key under __catalog__: or __sequence__: in any database. nextval does not bump it, because it uses the counter path. (source: src/storage/mod.rs, catalog_epoch, bump_catalog_epoch; src/storage/namespaced.rs, bumps_catalog_epoch)
Two caches depend on the epoch:
| Cache | Scope | Invalidation |
|---|---|---|
MetaCache in each QueryEngine
|
Decoded column lists, constraints, unique indexes, checks, view presence, absent auto-increment counters | Cleared when the engine sees a newer epoch, and by invalidate_meta_cache after its own DDL |
catalog_memo on the storage engine |
Values derived from one namespace's catalog, keyed by namespace and name | A value is reused only if stored under the current epoch; the epoch is sampled before building |
(source: src/query/engine.rs, MetaCache, meta_cache_locked, invalidate_meta_cache; src/storage/namespaced.rs, catalog_memo)
Because the epoch is global per storage engine, DDL in one database invalidates cached metadata in all of them. Tested by catalog_epoch_makes_other_sessions_ddl_visible_to_cached_metadata, statement_caches_follow_views_and_sequences_from_other_sessions and catalog_relation_cache_follows_analyze_and_sequences. (source: src/query/engine.rs, those tests)
Tests
| Area | Tests |
|---|---|
| System table structs |
test_authid_new_user, test_authid_new_superuser, test_auth_member, test_relation_kind, test_table_class_rls, test_table_class_with_origin, test_protocol_schema_lookup, test_key_formats (src/catalog/system_tables.rs) |
| Repository | One unit test in src/catalog/repository.rs
|
| Bootstrap | Four tests in src/catalog/bootstrap.rs (listed above) |
| Cache invalidation | Engine tests listed above |
Third-party crates
bincode 1.3 for record values, uuid 1.6 for oids, argon2 0.5 for password hashing (through crate::auth::password::PasswordHasher), dialoguer 0.11 for the interactive bootstrap prompt. (source: src/catalog/repository.rs, set_role_password; src/catalog/bootstrap.rs, imports; Cargo.toml)