# A database on your machine (/docs/prisma-orm/local-database) > 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. Get a PostgreSQL or MongoDB database for a Prisma ORM project without signing up for anything, and look at the rows your app writes. Location: Prisma ORM > A database on your machine Every Prisma ORM setup page asks you for a connection string and puts it in `DATABASE_URL`. If you have no database yet, this page gives you one. For PostgreSQL, pick one of three options: a temporary hosted database with nothing to install, PostgreSQL in Docker on your machine, or, for an app made with `npm create prisma`, the database that app can start on its own. MongoDB has its own section. The last section shows how to look at the rows once your app has written some. ## A temporary database, with nothing to install [#a-temporary-database-with-nothing-to-install] `create-db` creates a [Prisma Postgres](https://www.prisma.io/docs/postgres) database, Prisma's hosted PostgreSQL, with no account and no install. It is the fastest option, and the only one on this page that runs on Prisma's servers instead of your machine. #### bun ```bash bunx create-db@latest ``` #### pnpm ```bash pnpm dlx create-db@latest ``` #### yarn ```bash yarn dlx create-db@latest ``` #### npm ```bash npx create-db@latest ``` The output has a **Connection String** line, which is the value for `DATABASE_URL`, and a **Claim Your Database** link. Put the connection string in `DATABASE_URL`. The setup pages that start from `npm create prisma` export it in the shell, and the other setup pages put it in `.env`: ```bash export DATABASE_URL="" ``` The database is deleted after 24 hours unless you claim it: open the claim link and sign in to a Prisma account, and you keep the database for free. To have it deleted sooner, set the lifetime when you create it, for example `npx create-db@latest --ttl 1h`. [create-db](https://www.prisma.io/docs/postgres/npx-create-db) lists the other options. ## PostgreSQL in Docker [#postgresql-in-docker] When you want the database on your own machine, run PostgreSQL in a container. You need Docker installed, for example [Docker Desktop](https://docs.docker.com/get-started/get-docker/); `docker compose version` tells you whether you have it. Prisma ORM 8 needs PostgreSQL 15 or newer, and the file below runs 17. Create this file in your project root: ```yml title="docker-compose.postgres.yml" services: postgres: image: postgres:17 restart: always environment: - POSTGRES_DB=postgres - POSTGRES_USER=postgres - POSTGRES_PASSWORD=prisma ports: - "127.0.0.1:5432:5432" healthcheck: test: ["CMD-SHELL", "pg_isready -U postgres -d postgres"] interval: 5s timeout: 2s retries: 20 volumes: - postgres_data:/var/lib/postgresql/data volumes: postgres_data: ``` Start it: ```bash docker compose -f docker-compose.postgres.yml up -d ``` The command returns as soon as the container is running, and the database takes a few more seconds to accept connections. `docker compose -f docker-compose.postgres.yml ps` shows `healthy` in the status column once it does. The container answers on port 5432, on this machine only, with the user `postgres`, the password `prisma`, and a database named `postgres`, so the connection string is: ```bash title=".env" DATABASE_URL="postgresql://postgres:prisma@localhost:5432/postgres" ``` The setup pages that start from `npm create prisma` read the variable from the shell, not from `.env`, so on those pages export it in the shell instead: ```bash export DATABASE_URL="postgresql://postgres:prisma@localhost:5432/postgres" ``` Unlike the hosted examples on the setup pages, this string has no `sslmode=require` at the end. Leave it off: the connection never leaves your machine. If port 5432 is already taken, for example by a PostgreSQL you installed earlier, change the middle `5432` in `127.0.0.1:5432:5432` under `ports` to another number such as `5433`, and use that number in the connection string. The data is kept in the `postgres_data` volume, so stopping and starting the container keeps your rows: ```bash docker compose -f docker-compose.postgres.yml stop docker compose -f docker-compose.postgres.yml up -d ``` To start over with an empty database, remove the container and the volume together: ```bash docker compose -f docker-compose.postgres.yml down -v ``` A PostgreSQL you installed in another way, such as with Homebrew or Postgres.app, works the same. Its connection string uses the user, password, port, and database name of that install. ## The database that comes with a new app [#the-database-that-comes-with-a-new-app] If `npm create prisma` made your app, its `package.json` has a `dev:composer` script, and the script gives you a database with nothing more to install. An app made another way does not have the script, so use Docker instead. #### bun ```bash bun run dev:composer ``` #### pnpm ```bash pnpm run dev:composer ``` #### yarn ```bash yarn dev:composer ``` #### npm ```bash npm run dev:composer ``` The script starts a PostgreSQL database on your machine, creates your tables in it by applying the migration the scaffold wrote, and starts your app. Your app needs no `DATABASE_URL` for this, the database keeps its rows from one run to the next, and `Ctrl-C` stops both. The script uses [Prisma Composer](https://www.prisma.io/docs/composer), which `npm create prisma` installed; you need not edit anything for this to work. Commands such as `npx prisma db migrate`, which applies a migration to the database, still need `DATABASE_URL` even while the script runs. Get the connection string from a second terminal in the project directory: ```bash npx prisma dev url my-app.database ``` `my-app.database` is the database's address: your app's name, then the name `module.ts` gives the database. `npm create prisma` names the app after the project directory, so replace `my-app` with yours. The command prints the connection string, and this sets `DATABASE_URL` to it in the same shell: ```bash export DATABASE_URL="$(npx prisma dev url my-app.database)" ``` `dev url` is in `prisma` since 8.0.0-rc.24, and `npx prisma --version` shows which version your project has. To empty the database, stop the script, run `npm run build`, and then run `npx prisma dev --fresh`. That deletes the database and its rows and starts the app as the script does. Stop it with `Ctrl-C` when you are done, and use `npm run dev:composer` next time. [Local development](https://www.prisma.io/docs/composer/local-development) covers running the app in the background. ## MongoDB [#mongodb] Prisma ORM 8 needs MongoDB 8.0 or newer. To run it in Docker, create this file in your project root: ```yml title="docker-compose.mongodb.yml" services: mongodb: image: mongo:8 restart: always ports: - "127.0.0.1:27017:27017" volumes: - mongodb_data:/data/db volumes: mongodb_data: ``` Start it: ```bash docker compose -f docker-compose.mongodb.yml up -d ``` The server answers on port 27017, on this machine only, with no user or password. The database name at the end of the connection string, `mydb` here, can be any name you like, and you need not create it first. ```bash title=".env" DATABASE_URL="mongodb://localhost:27017/mydb?directConnection=true" ``` The setup pages that start from `npm create prisma` read the variables from the shell, not from `.env`, and the MongoDB scaffold uses two names: the `prisma` commands read `MONGODB_URL` and the app reads `DATABASE_URL`. On those pages export both instead of writing `.env`: ```bash export MONGODB_URL="mongodb://localhost:27017/mydb?directConnection=true" export DATABASE_URL="$MONGODB_URL" ``` This is a standalone server, not a replica set. A replica set is needed only for transactions and change streams, and the setup pages use neither; if your own app uses transactions, use the Atlas option below instead. The string the MongoDB setup pages show has `replicaSet=rs0` in it, which only connects to a replica set. For this server use the string above, without it. A free [MongoDB Atlas](https://www.mongodb.com/atlas) cluster is the hosted alternative. It is a replica set already, so use the connection string Atlas shows you as it is. The same stop, start, and `down -v` commands as for PostgreSQL apply, with `docker-compose.mongodb.yml` as the file. ## Look at your rows [#look-at-your-rows] ### PostgreSQL [#postgresql] Every command here takes the connection string of whichever database you set up above, so export it in the shell first. For the Docker setup that is the string from `.env`, for the `create-db` database the string it printed, and for the database the `dev:composer` script started, the one `dev url` prints: ```bash export DATABASE_URL="postgresql://postgres:prisma@localhost:5432/postgres" ``` `psql` is the PostgreSQL command line. With it installed on your machine: ```bash psql "$DATABASE_URL" ``` With the Docker setup you need not install it, because the container has it: ```bash docker compose -f docker-compose.postgres.yml exec postgres psql -U postgres -d postgres ``` Inside `psql`, `\dt` lists your tables. A table is named after its model, or after the model's `@@map` if it has one, so the starter contract's `User` model is the `"User"` table: `\d "User"` shows its columns, and `SELECT * FROM "User";` prints its rows. The quotes matter, because PostgreSQL lowercases a name written without them. [Prisma Studio](https://www.prisma.io/docs/studio) shows your tables in the browser, and the migrations Prisma ORM has applied. Run it from the directory above your project and pass the connection string: ```bash cd .. && npx prisma@prev studio --url "$DATABASE_URL" ``` Studio works with Prisma ORM 8 databases, but it still ships with the Prisma ORM 7 command-line tool, which `prisma@prev` installs. That tool stops with an error inside a Prisma ORM 8 project, so run it from the directory above and `cd` back afterwards. Studio prints the address it serves on, usually `http://localhost:5555`. [Studio with Prisma ORM](https://www.prisma.io/docs/studio/prisma-next) explains the Migrations view, which shows what each applied migration changed. A database editor such as pgAdmin, TablePlus, DBeaver, or DataGrip asks for the parts of the connection string. For the Docker setup they are the host `localhost`, the port `5432`, the user `postgres`, the password `prisma`, the database `postgres`, and SSL off. [Viewing data](https://www.prisma.io/docs/guides/postgres/viewing-data) shows the connection dialogs of several editors. ### MongoDB [#mongodb-1] Prisma Studio does not support MongoDB. `mongosh` is the MongoDB shell, and the container has it: ```bash docker compose -f docker-compose.mongodb.yml exec mongodb mongosh mydb ``` Inside `mongosh`, `show collections` lists your collections and `db.users.find()` prints the documents in the `users` collection. A collection is named after its model, so a `Comment` model is the `Comment` collection, unless the model has `@@map`: the starter contract maps `User` to `users` and `Post` to `posts`. [MongoDB Compass](https://www.mongodb.com/products/tools/compass) is the graphical alternative; connect it to `mongodb://localhost:27017`. ## Next steps [#next-steps] * Go back to the setup page you came from: [Create a new app with PostgreSQL](https://www.prisma.io/docs/prisma-orm/quickstart/postgresql), [Create a new app with MongoDB](https://www.prisma.io/docs/prisma-orm/quickstart/mongodb), or [Add Prisma ORM and PostgreSQL to an existing app](https://www.prisma.io/docs/prisma-orm/quickstart/existing-app/postgresql). * [Deploy with Docker](https://www.prisma.io/docs/guides/deployment/docker) runs your app and PostgreSQL together in containers, with a Compose file like the one above. Its PostgreSQL port is published to the network, not only to this machine, because the app container connects to it. ## Related pages - [`create-prisma`](https://www.prisma.io/docs/prisma-orm/create-prisma): Scaffold a new Prisma ORM app with create-prisma, with Prisma Composer, Prisma Postgres, and a deploy path built in. - [`From scratch`](https://www.prisma.io/docs/prisma-orm/from-scratch): Set up Prisma ORM with PostgreSQL by hand, with one config file, one contract, and one index.ts.