Import data
CloudBase PostgreSQL can import data through DMC, SQL scripts, PostgreSQL tools, or application programs. Choose the method based on data volume, downtime window, index impact, and rollback plan.
Import methods
| Method | Use case |
|---|---|
| DMC import/export | Small data sets, development tests, manual operations |
| SQL files | Initial schemas, seed data, auditable changes |
pg_dump / pg_restore | Migration from an existing PostgreSQL database |
| Batch application scripts | Data that needs cleansing, conversion, or external API calls |
Pre-import checks
Before importing, confirm that:
- The target PostgreSQL version and extension support meet source database requirements.
- Tables, primary keys, foreign keys, unique constraints, and defaults are ready.
- RLS policies do not block writes from the import account.
- Index, trigger, and foreign key costs are acceptable for large imports.
- A rollback plan is ready, such as a backup, staging table, or repeatable script.
Import with DMC
DMC is suitable for importing CSV, SQL, and similar files, or for small development migrations. For the entry point, see DMC database management.
After importing, run sampling checks:
select count(*) from public.orders;
select * from public.orders order by created_at desc limit 10;
Initialize with SQL
For project initialization data, keep schema, indexes, extensions, and seed data in SQL files so they can be reviewed and reproduced.
begin;
create table if not exists public.categories (
id bigint generated by default as identity primary key,
name text not null unique
);
insert into public.categories (name)
values ('default')
on conflict (name) do nothing;
commit;
Migrate from PostgreSQL
When migrating from an existing PostgreSQL database, export with pg_dump and import with pg_restore or psql.
pg_dump "$SOURCE_DATABASE_URL" \
--format=custom \
--no-owner \
--file=backup.dump
pg_restore \
--dbname="$TARGET_DATABASE_URL" \
--no-owner \
--clean \
--if-exists \
backup.dump
Use --table to migrate only selected tables. Always rehearse the full migration in a staging environment before production.
Large import recommendations
- Import in batches instead of using one very large transaction.
- Evaluate whether non-essential indexes or triggers should be disabled temporarily.
- Run
analyzeafter import to update statistics. - Validate important tables with row counts, primary key ranges, and aggregate checks.
- Run during off-peak hours and keep source data until validation finishes.
analyze public.orders;
Permission checks after import
After importing, verify that normal users can only access authorized data.
select count(*)
from public.orders
where user_id is null;
If the table has RLS enabled, make sure ownership fields match the policies. For policies, see Basic permissions.