Conversation
…rage Add migrate_from_native() and migrate_to_native() SQL functions that move large objects between PostgreSQL's native pg_catalog storage and lolor's replication-compatible tables, preserving OIDs, owners, ACLs, and data. The DROP EXTENSION event trigger now calls migrate_to_native() automatically before removing the extension, preventing data loss that previously occurred when lolor tables were dropped with the schema. Key details: - Forward migration uses bulk INSERT for performance - Reverse migration uses the native LO API (lo_create_orig/lowrite_orig) since direct INSERT into pg_catalog.pg_largeobject is not allowed - LOBLKSIZE derived at runtime from block_size GUC for non-default builds - Uses lo_lseek64_orig for large objects exceeding 2 GB - Both functions require superuser and verify lolor is enabled - Event trigger guards migrate_to_native() with pg_proc existence check for backward compatibility with versions < 1.2.3 - Emits NOTICE during installation if streaming replicas are detected - Migration is safe only in master-replica configurations for now Add regression tests for forward migration, reverse migration via DROP EXTENSION, manual migrate_to_native, empty-database edge cases, and the 1.2.2 to 1.2.3 upgrade path.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (8)
📝 WalkthroughWalkthroughThis pull request adds version 1.2.3 of the lolor PostgreSQL extension with bidirectional large object migration support. Two new SQL functions enable migrating native PostgreSQL large objects to lolor storage and back, with automatic migration triggered during extension drop. Documentation, tests, and build configuration are updated to reflect the new feature. Changes
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Up to standards ✅🟢 Issues
|
| Category | Results |
|---|---|
| Compatibility | 26 high (25 false positives) |
🟢 Metrics 0 duplication
Metric Results Duplication 0
TIP This summary will be updated as you push new changes. Give us feedback
| END IF; | ||
|
|
||
| -- Migrate each object using the native LO API (_orig functions). | ||
| -- We cannot INSERT directly into pg_catalog.pg_largeobject from SQL, |
There was a problem hiding this comment.
Superusers can do INSERT directly into pg_catalog.pg_largeobject. That restriction applies only for non-superusers. Since both functions already require superuser, the loop can be replaced with bulk INSERT ... SELECT, the same approach migrate_from_native() uses.
Adds
lolor.migrate_from_native()andlolor.migrate_to_native()SQL functionsthat move large objects between PostgreSQL's native
pg_catalogstorage andlolor's replication-compatible tables, preserving OIDs, owners, ACLs, and data.
Design decisions
migrate_from_native()explicitly afterCREATE EXTENSION lolor. This requires superuser and should be done during a maintenance window.DROP EXTENSION lolortriggersmigrate_to_native()via the event trigger, ensuring no large objects are lost on extension removal. If migration fails (e.g. OID conflict), the DROP is rejected so the user can resolve the issue and retry.Implementation details
INSERTfor performance; reverse migration uses the native LO API (lo_create_orig/lo_lseek64_orig/lowrite_orig) since directINSERTintopg_catalog.pg_largeobjectis not allowed from SQL.LOBLKSIZEis derived at runtime fromcurrent_setting('block_size')to support non-default block sizes.lo_lseek64_origwithbigintoffsets to handle large objects exceeding 2 GB.migrate_to_native()with apg_procexistence check for backward compatibility with lolor versions < 1.2.3.lo_unlink_origto avoid scanning the catalog while modifying it.NOTICEduring installation if active streaming replicas are detected.Tests
DROP EXTENSION: all objects (including ones created directly in lolor) restored to native storage with data verification.migrate_to_native()without dropping the extension.migrate_from_nativeandmigrate_to_native.DROP EXTENSIONrejected on OID conflict, user resolves and retries successfully.