Oracle (TNS/TTC) implementation reference

This page describes how the Oracle wire is built: the TNS listener and packet framing, the TTC message dispatch, O5LOGON authentication, how statements reach the engine, type and error mapping, transactions, limits and tests. For the port, the proof scores, how to connect and how to re-run the differential suite, see the operator page Oracle (TNS). Authentication policy across all wires is in Security.

Code lives in src/protocol/oracle/:

File Role
mod.rs OracleHandler: listener, serve_connection, TTC dispatch (handle_ttc_data), O5LOGON, OALL8 execute, fetch, LOB operations, ora_error.
tns.rs TNS packet types, header encoding, take_packet.
ttc.rs, wire.rs TTC message structures, OraReader and the legacy TtcHeader path.
query.rs Response builders for the OALL8 query path (describe, row header, row data, error/status), Oracle NUMBER encoding.
crypto.rs O5LOGON key derivation and verify_speedy_key.
dialect.rs Oracle SQL to engine SQL translation, bind substitution, dictionary views.
plsql.rs PL/SQL interpreter: anonymous blocks, stored procedures, functions and packages.
trigger.rs DML triggers stored in _ora_triggers.
types.rs, objwire.rs User-defined object, nested table and VARRAY types and their wire images.
admin.rs ALTER SESSION, COMMENT ON, synonyms, and the _ora_objects / _ora_source / _ora_comments registry.

REAL_PROTOCOL_NOTES.md in the same directory holds developer notes; this page does not rely on it. (source: src/protocol/oracle/, module doc comments)

Listener and connection lifecycle

  • The default port is 1521 (oracle_port in ServerConfig::default). The wire starts only when the port is set; a config file that omits the key turns it off. Server::start_handler binds the port before the handler starts, so a port clash fails startup. (source: src/config.rs, ServerConfig::default; src/server/mod.rs, Server::start_handler)
  • With SYNERGYDB_ORACLE_THREAD_PER_CONN on (the default), each connection gets its own OS thread named ora-<port> with an 8 MiB stack and a current-thread Tokio runtime. Otherwise the connection runs as a task and blocking engine calls use block_in_place. (source: src/protocol/oracle/mod.rs, OracleHandler::start)
  • TLS (TCPS) is on the same port: TlsListener::accept_auto peeks the first byte, and 0x16 starts a TLS handshake. A plaintext connection is accepted only when require_tls is off or the peer is loopback. The first byte must arrive within 30 s. (source: src/protocol/tls.rs, TlsListener::accept_auto) Not verified: no Rust test connects to the Oracle wire over TLS.
  • Timeouts: a connect timeout applies before login, an idle timeout after login, a read timeout mid-packet and a write timeout on writes. The test stalled_client_is_disconnected covers a client that stops sending. (source: src/protocol/oracle/mod.rs, serve_connection, test stalled_client_is_disconnected)
  • SYNERGYDB_ORACLE_TRACE hex-dumps traffic and logs translated SQL to stderr. (source: src/protocol/oracle/mod.rs, serve_connection, run_oall8)

TNS framing

The TNS header is 8 bytes. Packet types handled (source: src/protocol/oracle/tns.rs, PacketType):

Type Value Handling
Connect 1 Parsed for the connect descriptor; answered with Accept.
Accept 2 Sent by the server; echoes the client version and SDU.
Ack 3 Defined.
Refuse 4 Sent on a refused connect.
Redirect 5 Defined.
Data 6 Carries TTC messages.
Null 7 Defined.
Abort 9 Closes the connection.
Resend 11 Defined.
Marker 12 A break marker (1) is answered with a reset marker (2).
Attention 13 Defined.
Control 14 Defined.

