question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for Read Replicas (Postgres, MySQL) or setting Client in read-only mode

See original GitHub issue

@matthewmueller’s update

Problem

Currently we don’t support read-replicas. This is a common need for scaling databases.

Solution

I agree with @dpetrick’s solution below.

One thing I would additionally suggest is to provide a Readonly interface that you can pass through. This Readonly interface would omit the Create, Update, Delete methods.


Does prisma2 support the ability to direct queries to master db or read-only replicas based on read/write? This is useful functionality that lots of db drivers support. Hopefully since prisma2 aims to replace the db driver, it would also have this functionality.

(User feedback)

This can be handled in various ways (the list if from the top of my mind):

  1. Not natively in Prisma, have actual read/read-write nodes in the DB natively and multiple datasource blocks and multiple generate blocks to generate read-only, read-write photon.
datasource ReadOnlyDB {
  provider = "postgresql"
  url      = "<read only DB credentials>"
}

datasource ReadWriteDB {
  provider = "postgresql"
  url      = "<read-write DB credentials>"
}

generator ReadOnlyPhoton {
  provider = "photonjs"
  datasource = "ReadOnlyDB" // API is not final
}
...
  1. Natively in Photon with a read only parameter
generator ReadOnlyPhoton {
  provider = "photonjs"
  readOnly = true // API is not final
}

Other ways are also possible.

Additional context

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:73
  • Comments:56 (18 by maintainers)

github_iconTop GitHub Comments

37reactions
dpetrickcommented, May 12, 2020

My first intuition on the subject was neither of your options, but the possibility to provide a read-only endpoint directly in the datasource, which would cause Prisma to internally either load balance or direct all read traffic to the read db. Both your options are severely limited in use:

  • Option 1) requires you to annotate models with a source… and then you suddenly need 2 annotations for read and write.

  • Option 2) would imply that the whole photon client is just throwing out write queries and just allow read queries. Seems odd to me all around, because what’s the point of having this when the approach is pretty much a glorified version of creating 2 photon clients and separating traffic on the client side.

For me, this is the most simple and intuitive version:

datasource PSQL {
  provider = "postgresql"
  url      = "<regular conn-string>"
  read-url = "<read-only conn-string>" // Or whatever we feel like naming it
}

… and Prisma handles the rest.

23reactions
bmxpikucommented, Jun 16, 2022

It would also be very convenient when using AWS Aurora ❤️

Read more comments on GitHub >

github_iconTop Results From Across the Web

Working with read replicas for Amazon RDS for PostgreSQL
PostgreSQL read replicas are read-only. Although a read replica isn't a writeable DB instance, you can promote it to become a standalone RDS...
Read more >
Read queries on replicas - Azure SQL Database & SQL ...
Azure SQL provides the ability to use the capacity of read-only replicas for read workloads, called Read Scale-Out.
Read more >
AWS RDS Read Replicas - Jayendra's Cloud Certification Blog
Supported for MySQL, PostgreSQL, MariaDB, and Oracle. · Not supported for SQL Server · Cross-Region Read Replicas help to improve · A source...
Read more >
Resource: aws_db_instance - hashicorp - Terraform Registry
replica_mode - (Optional) Specifies whether the replica is in either mounted or open-read-only mode. This attribute is only supported by Oracle instances.
Read more >
AWS RDS - Cross-Region Read Replicas for MySQL
AWS RDS : Cross-Region Read Replicas for MySQL and Snapshots for PostgreSQL · Migration Between Regions: The replica could be used for the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found