1

In the PostgreSQL documentation https://www.postgresql.org/docs/10/libpq-connect.html, it has been said that multiple hosts can be specified in a single connection string such that all the hosts will be tried in order one after the other until one of the server gets succeeds.

But when i tried to implement the same setting in the tag present in my ASP.net web.config file, it is throwing error as no such host name. I am using NpgSQL provider in order to connect to PostgreSQL database.

I need to add multiple server names in the connection string such that if the server#1 fails then it should try for the next server server#2 immediately provided in the order until it succeeds

Can you please suggest on how multiple hosts can be provided in the connection string?

2 Answers 2

1

The Npgsql driver does not currently support this functionality. The issue tracking this is https://github.com/npgsql/npgsql/issues/732, I'm still hoping we can get this into the next release but there's a lot going on.

Sign up to request clarification or add additional context in comments.

Comments

1

Load balancing and failover is avaialble in Npgsql version 6. At the time of writing v.6 is in preview.

Simple failover example (server2 is only used if a connection could not be established to server1):

Host=server1,server2;Username=test;Password=test

Example with load balancing (round robin I guess):

Host=server1,server2,server3,server4,server5;Username=test;Password=test;Load
Balance Hosts=true;Target Session Attributes=prefer-standby

https://www.npgsql.org/doc/failover-and-load-balancing.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.