(source: src/protocol/oracle/tns.rs, PacketType; src/protocol/oracle/mod.rs, serve_connection)

  • Before Accept the length field is the legacy 16-bit form. After Accept, when the negotiated version is at least TNS_VERSION_MIN_LARGE_SDU (315), the length is 32-bit. (source: src/protocol/oracle/tns.rs, TNS_VERSION_MIN_LARGE_SDU)
  • One TNS packet is limited to 2 MiB (MAX_PACKET_SIZE, take_packet). DATA packets that fill the SDU are joined into one TTC request up to MAX_TTC_REQUEST_SIZE (64 MiB); the server waits SDU_CONTINUATION_WAIT (1 s) for a continuation. (source: src/protocol/oracle/tns.rs, take_packet; src/protocol/oracle/mod.rs, MAX_TTC_REQUEST_SIZE, SDU_CONTINUATION_WAIT)
  • A Connect whose connect data is over 230 bytes is followed by a separate DATA packet with that data; the handshake waits for it. Test: connect_data_packet_split_from_connect_completes_handshake. (source: src/protocol/oracle/mod.rs, serve_connection)
  • SERVICE_NAME from the connect descriptor becomes the schema. A USER in the descriptor is ignored; the user comes from the auth message. (source: src/protocol/oracle/mod.rs, serve_connection)

TTC dispatch

handle_ttc_data first consumes piggyback messages (type 17). Before login only is_pre_login_message passes: message types 1 and 2, type 3 with function 118, 115 or 9, and the legacy SetProtocol, Auth, Version and Logoff. Anything else gets ORA-01012 "not logged on". Tests: only_the_login_handshake_is_allowed_before_login, execute_before_login_is_refused. (source: src/protocol/oracle/mod.rs, handle_ttc_data, is_pre_login_message)

Message type / function Meaning Handler
1 Protocol negotiation build_protocol_response (negotiates TTC field version 11.2).
3 / 118 O5LOGON phase one build_auth_phase_one_response
3 / 115 O5LOGON phase two build_auth_accept_response
3 / 94 OALL8 execute handle_oall8_execute then run_oall8
3 / 4, 3 / 78 Re-execute, re-execute and fetch handle_oall8_reexecute
3 / 5 Fetch fetch from the cursor's held result
3 / 96 LOB operation handle_lob_op
3 / 14, 3 / 15 Commit, rollback engine COMMIT / ROLLBACK
3 / 147 Ping status reply
3 / 9 Logoff ends the session
anything else (including type 2, data types) Legacy TtcHeader path SetProtocol (0x02) gets a 3-byte OK; Auth, Parse, Execute, Fetch, Commit, Rollback, CloseCursor, Bind, Define, Describe, Version; unknown gets "Unsupported operation" (0xFF).

(source: src/protocol/oracle/mod.rs, handle_ttc_data; src/protocol/oracle/query.rs, module doc)

Not verified: the data-types message (type 2) is answered through the legacy path with an OK rather than an echo of the client's type table. The python-oracledb runs in the proof log pass with this, but no Rust test covers it.

Authentication (O5LOGON)

Phase one (function 118)

  • The username comes from the auth message. The verifier is the catalog's 12c verifier for that role (get_oracle_12c_verifier; exact name first, then lowercase). (source: src/protocol/oracle/mod.rs, catalog_oracle_verifier, extract_auth_username)
  • A role that cannot log in or has no password is refused and is sent a random verifier. A role not in the catalog falls back to auth_config.oracle_verifier; an unknown user gets a random verifier, so the proof check in phase two fails. Test: test_empty_registry_fails_closed_without_dev_flag. (source: src/protocol/oracle/mod.rs, catalog_oracle_verifier)
  • The reply carries AUTH_VFR_DATA (salt, verifier type 0x4815), AUTH_SESSKEY (AES-256-CBC), AUTH_PBKDF2_VGEN_COUNT 4096, AUTH_PBKDF2_CSK_SALT, AUTH_PBKDF2_SDER_COUNT 3 and AUTH_VERSION_NO 386138880. (source: src/protocol/oracle/mod.rs, build_auth_phase_one_response, O5_VGEN_COUNT)

