Before you begin: scope and permissions
- Use an approved read-only database identity with SELECT access to the scoped tables or views; account for row-level security.
- Agree a consistent snapshot strategy and operational load window with the DBA before exporting related tables.
- Approve the intended scope and use with the business owner; export access alone does not establish licensing rights.
- Use an approved encrypted working environment with restricted access and a retention deadline.
Choose between a database archive and a dataset extract
PostgreSQL stores structured records whose meaning comes from schema, relationships and application rules. A backup for restoration and a candidate AI dataset serve different purposes. A selective export can minimize sensitive fields and preserve a clear business cohort; an entire database dump may include unrelated and restricted tables.
Export a scoped CSV with psql
In an authenticated psql session, a client-side \copy writes to the local client’s filesystem. The following uses a synthetic approved view, not a table assumed to exist in your database:
BEGIN TRANSACTION ISOLATION LEVEL REPEATABLE READ READ ONLY;
\copy (SELECT record_id, created_at, body FROM dataset_release_view ORDER BY record_id) TO 'records.csv' WITH (FORMAT csv, HEADER true, ENCODING 'UTF8')
COMMIT;
Create or substitute the reviewed view through your normal database process. Keep \copy on one line in psql. PostgreSQL’s COPY documentation and psql reference distinguish server-side file access from client-side copying. Do not request elevated server file roles merely to write a local CSV.
Use pg_dump for a different purpose
The documented pg_dump utility creates a consistent database export in SQL or archive formats. It is useful for database archival, not a ready-made JSONL training dataset. Review version compatibility, selected schemas/tables and dependencies before using it. A sample archive command for a synthetic database is:
pg_dump --format=custom --no-owner --no-acl --file=archive.dump example_database
Use approved authentication without putting passwords in commands. This command can export a broad scope; for dataset work, prefer the explicitly reviewed view or query above. Even with ownership and privilege statements omitted, the archive can contain confidential data and schema.
Preserve consistency across related records
For several related CSVs, export them within a planned consistent transaction or an agreed snapshot mechanism. Long-running transactions can affect operations, so coordinate with the DBA. A child table exported after a parent changes can produce apparent orphan records. Record snapshot/cutoff evidence without exposing credentials or infrastructure secrets.
Keep primary keys, foreign keys and source types. Preserve decimal values without converting money to imprecise floats. Distinguish SQL NULL, an empty string and the literal text “NULL.” Document timestamp-with-time-zone versus timestamp-without-time-zone behavior and the chosen timezone interpretation. Do not repair missing relationships by guessing from names.
Prepare and validate a release
Retain a restricted original and a reproducible transformation pipeline. Normalize text, identify duplicates at the right business grain, and inspect JSON/array columns before flattening them. Validate uniqueness, referential integrity, permitted date ranges and content coverage. A syntactically valid CSV can still contain the wrong population.
Synthetic example: customer c-2 has tickets t-7 and t-8. Removing the customer table for privacy requires either a safe stable surrogate or explicit removal of the relationship. Do not leave an undocumented identifier that still maps to the production system.
Troubleshoot and review rights
Why is the file on the wrong machine? Server-side COPY and client-side \copy have different filesystem contexts.
Why do exported counts differ? Check transaction timing, row-level security and selection filters before changing permissions.
Database ownership does not establish rights over licensed or personal records stored inside it. Review the source application, contributing parties and proposed use. Potential tasks depend on the table semantics, trustworthy outcomes and sufficient context; raw row count alone is not evidence of commercial value. Begin any assessment with schema and coverage descriptions, not a production dump.
Release checklist
- Verify row counts, keys and foreign-key coverage from the same logical extraction scope.
- Keep schema, null conventions, timezone, encoding and type conversion rules with the files.
- Reconcile source counts and date coverage; record excluded or unavailable records.
- Validate identifiers, relationships, timestamps and field types after transformation.
- Document provenance, privacy review, third-party restrictions and the authorized release approver.
- Scan the release files for personal information, secrets and confidential material; test a reviewed sample before transfer.
Have a proprietary dataset?
Find out whether it may be suitable for AI licensing. Start with a high-level description of the source, date range, volume, rights status, and preparation work still needed.
Assess dataset readinessUse the existing buyer application when ready. Share only authorized information. Do not submit raw confidential records, credentials, or personal data in the initial assessment.
Sources & verification
Official documentation reviewed 2026-10-15. Procedures and access rules can change. These are documentation-based instructions, not a live export from your account. Verify your product version, permissions and retention settings before running a job.