IMPL_3420 - PostgreSQL Patterns Implementation Program
Status: IMPLEMENTED
Priority: HIGH
Program Owner: Platform Team
Created: 2025-12-14
Implementation Date: 2025-12-14
Target Completion: Q1 2026
1. Executive Summary
This implementation program delivers four PostgreSQL pattern enhancements identified in the gap analysis of docs/product-advisories/14-Dec-2025 - PostgreSQL Patterns Technical Reference.md. These patterns strengthen StellaOps' data layer for determinism, multi-tenancy security, query performance, and operational efficiency.
1.1 Program Scope
| Sprint |
Pattern |
Priority |
Complexity |
Est. Duration |
| SPRINT_3420_0001_0001 |
Bitemporal Unknowns Schema |
HIGH |
Medium-High |
2-3 weeks |
| SPRINT_3421_0001_0001 |
RLS Expansion |
HIGH |
Medium |
3-4 weeks |
| SPRINT_3422_0001_0001 |
Time-Based Partitioning |
MEDIUM |
High |
4-5 weeks |
| SPRINT_3423_0001_0001 |
Generated Columns |
MEDIUM |
Low-Medium |
1-2 weeks |
1.2 Not In Scope (Deferred/Rejected)
| Pattern |
Decision |
Rationale |
routing schema (feature flags) |
REJECTED |
Conflicts with air-gap/offline-first design |
| PostgreSQL LISTEN/NOTIFY |
REJECTED |
Redis Pub/Sub already fulfills this need |
pgaudit extension |
DEFERRED |
Optional for compliance deployments only |
2. Strategic Alignment
2.1 Core Principles Supported
| Principle |
How This Program Supports It |
| Determinism |
Bitemporal unknowns enable reproducible point-in-time queries |
| Offline-first |
All patterns work without external dependencies |
| Multi-tenancy |
RLS provides database-level tenant isolation |
| Performance |
Generated columns and partitioning optimize hot queries |
| Auditability |
Bitemporal history supports compliance audits |
2.2 Business Value
3. Dependency Graph
3.1 Sprint Dependencies
| Sprint |
Depends On |
Blocking |
| 3420 (Bitemporal) |
None |
Integration tests |
| 3421 (RLS) |
None |
3422 (partitioning) |
| 3422 (Partitioning) |
3421 (RLS must be applied to partitioned tables) |
None |
| 3423 (Generated Cols) |
None |
None |
4. Implementation Phases
Phase 1: Foundation (Weeks 1-4)
Objective: Establish bitemporal unknowns and begin RLS expansion
| Week |
Focus |
Deliverables |
| 1 |
Bitemporal schema design |
unknowns schema DDL, domain models |
| 2 |
Bitemporal implementation |
Repository, migration from vex.unknown_items |
| 3 |
RLS scheduler schema |
scheduler_app.require_current_tenant(), policies |
| 4 |
RLS vex schema |
VEX schema RLS policies |
Exit Criteria:
Phase 2: Security Hardening (Weeks 5-7)
Objective: Complete RLS rollout and add generated columns
| Week |
Focus |
Deliverables |
| 5 |
RLS authority + notify |
Identity and notification schema RLS |
| 6 |
RLS policy + validation |
Policy schema RLS, validation service |
| 7 |
Generated columns |
SBOM and advisory hot fields extracted |
Exit Criteria:
Phase 3: Scalability (Weeks 8-12)
Objective: Implement time-based partitioning for high-volume tables
| Week |
Focus |
Deliverables |
| 8 |
Partition infrastructure |
Management functions, retention config |
| 9 |
scheduler.runs partitioning |
Migrate runs table to partitioned |
| 10 |
execution_logs partitioning |
Migrate logs table |
| 11 |
vex + notify partitioning |
Timeline events, deliveries |
| 12 |
Automation + monitoring |
Maintenance job, alerting |
Exit Criteria:
Phase 4: Validation & Documentation (Weeks 13-14)
Objective: Integration testing, performance validation, documentation
| Week |
Focus |
Deliverables |
| 13 |
Integration testing |
Cross-schema tests, failure scenarios |
| 14 |
Documentation |
Runbooks, SPECIFICATION.md updates |
Exit Criteria:
5. Risk Register
| # |
Risk |
Likelihood |
Impact |
Mitigation |
| R1 |
RLS performance overhead |
Medium |
Medium |
Benchmark before/after; use efficient policies |
| R2 |
Partitioning migration downtime |
High |
High |
Use dual-write pattern for zero-downtime |
| R3 |
Generated column storage bloat |
Low |
Low |
Monitor disk usage; columns are typically small |
| R4 |
FK references to partitioned tables |
Medium |
Medium |
Use trigger-based enforcement or denormalize |
| R5 |
Bitemporal query complexity |
Medium |
Low |
Provide helper functions and views |
6. Success Metrics
6.1 Security Metrics
| Metric |
Target |
Measurement |
| RLS coverage |
100% of tenant-scoped tables |
RlsValidationService in CI |
| Cross-tenant query attempts blocked |
100% |
Integration test suite |
6.2 Performance Metrics
| Metric |
Baseline |
Target |
Measurement |
| SBOM format filter query |
800ms |
<50ms |
EXPLAIN ANALYZE |
| Dashboard summary query |
2000ms |
<200ms |
Application metrics |
| Retention cleanup time |
O(n) DELETE |
O(1) DROP |
Maintenance job logs |
| Partition pruning efficiency |
N/A |
>90% queries pruned |
pg_stat_statements |
6.3 Operational Metrics
| Metric |
Target |
Measurement |
| Partition creation automation |
100% hands-off |
No manual partition creates |
| Retention policy compliance |
<1 day overdue |
Monitoring alerts |
| Bitemporal query success rate |
>99.9% |
Application logs |
7. Resource Requirements
7.1 Team Allocation
| Role |
Allocation |
Duration |
| Backend Engineer (DB focus) |
1.0 FTE |
14 weeks |
| Backend Engineer (App layer) |
0.5 FTE |
14 weeks |
| DevOps Engineer |
0.25 FTE |
Weeks 8-14 |
| QA Engineer |
0.25 FTE |
Weeks 12-14 |
7.2 Infrastructure
| Resource |
Requirement |
| Staging PostgreSQL |
16+ with 100GB+ storage |
| Test data generator |
10M+ rows per table |
| CI runners |
PostgreSQL 16 Testcontainers |
8. Sprint Index
| Sprint ID |
Title |
Document |
| SPRINT_3420_0001_0001 |
Bitemporal Unknowns Schema |
Link |
| SPRINT_3421_0001_0001 |
RLS Expansion |
Link |
| SPRINT_3422_0001_0001 |
Time-Based Partitioning |
Link |
| SPRINT_3423_0001_0001 |
Generated Columns |
Link |
9. Approval & Sign-off
| Role |
Name |
Date |
Signature |
| Program Owner |
|
|
|
| Tech Lead |
|
|
|
| Security Review |
|
|
|
| DBA Review |
|
|
|
10. Revision History
| Version |
Date |
Author |
Changes |
| 1.0 |
2025-12-14 |
AI Analysis |
Initial program definition |
| 2.0 |
2025-12-14 |
Claude Opus 4.5 |
Implementation completed - all sprints implemented |
Appendix A: Gap Analysis Summary
Implemented Patterns (No Action Needed)
- Multi-tenancy with
tenant_id column
- SKIP LOCKED queue pattern
- Audit logging (per-schema)
- JSONB for semi-structured data
- Connection pooling (Npgsql)
- Session configuration (UTC, statement_timeout)
- Advisory locks for migrations
- Distributed locking
- Deterministic pagination (keyset)
- Index strategies (B-tree, GIN, composite, partial)
Partially Implemented Patterns
- RLS policies - Only
findings_ledger → Expand to all schemas
- Outbox pattern - Interface exists → Consider
core.outbox table (future)
- Partitioning - LIST by tenant → Add RANGE by time for high-volume
Not Implemented Patterns (This Program)
- Bitemporal unknowns - New schema with temporal semantics
- Generated columns - Extract JSONB hot keys
- Time-based partitioning - Monthly RANGE partitions
Rejected Patterns
- routing schema - Conflicts with offline-first architecture
- LISTEN/NOTIFY - Redis Pub/Sub is sufficient
- pgaudit - Optional for compliance (document only)
Appendix B: Related Documentation
docs/db/SPECIFICATION.md - Database design specification
docs/db/RULES.md - Database coding rules
docs/db/MIGRATION_STRATEGY.md - Migration approach
docs/operations/postgresql-guide.md - Operational runbook
docs/adr/0001-postgresql-for-control-plane.md - Architecture decision
docs/product-advisories/14-Dec-2025 - PostgreSQL Patterns Technical Reference.md - Source advisory