Azure database services
This service provides local Azure-style database resources for Cosmos DB, SQL Database, MySQL, MariaDB, PostgreSQL, and Azure Cache for Redis. Cosmos NoSQL runs as an embedded document service. The relational engines and optional Redis data plane use managed sidecar processes. Each service exposes resource state and connection details through a control plane. Service choices are described in build and configuration, while resource persistence is covered in storage backends.
Service model
The database services separate resource management from data access. A control-plane request creates and tracks a logical Azure resource. The request then either serves data in the emulator or exposes an endpoint for a local engine.
| Service | Data access model | Resource model |
|---|---|---|
| Cosmos DB NoSQL | Embedded document and query service | Databases, containers, and items remain in the emulator |
| Cosmos DB API variants | Embedded Table engine or native sidecar service | The emulator selects the API engine and reports its state |
| SQL Database | SQL Server sidecar, metadata-only mode, or unavailable external mode | Logical servers and databases are managed resources |
| MySQL | MySQL sidecar or mocked management plane | Flexible servers and databases are managed resources |
| MariaDB | MariaDB sidecar or mocked management plane | Servers and databases are managed resources |
| PostgreSQL | PostgreSQL sidecar or mocked management plane | Flexible servers and databases are managed resources |
| Cache for Redis | Redis sidecar or metadata-only mock | Caches and access keys are managed resources |
The relational services do not create application schemas or run migrations. Applications remain responsible for DDL and schema setup after they receive a usable connection. The convenience connect responses package host, port, credentials, and common client connection forms for local development.
Cosmos DB
Cosmos DB NoSQL is an embedded document store that aims to preserve the resource and request behavior expected by Cosmos SDKs. It stores items within databases and containers and applies container partition-key rules to item access and queries. The Cosmos compatibility page covers the SDK-facing details of the supported API variants.
Item and partition behavior
An item has application fields and Cosmos-managed fields. The service assigns system values such as id, _rid, _etag, _ts, and _self. Clients can update application content but cannot use patch operations to change these protected roots or move an item to another partition.
Patch requests can change user fields with common add, set, replace, remove, increment, and move operations. The service checks the full operation set before it stores the result, so a rejected protected-field or partition-key change leaves the item unchanged.
Container TTL settings control when items expire. Expiration is lazy. An expired item is removed when a later read or scan encounters it rather than through a separate background deletion process.
References: src/…/CosmosHandler.java• L630-669 src/…/CosmosHandler.java• L713-765
Query behavior
The service evaluates the Cosmos SQL query language over embedded items. It supports filtering, projection, ordering, grouping, aggregates, distinct results, scalar SELECT VALUE results, and common array, string, math, and conditional expressions.
Queries can be limited to a logical partition by the request partition-key header. Continuation tokens bind a page to its query, resource, partition, ordering values, and document identity. This prevents a token from one query or partition from returning an unrelated page.
The emulator checks indexing policy compatibility before it evaluates a query. A single-property order uses the default range index. A multi-property order needs a matching composite index. SDKs can request a query plan before execution. The plan describes the emulator's single partition and preserves scalar SELECT VALUE results.
References: src/…/CosmosHandler.java• L183-210 src/…/CosmosHandler.java• L537-604 src/…/CosmosQueryEngine.java• L1-25 src/…/CosmosQueryPartition.java• L1-20
Transactional batches
Cosmos transactional batches group item operations within one partition. The service stages creates, reads, replacements, patches, upserts, and deletes. It commits the group only after every operation succeeds. A failed operation therefore leaves the stored partition unchanged.
This diagram shows how a Cosmos request moves from resource scope to a committed item result.
flowchart LR
A[Cosmos request] --> B[Resource and partition scope]
B --> C{Request type}
C -->|Item| D[Validate item or patch]
C -->|Query| E[Filter and shape items]
C -->|Batch| F[Stage same-partition operations]
D --> G[Persist item]
E --> H[Page results]
F --> I{All operations succeed?}
I -->|Yes| J[Commit batch]
I -->|No| K[Discard staged changes]
References: src/…/CosmosHandler.java• L183-210 src/…/CosmosHandler.java• L713-766
Server-side scripts
Cosmos containers expose stored procedures, triggers, and user-defined functions as stored resources. The emulator validates and serves these resources through feeds and queries, but it does not execute their JavaScript. An execution request for an existing stored procedure returns an unsupported-operation response.
References: src/…/CosmosHandler.java• L907-1072 src/…/CosmosScriptKind.java• L3-16
Cosmos API variants
Cosmos exposes more than its default NoSQL API. The emulator selects Mongo, Cassandra, Gremlin, Table, or PostgreSQL behavior from the requested API. Each API is represented by a provider that reports its compatibility level, connection form, and whether its data path is embedded or sidecar-backed.
Embedded engines handle data requests inside floci-az and return a local connection form for compatible clients. Sidecar-backed engines return connection details after their native service starts, so the client sends data traffic to that engine rather than to the control plane. The Table API is an embedded in-memory engine, so its tables and entities are cleared when floci-az restarts. Mocked Cosmos mode starts no engine.
Each non-mocked Cosmos engine can use on-demand startup, eager startup at emulator launch, or disabled startup. On-demand startup starts an engine when a client first needs its connection details, while disabled startup keeps that API unavailable.
The PostgreSQL Cosmos API is kept for legacy compatibility with PostgreSQL and Citus clients. Azure is retiring Cosmos DB for PostgreSQL, so this mode does not represent new Azure features such as its former high-availability, scaling, or multi-region behavior.
References: src/…/CosmosEngineHandler.java• L19-35 src/…/CosmosEngineHandler.java• L107-153 src/…/CosmosLifecycleManager.java• L21-30 src/…/CosmosLifecycleManager.java• L55-175 src/…/PostgreSqlCosmosEngine.java• L21-56
Managed relational databases
SQL Database, MySQL, MariaDB, and PostgreSQL present an Azure-like management surface over a logical server. In managed data-plane mode, each server maps to one local database sidecar. Creating the server then waits for an engine-specific readiness signal and records the endpoint that clients can reach from their network location. SQL also supports a metadata-only mode and an external-provider mode that does not provide a local connection.
The management surface groups each server with the child resources that clients use to shape and reach it:
| Service | Server resource | Child resource purpose |
|---|---|---|
| SQL Database | Server | Databases, connection policies, settings, and firewall rules |
| MySQL | Flexible server | Databases, configurations, and firewall rules |
| MariaDB | Server | Databases, configurations, and firewall rules |
| PostgreSQL | Flexible server | Databases, configurations, and firewall rules |
The sidecar manager owns container lifecycle, port selection, reachability, readiness, cleanup, and shutdown. It does not own application database setup. A configured host port is claimed before container creation when available. Otherwise the service can use an operating-system port so one server does not block another. PostgreSQL pulls its image before it claims a fixed port, then releases that claim on every failed start path. A failed start must not report a usable server.
Server provisioning
The control plane records the server resource before or during sidecar startup. Clients must use the reported provisioning state. They can then obtain connection details from the resource or the convenience connect endpoint before sending database traffic. A PostgreSQL server maps to one managed container, and the endpoint uses the address that the client can reach in its network mode.
SQL managed provisioning runs as a tracked long-running operation. The create request returns an operation location while a worker starts the sidecar. The operation reaches Succeeded only after the sidecar is attached to the server state and the master database is recorded. The worker pool reuses an active operation for the same server. A full queue produces a terminal provisioning error instead of a ready server. MySQL and MariaDB complete creation after startup. PostgreSQL starts its sidecar during the request, but returns the completed ARM-style 202 operation response expected by its clients for mutating requests.
PostgreSQL updates keep the running sidecar in place. When an update changes the administrator password, the service applies the new password to the live server before it stores the new management state. A bounded statement and a follow-up login settle an incomplete command where possible. A failed or unknown password change leaves the old credential as the valid control-plane value, and credentials are not written to errors.
The four engines use different readiness signals because an open port does not always mean that the engine can accept clients. SQL Server and PostgreSQL allow startup initialization after the port opens. PostgreSQL also waits through the image's first-boot initialization window. MySQL and MariaDB wait for the engine protocol handshake. SQL managed mode reports a separate provisioning operation while the sidecar starts. MySQL and MariaDB also apply administrator password changes inside the live sidecar, so management state changes only after the data-plane credential change succeeds.
References: src/…/SqlHandler.java• L237-351 src/…/SqlProvisioningService.java• L54-133 src/…/SqlServerManager.java• L74-182 src/…/PostgresHandler.java• L260-365 src/…/PostgresServerManager.java• L68-177 src/…/PostgresServerManager.java• L193-230 src/…/MySqlHandler.java• L181-337 src/…/MySqlServerManager.java• L50-159 src/…/MariaDbHandler.java• L181-369 src/…/MariaDbServerManager.java• L50-159
SQL child resources
SQL child resources describe database settings and server policy without changing the role of the local sidecar. The emulator keeps these resources with their parent and returns defaults until a client writes a value. Each supported setting has one fixed child name, and only the properties allowed by that setting are retained.
Database creation and update change the SQL management record only. The application still creates or changes the live database schema through the connection endpoint. Firewall rules are stored for API compatibility and are not enforced in the local development data plane.
References: src/…/SqlHandler.java• L491-589 src/…/SqlHandler.java• L649-759 src/…/SqlSettingType.java• L10-22 src/…/SqlState.java• L156-253
Connection forms
Each relational service returns connection forms for the client ecosystems most likely to use the local database. The selected database defaults to the engine's initial database when no database name is supplied.
| Service | Main local connection forms |
|---|---|
| SQL Database | JDBC, ADO.NET, ODBC, and EF Core |
| MySQL | JDBC, URI, command line, and .NET |
| MariaDB | JDBC, URI, command line, and .NET |
| PostgreSQL | JDBC, URI, psql, and .NET |
SQL Server requires explicit local acceptance of the image EULA before a managed sidecar can start. PostgreSQL local connection forms disable TLS because the stock local image does not provide the cloud certificate setup. These are local emulator boundaries rather than statements about Azure production transport.
References: src/…/SqlHandler.java• L761-877 src/…/MySqlHandler.java• L550-610 src/…/MariaDbHandler.java• L545-605 src/…/PostgresHandler.java• L606-624
Metadata-only operation
Relational services can run without a live data plane in supported metadata-only or mocked modes. These modes allow ARM-style resource workflows and CI planning without Docker. SQL's metadata-only mode keeps the logical server and master database without a sidecar. MySQL, MariaDB, and PostgreSQL mocked modes report management success without a sidecar. A successful management request does not imply that an application can open a database connection.
Persistent resource state can outlive a sidecar. On restart, the emulator restores management metadata but does not treat old container identifiers or ports as live endpoints. MySQL and MariaDB can rehydrate a sidecar when a later read or connection request needs one. PostgreSQL exposes restored metadata without silently starting a replacement sidecar.
The relational lifecycle moves from a logical resource to an engine endpoint only after the sidecar passes its readiness check.
This diagram shows the common relational path from a logical server to an application database endpoint.
flowchart LR
A[Create logical server] --> B[Prepare image and port]
B --> C[Start database sidecar]
C --> D{Engine ready?}
D -->|No| E[Clean up and fail provisioning]
D -->|Yes| F[Record reachable endpoint]
F --> G[Application creates schema and uses database]
References: src/…/SqlHandler.java• L294-341 src/…/SqlProvisioningService.java• L111-159 src/…/MySqlHandler.java• L296-373 src/…/MySqlServerManager.java• L50-159 src/…/MariaDbHandler.java• L291-369 src/…/MariaDbServerManager.java• L50-159 src/…/PostgresHandler.java• L390-432 src/…/PostgresServerManager.java• L68-177 src/…/PostgresServerManager.java• L341-367
Cache for Redis
Cache for Redis models a managed cache whose resource state, access keys, and client endpoints are controlled by the emulator. Its management surface supports cache lifecycle requests, key lookup, and key regeneration. The service can either keep only cache metadata or start a Redis-compatible sidecar for real cache traffic.
In mocked mode, a cache becomes Succeeded immediately and reports a local host without a Redis data plane. In sidecar mode, creation first records Creating and starts the cache. A readiness check confirms authenticated Redis access before the service applies both access keys and changes the cache to Succeeded. A failed start changes the cache to Failed instead of exposing a usable endpoint. Deletion stops the sidecar before it removes the managed resource.
The sidecar can expose plain Redis traffic and an optional TLS endpoint. The resource reports the host and port that clients can reach from their network location. In published mode it reports the Docker daemon address and allocated host ports. In a container network it can use the cloud-shaped Redis host name as a network alias. Key regeneration authenticates the live cache with the still-valid old key, then applies the replacement primary or secondary key so the stored keys and running cache stay aligned. The service also releases allocated ports, removes duplicate legacy records before they can leave extra sidecars running, and does not restore a cache record after a concurrent delete has won the resource race.
The relational and cache engine lifecycle page describes startup, readiness, persistence, and shutdown behavior in more detail.
References: src/…/RedisHandler.java• L118-159 src/…/RedisHandler.java• L231-351 src/…/RedisHandler.java• L387-425 src/…/RedisCacheManager.java• L89-179 src/…/RedisCacheManager.java• L249-327
Change checklist
When these files or sections are changed, remember to consider these:
- If Cosmos item, partition, TTL, query, or batch rules change, keep direct item requests, query paging, and transactional batch behavior aligned.
- If Cosmos query-plan or script behavior changes, keep SDK preflight responses, scalar
SELECT VALUEresults, script feeds, and stored-procedure execution responses aligned. - If Cosmos API selection changes, update both the embedded-versus-sidecar boundary and the connection details reported to clients. For embedded APIs, also check the route prefix and restart persistence described by the connection information.
- If Cosmos startup modes or lifecycle changes, keep eager, on-demand, disabled, mocked, embedded, and sidecar states aligned with reported connection availability.
- If Cosmos compatibility metadata changes, keep the reported parity, connection form, and limits aligned with the behavior of the selected engine. Treat the PostgreSQL API as a legacy compatibility mode.
- If a relational sidecar readiness check changes, verify that the matching control-plane state and connection endpoint cannot become usable before the engine is ready. Keep TCP-open checks separate from protocol readiness where the engine needs post-start initialization.
- If PostgreSQL startup or password rotation changes, keep the live container, reachable endpoint, readiness state, stored server state, and update response synchronized. Apply a password change before storing it, settle an incomplete command when possible, and do not restart a running server for a metadata-only update.
- If MySQL or MariaDB password rotation changes, keep the live administrator and root credentials aligned with the stored management password. Do not report the new password after a failed in-container change.
- If SQL provisioning changes, keep operation polling, cancellation, failure state,
mastercreation, and sidecar cleanup consistent. - If SQL provisioning queue or worker behavior changes, keep active-operation reuse, queue-full failure, terminal operation retention, and cancellation cleanup consistent with the server state.
- If SQL child settings or database update rules change, keep fixed child names, default responses, writable fields, parent state, and PUT/PATCH behavior aligned.
- If a relational connection format changes, check the default database, local transport settings, and the client-specific endpoint fields together.
- If port allocation or container reachability changes, check host-mode clients, Docker-network clients, image-pull ordering, failed startup cleanup, and shutdown release as one lifecycle. A claimed fixed port must be released even when container creation or readiness fails.
- If metadata-only or restart behavior changes, keep persisted management state separate from live container state. Check rehydration for MySQL and MariaDB separately from PostgreSQL's restored metadata behavior.
- If SQL data-plane provider modes change, keep metadata-only resources, asynchronous provisioning results, and
/connectavailability consistent. - If Redis create, delete, readiness, or sidecar update behavior changes, keep cache state, container ownership, endpoint reporting, and cleanup safe when requests overlap.
- If Redis TLS, startup, or key rotation changes, keep the stored keys, the authenticated readiness check, the plain and TLS endpoints, and the access-control state of the running cache synchronized.
- If Redis resource identity or legacy-state handling changes, keep case-insensitive names, duplicate cleanup, global name claims, and instance-safe sidecar updates aligned.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Cosmos patch changes an item system field or partition-key value | The item is rejected and the stored item stays unchanged | Protected-field and same-partition validation |
| Cosmos batch contains a failing operation | Earlier staged changes are not committed | All operations must succeed before the batch commits |
| Cosmos multi-property order has no matching composite index | The query is rejected instead of returning an incompatible result | Indexing-policy compatibility check |
| A continuation token is used with another query or partition | The next page is rejected | Token scope and ordering validation |
| A Cosmos SDK receives no matching query plan or scalar-result flag | Query execution can fail or return a wrapped value instead of the scalar | Return a single-partition plan with the correct SELECT VALUE marker |
| A stored procedure is executed after it is created | The request cannot run JavaScript in the emulator | Treat script resources as stored compatibility objects and return the unsupported-operation response |
| The embedded Table API is used across an emulator restart | In-memory tables and entities are lost | Treat Table API data as process-local state |
| A Cosmos API is enabled but its provider mode does not match its connection response | A client can receive a sidecar endpoint for embedded data or no usable data path | Keep provider metadata, lifecycle state, route handling, and connection information aligned |
| SQL child setting uses an unsupported name or property | The setting is not represented as the requested resource or the write silently loses unsupported fields | Validate the fixed child name and retain only declared writable properties |
| SQL Server EULA acceptance is missing | No SQL sidecar starts | Explicit EULA check before container creation |
| SQL managed provisioning is still in progress | The server has management state but no usable SQL endpoint | Poll the provisioning operation before using /connect |
| SQL provisioning queue is full | The new server is not provisioned and its operation reports a queue error | Keep the resource unavailable and return terminal ProvisioningQueueFull state |
| SQL is configured with no or external data-plane support | Management calls can succeed without a local database connection | Check the provider mode before treating the resource as data-plane ready |
| A relational sidecar port opens before the engine is ready | Clients can receive a connection endpoint that cannot yet authenticate | Engine-specific readiness wait |
| PostgreSQL administrator password rotation fails or its command outcome is unknown | The old password remains the valid control-plane credential and the update does not claim success | Apply the live change before committing metadata, verify an incomplete command with a login probe, and redact credentials from errors |
| MySQL or MariaDB administrator password rotation fails | The old password must remain valid and the new password must not be reported as active | Change the live users before committing management state and redact credentials from errors |
| Docker is unavailable in managed sidecar mode | Provisioning fails and no usable data endpoint is available | Terminal failed state and startup cleanup |
| A fixed host port is claimed before a sidecar start fails | Later resources cannot reuse the port | Release the claim on every failed start path |
| A resource is restored without its live sidecar | Management metadata exists but database traffic cannot use the old endpoint | Runtime container fields are not treated as persistent liveness |
| SQL provisioning is canceled during sidecar startup | The operation stops, but a late sidecar could remain or attach to a deleted resource | Check operation ownership before attaching and stop superseded containers |
| Redis runs in mocked mode | Cache management calls succeed without a Redis data plane | Mocked mode is kept separate from sidecar mode |
| Redis startup fails or readiness never succeeds | The cache stays unavailable instead of providing a false connection endpoint | Keep Failed or Creating state until the sidecar is usable |
| A cache is deleted while its sidecar start is finishing | A late start can leak a container or recreate a deleted resource | Match the running instance before storing startup state and stop an orphaned sidecar |
| Legacy case variants hold the same cache name | Duplicate records can leave extra Redis containers running | Remove shadowed records and stop their containers during startup |
| Redis TLS is enabled but the client uses the plain endpoint or wrong port | The client cannot establish the expected secure cache connection | Use the reported TLS endpoint and match the cache's TLS settings |
| Redis key rotation cannot authenticate with the current key | Stored key state and live cache authentication can diverge | Apply the new keys through an already valid key |
Key files
| File | Why to read it |
|---|---|
| src/…/CosmosHandler.java | Main Cosmos resource, item, query, batch, script, and account behavior |
| src/…/CosmosScriptKind.java | Shared meaning of the Cosmos script resource types |
| src/…/CosmosQueryEngine.java | Cosmos SQL query behavior and result paging |
| src/…/CosmosEngineHandler.java | Boundary between embedded Cosmos data paths and sidecar connection responses |
| src/…/CosmosLifecycleManager.java | Lifecycle boundary for non-default Cosmos API engines |
| src/…/PostgreSqlCosmosEngine.java | PostgreSQL Cosmos API compatibility level and connection form |
| src/…/TableCosmosEngine.java | Embedded Table API mode, connection route, and in-memory lifetime |
| src/…/SqlArmSurface.java | SQL server and child resource types exposed by the management surface |
| src/…/SqlHandler.java | SQL provider modes, resource provisioning, settings, and connection availability |
| src/…/SqlServerManager.java | SQL sidecar startup, endpoint selection, readiness, port claims, and shutdown |
| src/…/SqlSettingType.java | SQL setting names, defaults, writable fields, and PUT/PATCH rules |
| src/…/SqlProvisioningService.java | Asynchronous SQL sidecar provisioning, queueing, cancellation, and operation state |
| src/…/SqlState.java | SQL resource persistence, child resources, settings, and runtime state |
| src/…/MySqlHandler.java | MySQL server management, sidecar rehydration, and connection discovery |
| src/…/MySqlServerManager.java | MySQL sidecar startup, handshake readiness, password rotation, port claims, and shutdown |
| src/…/MariaDbHandler.java | MariaDB server management, sidecar rehydration, and connection discovery |
| src/…/MariaDbServerManager.java | MariaDB sidecar startup, handshake readiness, password rotation, port claims, and shutdown |
| src/…/PostgresHandler.java | PostgreSQL ARM operation responses, resource updates, and connection discovery |
| src/…/PostgresServerManager.java | PostgreSQL sidecar startup, reachable endpoint selection, readiness, port cleanup, and live password changes |
| src/…/RedisHandler.java | Redis management state, resource identity, readiness transitions, cleanup, and key actions |
| src/…/RedisCacheManager.java | Redis sidecar, readiness, access keys, TLS, port allocation, and cache endpoint behavior |
| src/…/RedisModels.java | Redis cache state and endpoint fields shared by management and sidecar flows |
| docs/storage-backends.md | Storage choices that control persistence of managed database resource state |
| docs/build-and-config.md | Service and data-plane choices that control which database modes run |