Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running npx prisma introspect throws access denied error #6778

Open
enoent4400 opened this issue Apr 25, 2021 · 5 comments
Open

Running npx prisma introspect throws access denied error #6778

enoent4400 opened this issue Apr 25, 2021 · 5 comments
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. team/schema Issue for team Schema. tech/engines Issue for tech Engines. topic: introspection topic: prisma db pull CLI: prisma db pull

Comments

@enoent4400
Copy link

Bug description and reproduction

This is pretty basic example I used to experiment with Prisma introspect feature and to test it with existing DB. I'm running Postgres database inside Docker container with already defined schema. Existing model just creates one table like:

(
    id SERIAL,
    name VARCHAR(80) NOT NULL,
    PRIMARY KEY(id)
);

My docker compose looks like:

version: "3"

services:
  pg:
    image: postgres:13
    restart: "always"
    expose:
      - "5432"
    ports:
      - "5432:5432"
    environment:
      - POSTGRES_DB=prisma
      - POSTGRES_HOST_AUTH_METHOD=trust
    volumes:
      - "./db/data:/var/lib/postgresql/data"
      - "./db/init:/docker-entrypoint-initdb.d"

After you run docker compose up you will have running DB in a container locally ready to accept connections.

Run npx prisma introspect

You will get following output:

Prisma schema loaded from prisma/schema.prisma

Introspecting based on datasource defined in prisma/schema.prisma …
Error: P1010

User `postgres` was denied access on the database `postgres.public`

I tried also granting permissions to user postgres, no luck.

schema.prisma file

// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

datasource db {
  provider = "postgresql"
  url      = "postgresql://postgres@localhost:5432/prisma"
}

generator client {
  provider = "prisma-client-js"
}

Running npx prisma validate is returning ok result.

Expected behavior

It should run introspection and populate schema.prisma file. This is pretty basic example and should be pretty much covered inside the official docs.

Environment & setup

  • OS: Mac OS
  • Database: PostgreSQL
  • Node.js version: 14
  • Prisma version: 2.21.2

@janpio
Copy link
Member

janpio commented Apr 26, 2021

This really look like the user postgres does not have access to the database postgres.public.
Which is weird, as you defined the database as prisma. Hmmm...

What is the schema of that database called? If it is not public, maybe add it as ?schema=foo to your connection string please (https://www.prisma.io/docs/concepts/database-connectors/postgresql#arguments)

Can you try setting a password for the user and adding that to your connection string as well - maybe we have a bug around password less users.

@janpio janpio added bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. kind/bug A reported bug. topic: introspection labels Apr 26, 2021
@enoent4400
Copy link
Author

  1. I tried also with adding ?schema=public, same result. .
  2. I even tried with adding user and password so it's not related to passwordless users.

You can try setting basic postgres docker container with one table and try to introspect.

@pantharshit00
Copy link
Contributor

pantharshit00 commented May 16, 2021

@enoent4400 I think if you try to connect via peer authentication, then you will need to provide a unix domain socket in the connection string.

Can you try setting a password instead and try this? I use the following postgres docker config:

version: '3'
services:
  postgres:
    image: postgres
    ports:
      - 5432:5432
    restart: always
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
    volumes:
      - postgres:/var/lib/postgresql/data
volumes:
  postgres: ~

@janpio janpio added the team/schema Issue for team Schema. label May 31, 2021
@janpio janpio added the topic: prisma db pull CLI: prisma db pull label Mar 23, 2022
@janpio janpio added the tech/engines Issue for tech Engines. label Apr 2, 2022
@janpio janpio added bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. and removed bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. labels Jan 12, 2023
@janpio
Copy link
Member

janpio commented Jan 12, 2023

Internal reproduction note: Just try to introspect a database with the original Docker file.

@richardanewman
Copy link

For me it was my other local running instance of postgres. Previously I had installed postgres.app and pgadmin for another project and had it running in the background. So if you're running postgres inside docker, be sure to quit any other local postgres instances. Soon as I did that the issue went away.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. team/schema Issue for team Schema. tech/engines Issue for tech Engines. topic: introspection topic: prisma db pull CLI: prisma db pull
Projects
None yet
Development

No branches or pull requests

4 participants