Phase two (function 115)

  • The server decrypts the client's AUTH_SESSKEY, builds the combined key and checks AUTH_PBKDF2_SPEEDY_KEY with crypto::verify_speedy_key. A wrong password gets ORA-01017. (source: src/protocol/oracle/mod.rs, build_auth_accept_response; src/protocol/oracle/crypto.rs, verify_speedy_key)
  • On success the reply carries AUTH_SVR_RESPONSE, AUTH_SESSION_ID 1, AUTH_SERIAL_NUM 1, AUTH_VERSION_STRING "SynergyDB 19.0.0.0.0" and AUTH_SC_INSTANCE_ID 1. (source: src/protocol/oracle/mod.rs, build_auth_accept_response)
  • session_engine then opens an engine for the role (exact name, then lowercase) with database synergydb and a shared transaction manager. (source: src/protocol/oracle/mod.rs, session_engine)
  • SYNERGYDB_DEV_INSECURE_AUTH lets an unprovisioned user log in with a verifier derived from SYNERGYDB_SUPERUSER_PASSWORD and skips the proof check. Test harnesses only. (source: src/protocol/oracle/mod.rs, o5_password; src/auth/wire_auth.rs, dev_insecure_auth_enabled)

Not verified: login uses the stored verifier, not verify_wire_credential, so this page could not confirm that the synergy_wire_oracle membership check applies on this wire. tests/protocol_oracle.rs module auth_config tests the OracleAuthConfig helper (no default users, scott/tiger is not a backdoor), not the O5LOGON exchange.

How statements reach the engine

handle_oall8_execute parses the cursor id, SQL, bind rows, options and bind types. A fresh cursor id is allocated when the request has cursor 0; the SQL and bind shape are kept in real_statements so a re-execute can run again with new values. An execute on an existing cursor with no SQL reuses the stored statement or, for a REF CURSOR or implicit result, fetches from the held result. A define after a LOB describe turns CLOB/BLOB columns back into LONG/LONG RAW inline data when the client asked for that. (source: src/protocol/oracle/mod.rs, handle_oall8_execute)

run_oall8 then routes the statement in this order (source: src/protocol/oracle/mod.rs, run_oall8):

  1. LOB bind markers are resolved to the bytes held in the session.
  2. Several bind rows (executemany): a plain INSERT ... VALUES with no batch-errors flag and no triggers is first tried as a direct row copy (array_insert_copy), then as multi-row INSERTs of ARRAY_INSERT_CHUNK (1000) rows; anything else runs row by row. With EXEC_OPTION_BATCH_ERRORS (0x80000) the failing row offsets are collected and returned with build_batch_error_response.
  3. NLS_DATE_FORMAT from the session (default DD-MON-RR) is set for translation.
  4. types::handle_ddl (CREATE/DROP TYPE), trigger::handle_ddl, and admin::handle (ALTER SESSION, COMMENT ON, synonyms). Each commits an open transaction first.
  5. plsql::is_plsql (statements starting BEGIN or DECLARE, or CREATE of a procedure, function, trigger, package or type) goes to run_plsql.
  6. DROP PROCEDURE/FUNCTION/PACKAGE [BODY] goes to plsql::drop_routine.
  7. Everything else is translated by dialect::translate and run on the engine. DML on a table with triggers runs through exec_with_triggers, row by row.

dialect.rs rewrites Oracle types, functions, DUAL, ROWNUM, MINUS, sequences, dictionary views, empty string as NULL and NUMBER division, substitutes binds as typed literals, and names result columns the Oracle way (COUNT(*), upper case). (source: src/protocol/oracle/dialect.rs, module doc)

