pg_bao
pg_bao · Bao learned query optimizer hooks with an external model server
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 102442 | pg_bao | pg_bao | 0.0.1 | FEAT | AGPL-3.0-only | C |
PostgreSQL · 12
Usage
Sources:
- Official source
- Official source
- Official source
- Official source
- Official source
- Official source
- Official source
pg_bao is the Bao learned-query-optimizer prototype. Its control version is 0.0.1; the accompanying SQL script is empty. The official tutorial demonstrates PostgreSQL 12.3. No support for current PostgreSQL majors is implied by that historical example.
Activate the Hook
After installing a matching library in a research cluster, preserve existing preload entries, add the module and restart PostgreSQL. Start the separate Bao model server before using it:
Replace the example table with an existing relation. Activation is through preload and session settings, not through database SQL objects. enable_bao defaults off. The separate enable_bao_selection and enable_bao_rewards settings control plan selection and latency-feedback collection when it is enabled. The Bao server maintains and retrains the model.
Observe Behavior
EXPLAIN includes Bao’s prediction and recommended hint when enabled. An untrained server may report no prediction. Training needs representative completed workloads and sufficient observations; compare total planning plus execution time to the ordinary optimizer. The implementation considers multiple hint alternatives sequentially, which adds planning cost.
Security and Maintenance
The model server provides neither authentication nor encryption. Restrict it to a trusted network and intended clients. Although predicate literals are omitted from its plan representation, relation names, plan shapes and execution measurements still leave PostgreSQL. Upstream marks the code as a prototype not audited for production security.
Preserve training/model state separately from PostgreSQL backups. Removing preload takes a server restart; disabling the session setting is the immediate way to stop using its optimizer path in that session. The project supplies no SQL migration chain or verified modern-major compatibility matrix. The implementation is licensed under AGPLv3.