Repository navigation
v2.4.0
Hybrid PostgreSQL Import and Data Preparation Improvements
This release introduces a new hybrid PostgreSQL direct import workflow and improves the preparation of RFB datasets for large-scale database loading.
The CNPJ DB Loader can now handle extraction, validation and sanitization while PostgreSQL performs the heavier loading and materialization steps directly from sanitized source files.
Hybrid PostgreSQL direct import
- Added
postgres generate-scriptsupport for generating PostgreSQL direct import scripts. - Added direct
psql-based loading from sanitized Receita Federal files. - Added PostgreSQL-side raw loading, staging and materialization.
- Added generation of
establishment_secondary_cnaes. - Added modular SQL scripts by phase.
- Added
import-postgres-direct.sqlas the orchestration script. - Added manifest metadata with generated steps and dependencies.
Transaction modes
Added configurable transaction strategies:
single: uses one transaction for the entire import. It is the safest option because everything is committed only at the end, but any failure requires restarting the complete run.phase: uses one transaction per generated phase. It is the recommended option for large imports because completed phases remain committed and failures are easier to isolate and rerun.none: does not wrap generated scripts in explicit transactions. It can be faster for local benchmarks or disposable databases, but failures may leave partially imported data.
Selective script generation
- Added
--includesupport for generating only selected phases. - Added
--skip-indexessupport. - Added
--skip-analyzesupport. - Added clearer
\echomessages for long-running PostgreSQL operations. - Added PostgreSQL monitoring documentation and ready-to-use SQL snippets.
Hybrid quarantine handling
- Added quarantine handling during hybrid staging validation.
- Reused the existing
import_quarantinetable and operational model. - Preserved compatibility with the Node-driven import flow.
- Added summarized logs and checkpoints for quarantined records.
Technical limitation
Because hybrid validation happens after the raw COPY step, the exact original byte offset may not always be available. In these cases, checkpoint_offset can remain NULL, and raw_line is stored as a textual JSON representation of the raw temporary row.
Federal Revenue configuration
- Added
federal-revenue config set. - Added
federal-revenue config show. - Added
federal-revenue config test. - Added
federal-revenue config reset. - Added support for configuring
share-token,webdav-urlanduser-agent.
Large ZIP and ZIP64 extraction
- Added support for large ZIP and ZIP64 archives.
- Added support for split ZIP volumes such as
.zip.001. - Added automatic detection of supported split archive entry points.
- Added safer extraction using temporary directories before replacing the final destination.
- Fixed extraction failures where valid large archives could be incorrectly reported as unsupported multi-disk ZIP files.
Sanitization encoding improvements
- Added streaming normalization from
ISO-8859-1/LATIN1to UTF-8. - Added byte-level removal of NUL characters.
- Added detection of Unicode replacement characters (
�). - Added temporary output files and safe replacement after validation.
- Added optional
--allow-replacement-charssupport for controlled manual inspection. - Preserved the existing sanitization command behavior.
Recommended flow
Download the current Receita Federal reference:
cnpj-db-loader federal-revenue download --current --output C:\ReceitaDBThen use the generated reference directory in the next steps:
cnpj-db-loader extract C:\ReceitaDB\2026-05
cnpj-db-loader validate C:\ReceitaDB\2026-05\extracted
cnpj-db-loader sanitize C:\ReceitaDB\2026-05\extracted --output C:\ReceitaDB\2026-05\sanitized --force
cnpj-db-loader postgres generate-script C:\ReceitaDB\2026-05\sanitized --output C:\ReceitaDB\2026-05\postgres-direct --source-encoding UTF8 --transaction-mode phase --force
psql -d "postgres://postgres:postgres@localhost:5432/cnpj" -f "C:\ReceitaDB\2026-05\postgres-direct\import-postgres-direct.sql"The --current flag automatically selects the current RFB reference during download.
Notes
For large imports, phase is the recommended transaction mode because it provides a practical balance between safety and recoverability.