# Import and export data

Plan a data import, load records in bounded batches, and validate the result before switching applications.

Source: https://particledb.ai/guides/import-export/

## Choose a supported path

Start with your client's parameterized writes and bounded batches. For SQL bulk loading, consult [SQL commands](/sql/ddl/) and verify the format and command against your installed release before importing a large dataset.

Do not assume that a PostgreSQL export, extension or external table format can be loaded unchanged. [Migration](/operations/migration/) lists compatibility considerations.

## Prepare the destination

Define explicit column types, primary keys and constraints. Test timestamps, nulls, non-ASCII text, decimal precision and large values with a small sample first.

## Load in batches

Keep batches small enough to retry without exhausting memory. Use a transaction for each batch where supported. Record a checkpoint only after its commit succeeds.

Use stable primary keys so you can detect or reconcile records when a connection fails after a commit. Avoid constructing SQL with unescaped input.

## Validate

Compare record counts and representative values:

```sql
SELECT COUNT(*) AS records FROM work_items;
SELECT id, title, status FROM work_items ORDER BY id LIMIT 10;
```

This example uses the table from [relational data](/guides/relational-data/).

## Import CSV on the server

For a file readable by the database service account, create the destination table first:

```sql
CREATE TABLE imported_tasks (id BIGINT PRIMARY KEY, title TEXT);
```

Save this as `/var/lib/particledb/import/tasks.csv` on the database host:

```csv
id,title
1,Review request
2,Send response
```

Then import it from an authorized SQL connection:

```sql
COPY imported_tasks
FROM '/var/lib/particledb/import/tasks.csv'
WITH (FORMAT CSV, HEADER true);
SELECT id, title FROM imported_tasks ORDER BY id;
```

The result contains IDs `1` and `2` with their titles. `HEADER true` skips the header row; without it the first row is treated as data. The path is on the server, so a file on your laptop is not automatically accessible to a remote database. Use parameterized application writes when the server cannot access the source file.

## Export CSV

Choose a writable destination on the database host:

```sql
COPY imported_tasks
TO '/var/lib/particledb/import/tasks-export.csv'
(FORMAT CSV);
```

Verify the exported file before using it as an input to another system. Keep file-access privileges restricted to the service account and approved import/export directories.

## Export and recovery

A query result export is not a complete database backup: it may omit schema, indexes, privileges and function definitions. Plan export, restore and rollback separately using the [durability guide](/operations/durability/).

## Related

[Documentation home](/docs/) · [Troubleshooting](/guides/troubleshooting/)
