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

support read replicas config #1241

Open
steebchen opened this issue Apr 13, 2024 · 6 comments
Open

support read replicas config #1241

steebchen opened this issue Apr 13, 2024 · 6 comments

Comments

@steebchen
Copy link
Owner

No description provided.

@nettrino
Copy link

nettrino commented Nov 8, 2024

@steebchen even without this being implemented yet, is it possible to have NewClient accept a URL and thus to have two clients active, one for the read replica and one for the write replica just by means of passing different URLs?

@steebchen
Copy link
Owner Author

I haven't tried it but it might work yeah @nettrino

@nettrino
Copy link

nettrino commented Nov 12, 2024

I think client := db.NewClient(db.WithDatasourceURL(url)) might not be properly overwriting the URL if we have a single schema with a single datasource, however I will need to double check and come back to this ticket.

Update: locally, if I have a schema with a datasource

datasource db {
    provider = "postgresql"
    url      = env("DATABASE_URL")
    schemas  = ["public", "backend"]
}

with DATABASE_URL being set to postgresql://postgres:postgres@localhost:5432/postgres?application_name=foo
and I initiate two clients within my server, one with db.NewClient() and the other client with client := db.NewClient(db.WithDatasourceURL(url)) with url being postgresql://postgres:postgres@localhost:5432/postgres?application_name=bar while the first client is also running, only one of the two shows up in the DB if I run

SELECT DISTINCT application_name
FROM pg_stat_activity
WHERE application_name IS NOT NULL;

and spin up my server - so I think this might be a bug @steebchen ?

@steebchen
Copy link
Owner Author

What happens when you initiate both with WithDatasourceURL and not set an env var outside of your application? Maybe it's overwriting it.

@nettrino
Copy link

nettrino commented Nov 19, 2024

I don't think this is doable to not set an env var at all - if I use an empty URL I get

"msg":"Error connecting prisma","error":"spawn: query engine errored: Error in data model: Diagnostics { errors: [DatamodelError { span: Span { start: 1125, end: 1127, file_id: FileId(0) }, message: \"Error validating datasource `db`: You must provide a nonempty URL\" }], warnings: [] }"}

If I do set the env var and simply initialize both with WithDatasourceURL it does not seem to work either

@nettrino
Copy link

nettrino commented Dec 2, 2024

@steebchen did you manage to replicate the above by any chance?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

No branches or pull requests

2 participants