# Import from PostgreSQL (Prisma ORM v7) (/docs/v7/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. Learn how to import data from an existing PostgreSQL database into Prisma Postgres Location: v7 > Prisma Postgres > Import from PostgreSQL > [!NOTE] > Moving a database from your laptop? Follow the three-step guide: [Migrate a local Postgres database to the cloud](https://www.prisma.io/docs/postgres/import-from-existing-database). This guide provides step-by-step instructions for importing data from an existing PostgreSQL database into Prisma Postgres. The migration has three steps, and the sections below follow them in order. 1. Create a new Prisma Postgres database. 2. Export your existing data via `pg_dump`. 3. Import the previously exported data into Prisma Postgres via `pg_restore`. In the third step, you will be using a [direct connection](https://www.prisma.io/docs/postgres/database/connecting-to-your-database) to securely connect to your Prisma Postgres database to run `pg_restore`. ## Prerequisites [#prerequisites] * The connection URL to your existing PostgreSQL database * A [Prisma Data Platform](https://console.prisma.io/?utm_source=docs\&utm_medium=content\&utm_content=%28index%29) account * Node.js 18+ installed * PostgreSQL CLI Tools (`pg_dump`, `pg_restore`) for creating and restoring backups > [!NOTE] > Make sure your PostgreSQL tools match the Prisma Postgres version > > Prisma Postgres runs PostgreSQL 17, so your `pg_dump` and `pg_restore` tools need to be version 17 as well. You can check your version by running `pg_dump --version` or `pg_restore --version`. ## 1. Create a new Prisma Postgres database [#1-create-a-new-prisma-postgres-database] Follow these steps to create a new Prisma Postgres database: 1. Log in to [Prisma Data Platform](https://console.prisma.io/?utm_source=docs\&utm_medium=content\&utm_content=%28index%29) and open the Console. 2. In a [workspace](https://www.prisma.io/docs/console/concepts#workspace) of your choice, click the **New project** button. 3. Type a name for your project in the **Name** field, e.g. **hello-ppg**. 4. In the **Prisma Postgres** section, click the **Get started** button. 5. In the **Region** dropdown, select the region that's closest to your current location, e.g. **US East (N. Virginia)**. 6. Click the **Create project** button. Once your database is provisioned, obtain your direct connection string: 1. Navigate to your active Prisma Postgres instance. 2. Click the **Connection Strings** tab in the project's sidenav. 3. Click the **Create connection string** button. 4. In the popup, provide a **Name** for the connection string and click **Create**. 5. Copy the connection string starting with `postgres://`, this is your direct connection string. Save the connection string, as you'll need it in step 3. ## 2. Export data from your existing database [#2-export-data-from-your-existing-database] In this step, you're going to export the data from your existing database and store it in a `.bak` file on your local machine. Make sure to have the connection URL for your existing database ready, it should be [structured](https://www.prisma.io/docs/orm/v7/reference/connection-urls) like this: ```text postgresql://USER:PASSWORD@HOST:PORT/DATABASE ``` Expand below for provider-specific instructions that help you determine the right connection string: ### Neon * Make sure to select non-pooled connection string by switching off the **Connection pooling** toggle. * The `sslmode` has to be set to `require` and appended to your Neon database URL for the command to work. * The connection URL should look similar to this: ```text postgresql://USER:PASSWORD@YOUR-NEON-HOST/DATABASE?sslmode=require ``` ### Supabase * Use a database connection URL that uses [Supavisor session mode](https://supabase.com/docs/guides/database/connecting-to-postgres#supavisor-session-mode). * The connection URL should look similar to this: ```text postgres://postgres.apbkobhfnmcqqzqeeqss:[YOUR-PASSWORD]@aws-0-ca-central-1.pooler.supabase.com:5432/postgres ``` Next, run the following command to export the data of your PostgreSQL database (replace the `__DATABASE_URL__` placeholder with your actual database connection URL): ```bash pg_dump \ -Fc \ -v \ -d __DATABASE_URL__ \ -n public \ -f db_dump.bak ``` Here's a quick overview of the CLI options that were used for this command: * `-Fc`: Uses the custom format for backups, recommended for `pg_restore` * `-v`: Runs `pg_dump` in verbose mode * `-d`: Specifies the database connection string * `-n`: Specifies the target PostgreSQL schema * `-f`: Specifies the output name for the backup file Running this command will create a backup file named `db_dump.bak` which you will use to restore the data into your Prisma Postgres database in the next step. ## 3. Import data into Prisma Postgres [#3-import-data-into-prisma-postgres] Use your [direct connection string](https://www.prisma.io/docs/postgres/database/connecting-to-your-database) to connect to your Prisma Postgres instance and import data via `pg_restore`. Your direct connection string from step 1 should look like this: ```text postgres://USER:PASSWORD@db.prisma.io:5432/?sslmode=require ``` Use the backup file from **Step 2** to restore data into your Prisma Postgres database with `pg_restore` by running this command (replace `__USER__`, `__PASSWORD__` with the values from your direct connection string): ```bash pg_restore \ -h db.prisma.io \ -p 5432 \ -U __USER__ \ -d postgres \ -v \ ./db_dump.bak \ && echo "-complete-" ``` When prompted, enter the `__PASSWORD__` from your direct connection string. You can also use the full connection string format: ```bash pg_restore \ -d "postgres://USER:PASSWORD@db.prisma.io:5432/postgres?sslmode=require" \ -v \ ./db_dump.bak \ && echo "-complete-" ``` When the command completes, the data from your existing PostgreSQL database is in Prisma Postgres. To validate that the import worked, you can use [Prisma Studio](https://www.prisma.io/docs/guides/postgres/viewing-data#viewing-and-editing-data-in-prisma-studio). Either open it in the [Platform Console](https://console.prisma.io/?utm_source=docs\&utm_medium=content\&utm_content=%28index%29) by clicking the **Studio** tab in the left-hand sidenav in your project or run this command to launch Prisma Studio locally: #### bun ```bash bunx prisma studio ``` #### pnpm ```bash pnpm prisma studio ``` #### yarn ```bash yarn prisma studio ``` #### npm ```bash npx prisma studio ``` ## 4. Update your application code to query Prisma Postgres [#4-update-your-application-code-to-query-prisma-postgres] ### Scenario A: You are already using Prisma ORM [#scenario-a-you-are-already-using-prisma-orm] If you're already using Prisma ORM, you need to update your database connection URL to point to your new Prisma Postgres instance. Update the `DATABASE_URL` in your `.env` file to match your Prisma Postgres direct connection string from step 1: ```text title=".env" DATABASE_URL="postgres://USER:PASSWORD@db.prisma.io:5432/?sslmode=require" ``` Then, re-generate Prisma Client so that the updated environment variable takes effect: #### bun ```bash bunx prisma generate ``` #### pnpm ```bash pnpm prisma generate ``` #### yarn ```bash yarn prisma generate ``` #### npm ```bash npx prisma generate ``` Once this is done, you can run your application and it should work as before. > [!NOTE] > For a complete guide on setting up Prisma ORM with Prisma Postgres from scratch, including driver adapter configuration and best practices, see the [Prisma ORM with Prisma Postgres quickstart](https://www.prisma.io/docs/v7/prisma-orm/quickstart/prisma-postgres). ### Scenario B: You are not yet using Prisma ORM [#scenario-b-you-are-not-yet-using-prisma-orm] If you are not yet using Prisma ORM, you'll need to go through the following steps to use Prisma Postgres from your application: 1. Install the Prisma CLI and other required dependencies in your project 2. Introspect the database to generate a Prisma schema 3. Generate Prisma Client 4. Update the queries in your application to use Prisma ORM You can find the detailed step-by-step instructions for this process in this guide: [Add Prisma ORM to an existing project](https://www.prisma.io/docs/v7/prisma-orm/add-to-existing-project/prisma-postgres). ## Related pages - [`From the CLI`](https://www.prisma.io/docs/v7/prisma-postgres/from-the-cli): Start building a Prisma application with a Prisma Postgres database from the CLI - [`Import from MySQL`](https://www.prisma.io/docs/v7/prisma-postgres/import-from-existing-database-mysql): Learn how to import data from an existing MySQL database into Prisma Postgres