Question

Should I use primary database connection string or read only connection string

Posted October 20, 2021 190 views
DatabasesDigitalOcean Managed PostgreSQL Database

Let’s say i want to scale my database for different data centers. What I need to do is to replicate the primary database and create a read-only replicate of it. And DO gives two connection strings, one is the primary and the other is read-only. Which connection string should i use for my app?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
1 answer

Hi @matthewbennett,

If you want read and write to happen to your managed database cluster you will have to use a primary database connection string.

And when a read-only node is at the different data center which is going to be used for read operations; you can use a read-only node connection string. which can offload read requests/analytics traffic from the primary database.

For more information on read-only nodes:

https://docs.digitalocean.com/products/databases/postgresql/how-to/add-read-only-nodes/

https://docs.digitalocean.com/products/databases/postgresql/#plans-and-pricing

I hope this helps!

Regards,
Rajkishore

  • if that so, technically i need to add an extra droplet server to accommodate the read-only node connection string. Is that right? or is there a way, server can detect which connection string to use based on the user’s current location.

    • Hi @matthewbennett,

      Read-only nodes are targeted at adding additional geographic locations for the managed database cluster to be used for read operations.

      From your application end, you will have to enforce which queries should be going to the primary node and which should be going to read-only nodes in a different region. This does not need to create extra droplets.

      Regards,
      Rajkishore

      • I understand that but what if I have a nodejs backend server that will serve GET responses to the users from different regions. How does the server know which are the closest nodes to be used, if I have three different read-only nodes, and all of the nodes reside on a different region?