thelastapi
Get started free

Export Postgres tables to CSV

Export your Postgres database tables to CSV files using the vibiz CLI or API, with automatic table bundling, headers, and environment controls.

On this page 7 sections

To export Postgres tables to CSV, run vibiz export --db --csv in your terminal or request a database export with the API. This generates a compressed archive containing each table as an individual CSV file complete with header rows. You can pull data directly from your live production database or from an isolated development branch without writing custom export scripts.

Whether you need spreadsheet-ready files for reporting, a point-in-time snapshot for audits, or bulk records for an internal pipeline, the platform handles the extraction directly from your managed database.

How table exports work

When you request a CSV export, the platform inspects your Postgres schemas and creates a snapshot of your tables. Instead of forcing you to run manual COPY TO commands across dozens of tables, the system packages them into an archive named <slug>-<env>-database-csv.zip.

Inside that archive, you receive:

  • One CSV file per database table.
  • A clean header row for every file matching your column definitions.
  • All stored table rows formatted for standard spreadsheet and database ingestion tools.

These files are generated on server infrastructure and staged as temporary signed downloads. Download links remain valid for a day (24 hours). After that window passes, the signed link expires and the files are removed from temporary storage.

If you also need raw database restore scripts alongside your spreadsheets, you can pair CSV generation with standard SQL dumps. The export engine produces a <slug>-<env>-database.sql.gz snapshot containing schemas, views, triggers, and sequences that can be loaded into any Postgres instance using psql.

Export tables from the CLI

The fastest way to download your data is the vibiz export command. By passing flags, you choose whether you want code, SQL snapshots, or CSV archives.

To download only the database tables as CSV files from your current project directory:

Terminal
vibiz export --db --csv

This command connects to the project defined in your local configuration, initiates the export, waits for processing to complete, and downloads <slug>-<env>-database-csv.zip to your working directory.

You can also target a specific environment or output file location:

Terminal
# Export the production database tables to a custom archive name
vibiz export --db --csv --env production -o production-tables.zip

# Export from the isolated development branch
vibiz export --db --csv --env development -o dev-tables.zip

If you want the entire project bundle—including the source code, the setup guide, the full .sql.gz database dump, and the CSV tables—run the base command with the CSV flag:

Terminal
vibiz export --csv

To understand how projects manage isolated development databases with matching schemas, see our guide on serverless Postgres for side projects.

Export tables over the HTTP API

You can trigger and download CSV exports programmatically in backend jobs, CI workflows, or scheduled maintenance scripts. The export workflow operates in two steps: create the export job, then poll for completion.

Step 1: Start the export

Send a POST request to /v1/projects/:id/exports specifying database_csv in the include array:

Terminal
curl -X POST https://thelastapi.dev/v1/projects/prj_123/exports \
  -H "Authorization: Bearer $VIBIZ_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "include": ["database_csv"],
    "env": "production"
  }'

The API responds with status 202 Accepted and an export record:

JSON
{
  "object": "project_export",
  "id": "exp_01k947xyz",
  "environment": "production",
  "include": ["database_csv"],
  "status": "queued"
}

The include field accepts four possible values: code, database, database_csv, and env_guide. To receive both the SQL dump and individual table CSV files, pass ["database", "database_csv"].

Step 2: Check status and retrieve download URLs

Poll the export endpoint using the returned export id:

Terminal
curl https://thelastapi.dev/v1/projects/prj_123/exports/exp_01k947xyz \
  -H "Authorization: Bearer $VIBIZ_API_KEY"

Once extraction finishes, status changes to ready, and the payload lists the signed download URLs:

JSON
{
  "object": "project_export",
  "id": "exp_01k947xyz",
  "environment": "production",
  "include": ["database_csv"],
  "status": "ready",
  "files": [
    {
      "kind": "database_csv",
      "name": "acme-production-database-csv.zip",
      "size": 248910,
      "url": "https://thelastapi.dev/x/exp_01k947xyz/acme-production-database-csv.zip?expires=1793270400&signature=abc123def"
    }
  ],
  "url_expires_at": "2026-10-29T10:00:00.000Z",
  "warnings": [],
  "console_url": "https://thelastapi.dev/projects/prj_123/export?env=production&export=exp_01k947xyz"
}

The download link is self-contained and pre-signed. You can download the archive via curl or forward the URL to external systems without passing your account API key.

Permissions and environment controls

Access to export files depends on the API key permissions and the chosen environment.

CapabilityLimited KeyOwner / Full-Access Key
Development database CSV exportAllowedAllowed
Production database CSV exportRefused (403 owner_only)Allowed
Environment variables / .env downloadRefusedAllowed
CLI default environmentdevelopmentproduction

If an automated agent or CI runner using a limited key requests a production export, the platform blocks the operation with a 403 forbidden error:

JSON
{
  "error": {
    "code": "forbidden",
    "message": "Production exports require owner access or specific permissions.",
    "details": {
      "reason": "owner_only",
      "permission": "exports.production:read",
      "grant_url": "https://thelastapi.dev/keys/key_123/allow?permission=exports.production:read"
    }
  }
}

To let a service account or team member export production records without granting full account ownership, an account owner can grant the exports.production:read permission directly:

Terminal
vibiz keys access key_123 allow exports.production:read

To learn more about configuring keys and limiting access for automated tools, review the documentation on keys and environments.

Limits and large database alternatives

Before scheduling automated jobs, review the resource limits enforced on exports:

  • Concurrency: One active export per project at any given time. Starting a second export while one runs returns a 409 conflict error referencing the active export id.
  • Daily volume: A limit of 10 exports per project per day. Hitting this ceiling answers with 429 rate_limited.
  • Database size limit: Built-in exports support databases up to 2 GB uncompressed. Code exports are capped at 1 GB compressed.
  • Link lifetime: Export download links remain active for exactly 1 day before expiring.

If your database exceeds the 2 GB export ceiling, export tables individually using standard Postgres tools connected to your direct connection string.

Retrieve your database connection parameters by checking how to get a Postgres DATABASE_URL in one command. With your connection URL available, you can pipe a standard Postgres copy command straight to a local CSV file:

Terminal
psql "$DATABASE_URL" -c "\copy users TO 'users.csv' WITH (FORMAT CSV, HEADER)"

For quick data inspection or running test queries against development schemas from your terminal, see how to inspect tables and run read-only SQL from the CLI.

Web console exports

If you prefer using a browser over the command line:

  1. Open your project dashboard in the console.
  2. Navigate to the Export tab (/projects/<id>/export?env=production).
  3. Select your target environment (Production or Development).
  4. Check the database option and ensure CSV generation is selected.
  5. Click the generate button to create your signed download links.

Review the complete export documentation and database reference for technical details on schema structure and branch management.

To get started, initialize a database with vibiz init my-project --resources database or create your account at thelastapi.dev/start.

Frequently asked questions

What format are the generated table files?

Each table in your database is saved as an individual `.csv` file featuring a top header row with column names, all bundled inside a single zip archive.

How long do export download links stay valid?

Download links generated by the CLI, console, or API are pre-signed and remain active for 24 hours before expiring.

Can an automated agent export my production tables?

By default, limited API keys used by agents are restricted to development data; exporting production tables requires either a full-access owner key or the explicit `exports.production:read` permission.

What is the maximum database size supported by the export tool?

The export engine supports databases up to 2 GB; for larger datasets, connect directly with your `DATABASE_URL` and use `psql` or `pg_dump`.