# Import from PostgreSQL (/docs/next/prisma-postgres/import-from-existing-database-postgresql)

> For the complete Prisma documentation index, see [llms.txt](https://www.prisma.io/docs/llms.txt). A markdown version of any docs page is available by appending `.md` to its URL.

Import an existing PostgreSQL database into Prisma Postgres, then use it with Prisma Next.

Location: Next > Prisma Postgres > Import from PostgreSQL

Move an existing PostgreSQL database into Prisma Postgres, then connect Prisma Next to it.

## Prerequisites [#prerequisites]

You need:

* the connection URL for the PostgreSQL database you are importing from
* a Prisma Data Platform account
* PostgreSQL 17 CLI tools, including `pg_dump` and `pg_restore`
* Node.js 24 or newer

## 1. Create a Prisma Postgres database [#1-create-a-prisma-postgres-database]

Create a Prisma Postgres database from Console or with the CLI. Copy the direct connection string; you will use it for the restore and for `DATABASE_URL`.

## 2. Export from PostgreSQL [#2-export-from-postgresql]

Run `pg_dump` against the source database:

```shell
pg_dump -Fc -v -d "postgresql://USER:PASSWORD@HOST:PORT/DATABASE" -n public -f db_dump.bak
```

## 3. Restore into Prisma Postgres [#3-restore-into-prisma-postgres]

Restore the dump with the direct Prisma Postgres connection string:

```shell
pg_restore -d "postgres://USER:PASSWORD@db.prisma.io:5432/postgres?sslmode=require" -v ./db_dump.bak
```

## 4. Add Prisma Next [#4-add-prisma-next]

From your app root, initialize Prisma Next:

  

#### bun

```bash
bunx prisma-next init
```

#### pnpm

```bash
pnpm dlx prisma-next init
```

#### yarn

```bash
yarn dlx prisma-next init
```

#### npm

```bash
npx prisma-next init
```

Choose PostgreSQL, set `DATABASE_URL` to the Prisma Postgres connection string, then infer and emit the contract:

  

#### bun

```bash
bunx prisma-next contract infer --output ./prisma/contract.prisma
bunx prisma-next contract emit
bunx prisma-next db sign
```

#### pnpm

```bash
pnpm dlx prisma-next contract infer --output ./prisma/contract.prisma
pnpm dlx prisma-next contract emit
pnpm dlx prisma-next db sign
```

#### yarn

```bash
yarn dlx prisma-next contract infer --output ./prisma/contract.prisma
yarn dlx prisma-next contract emit
yarn dlx prisma-next db sign
```

#### npm

```bash
npx prisma-next contract infer --output ./prisma/contract.prisma
npx prisma-next contract emit
npx prisma-next db sign
```

## Next steps [#next-steps]

* Review the inferred contract before you rely on it in application code.
* Use the [PostgreSQL existing-project guide](https://www.prisma.io/docs/next/add-to-existing-project/postgresql) for the first Prisma Next query.
* Use the [full Prisma Postgres import guide](https://www.prisma.io/docs/prisma-postgres/import-from-existing-database-postgresql) for deeper migration details.

## Related pages

- [`From the CLI`](https://www.prisma.io/docs/next/prisma-postgres/from-the-cli): Start a Prisma Next app with Prisma Postgres from the command line.
- [`Import from MySQL`](https://www.prisma.io/docs/next/prisma-postgres/import-from-existing-database-mysql): Import an existing MySQL database into Prisma Postgres, then use it with Prisma Next.