PL/SQL, triggers and object types

  • plsql.rs interprets anonymous blocks, variables, SELECT ... INTO, DML, EXECUTE IMMEDIATE, IF/LOOP/WHILE/FOR, named and user exceptions, RAISE_APPLICATION_ERROR, and stored procedures and functions kept in storage. Expressions are evaluated as SELECT <expr> FROM dual. (source: src/protocol/oracle/plsql.rs, module doc, is_plsql) Four unit tests in plsql.rs.
  • trigger.rs stores triggers in _ora_triggers. A DML statement on a table with enabled triggers reads the affected rows, runs BEFORE ROW triggers (which can change :NEW), writes each row by primary key, then runs AFTER ROW triggers; statement triggers run before and after. Nesting is limited to 32 (MAX_DEPTH). (source: src/protocol/oracle/trigger.rs, module doc, MAX_DEPTH) One unit test in trigger.rs.
  • types.rs implements CREATE TYPE ... AS OBJECT, AS TABLE OF and AS VARRAY(n) OF. Object values are stored as JSON text keyed by upper-case attribute names; TABLE(coll(...)) becomes a VALUES list. objwire.rs builds the type descriptors that DBMS_PICKLER.GET_TYPE_SHAPE returns and the pickled images in rows and binds. (source: src/protocol/oracle/types.rs, src/protocol/oracle/objwire.rs, module docs) No unit tests in either file.

LOB operations (function 96)

handle_lob_op handles GET_LENGTH (0x0001), READ (0x0002), TRIM (0x0020), WRITE (0x0040), GET_CHUNK_SIZE (0x4000), CREATE_TEMP (0x0110), FREE_TEMP (0x0111) and IS_OPEN (0x11000); the array flag 0x80000 is masked off. LOB data lives in the session (session.lobs). An unknown locator gets ORA-22922 "nonexistent LOB value"; an unreadable request gets ORA-00600 "malformed LOB operation". (source: src/protocol/oracle/mod.rs, handle_lob_op) Not verified: no Rust test drives a LOB operation.

Type mapping

Result columns are described by pg_oid_to_ora_meta (source: src/protocol/oracle/mod.rs, pg_oid_to_ora_meta):

Engine type Oracle type sent Size
int2, int4, int8, numeric, float4, float8 NUMBER 22
date DATE 7
timestamp TIMESTAMP 11
timestamptz TIMESTAMP WITH TIME ZONE 13
interval (OID 1186) INTERVAL DAY TO SECOND 11
bytea RAW 2000
everything else (text, bool, time, json, uuid) VARCHAR2 4000

CLOB and BLOB columns are sent as LOB locators and switched to LONG / LONG RAW when the client defines them that way (see above). Strings are limited to MAX_STRING_SIZE (4000). Numbers use the Oracle NUMBER encoding ported from python-oracledb. (source: src/protocol/oracle/mod.rs, handle_oall8_execute, MAX_STRING_SIZE; src/protocol/oracle/query.rs, module doc)

The proof log shows the remaining differences are NUMBER precision and scale metadata: SynergyDB reports null, null where Oracle reports 38, 0 or 0, -127, and in one view the other way round. (source: docs/proof/2026-11-30/proof-pack-a3232c9/logs/oracle-oracle-diff.txt)

Error mapping

ora_error turns an engine error into an ORA code. An error that already carries __ora_err:<code>: (from PL/SQL or triggers) keeps its code. Otherwise message text is checked first, then the error kind (source: src/protocol/oracle/mod.rs, ora_error):

Condition ORA code
CURRVAL not yet defined 08002
sequence does not exist 02289
already exists 00955
invalid input syntax for numeric types, invalid number, type mismatch 01722
insert into a generated-always identity column 32795
permission denied 01031
table not found 00942
column not found 00904 (name in upper case)
unique or primary key; unclassified constraint 00001
NOT NULL 01400
foreign key, child row exists 02292
foreign key, parent missing 02291
CHECK 02290
division by zero 01476
numeric out of range 01438
string too long 12899
single-row subquery returned more than one row 01427
lock not available or lock timeout 00054
deadlock 00060
serialization conflict 08177
parse error 00900
unsupported 03001
function or procedure does not exist 04043
anything else 00900 with the engine text

