pg_onnx
pg_onnx · ONNX Runtime integrated with PostgreSQL. Perform ML inference with data in your database.
Overview
PostgreSQL · 13, 14, 15, 16, 17, 18
Usage
Sources:
pg_onnx runs ONNX inference from PostgreSQL. Release v1.32.0a bundles onnxruntime-server 1.32.0a; the SQL extension schema remains 1.2.1, with PostgreSQL 13–18 on Ubuntu and 14–18 on macOS. A dynamic background worker hosts onnxruntime-server and reuses one runtime session per imported model, avoiding a separate large runtime allocation in every client backend.
Release 1.32.0 recognizes FLOAT6E2M3 and FLOAT6E3M2 tensor type names, but the runtime still rejects allocating those tensors; this is not float6 inference support.
Pass model bytes as a parameter; do not use a caller-controlled server file path. Restrict import, drop, session, and execution functions. An ONNX model and optional custom-operation library are executable native inputs: accept only reviewed, hashed artifacts and constrain extension-library paths. Treat outputs as model results, not deterministic database facts.
Plan CPU, GPU, RAM, worker slots, timeouts, cancellation, model size, session recycling, and concurrency. Test worker crash/restart, transaction rollback around model metadata, failover, replicas, backup/restore, CUDA/ONNX Runtime ABI, and upgrades. Trigger-based inference adds remote computation to writes and can block or fail transactions; prefer asynchronous inference unless synchronous semantics are essential.
Scalar Outputs
Release v1.32.0a fixes an unsigned dimension-count underflow when serializing rank-zero tensors. Scalar model outputs now return single-element JSON arrays from pg_onnx_execute_session. Upgrade the bundled runtime and extension together and recheck the output shape expected by callers. Microsoft ONNX Runtime remains 1.32.0; this patch does not claim to fix separate vulnerabilities in that library. SQL extension version 1.2.1 is unchanged.