The fallback is ORA-00900, not ORA-00600, because drivers treat ORA-00600 as a dead session. ORA-00600 is still sent for protocol-level faults (malformed execute, unknown cursor, no storage engine). (source: src/protocol/oracle/mod.rs, ora_error, handle_oall8_execute, run_oall8)

Transactions

  • DML, SELECT ... FOR UPDATE and PL/SQL open a transaction that stays open until COMMIT or ROLLBACK; there is no autocommit unless the client sets it. DDL commits an open transaction first and is then committed. A failing statement rolls back only its own work. (source: src/protocol/oracle/mod.rs, doc comment above array_insert_copy, run_oall8)
  • The client's autocommit is the EXEC_OPTION_COMMIT bit (0x100) on execute, or bit 0x1 of the second options word on re-execute; the server commits after a successful statement. (source: src/protocol/oracle/mod.rs, handle_oall8_execute, handle_oall8_reexecute, run_oall8)
  • Function 14 commits and function 15 rolls back. (source: src/protocol/oracle/mod.rs, handle_ttc_data)

Limits and configuration

Setting Default Effect
[server] oracle_port 1521 Listener port; omitted in a config file means off.
SYNERGYDB_ORACLE_THREAD_PER_CONN on One OS thread (8 MiB stack) per connection.
SYNERGYDB_ORACLE_TRACE unset Hex dump and SQL trace to stderr.
SYNERGYDB_DEV_INSECURE_AUTH unset Unprovisioned users can log in (test harnesses only).
MAX_PACKET_SIZE 2 MiB One TNS packet.
MAX_TTC_REQUEST_SIZE 64 MiB One reassembled TTC request.
MAX_STRING_SIZE 4000 VARCHAR2 column size reported.
ARRAY_INSERT_CHUNK 1000 Rows per combined array INSERT.

(source: src/config.rs, ServerConfig::default; src/protocol/oracle/mod.rs, constants; src/protocol/oracle/tns.rs, MAX_PACKET_SIZE)

Not implemented

  • Any TTC message that reaches the legacy TtcHeader path with an unknown operation is answered "Unsupported operation" (0xFF). (source: src/protocol/oracle/mod.rs, handle_ttc_data)
  • ATTACH-style multi-database access is not offered: the session always uses database synergydb, and SERVICE_NAME only picks the schema. (source: src/protocol/oracle/mod.rs, session_engine, serve_connection)
  • The operator page lists packages, triggers, user-defined types and LOB writes as not implemented and SUBSTR on a CLOB returning VARCHAR2. The code at this snapshot has a trigger engine, package handling in the PL/SQL interpreter (DROP_PKG, DROP_PKG_BODY), object and collection types, and LOB WRITE/TRIM/CREATE_TEMP. Which of these work end to end is Not verified by any Rust test. (source: src/protocol/oracle/trigger.rs, src/protocol/oracle/plsql.rs, src/protocol/oracle/types.rs, src/protocol/oracle/mod.rs, handle_lob_op)

Tests and proof

Where What
src/protocol/oracle/** unit tests dialect.rs 21, query.rs 9, tns.rs 7, mod.rs 6 (pre-login gate, split connect data, stalled client, fail-closed registry, handler creation), plsql.rs 4, crypto.rs 3, ttc.rs 3, wire.rs 3, trigger.rs 1.
tests/protocol_oracle.rs Modules auth_config, sql_via_query_engine, handler_construction, error_handling. They test OracleAuthConfig and QueryEngine directly, not the wire.
Proof log docs/proof/2026-11-30/proof-pack-a3232c9/logs/oracle-oracle-diff.txt: "Oracle: 204/219 match (single 194/208, cross 5/5, durable 5/6)" against Oracle Database 23ai Free with python-oracledb thin. The DIFF lines are NUMBER precision/scale metadata.

(source: the files named)

No Rust test drives O5LOGON, OALL8, fetch, LOBs or TLS over a socket; those are covered only by the Python differential suite behind the proof log. The proof log also ends with python-oracledb IndexError tracebacks from the client's statement cache during cursor cleanup; they do not change the score line.