Connecting Cockroach DB with multiple ports

Hi,
I have a question on ports, since we create multiple ports for each node like 26257, 26258… when trying to establish the connection from java, do we have a specific port to call in the connection string (jdbc:postgresql://localhost:26257/testDb). If yes can anyone let me know what it is.

If not and we have to access the primary node port and if by anyway the node is down, how can i establish the connection.

Not sure if I understand you correctly but you could/should put haproxy in front of your cdb.
Haproxy will redirect your connection to one of the available cdb nodes. This will allow you to specify a front end in haproxy, which is your single connect address.
cockroach generate haproxy --host=one_of_your_cdb_hosts --port=the_corresponding_cdb_port
will generate some config for this.

So For example i created 3 nodes on three different servers
cockroach start --insecure --host=abc.com
cockroach start --insecure --store=node2 --host=cde.com --port=26258 --http-port=8081 --join=abc:26257
cockroach start --insecure --store=node3 --host=efg.com --port=26259 --http-port=8082 --join=abc:26257

cockroach gen haproxy --host=abc.com --port=26257

will generate haproxy.cfg file, and if my first server abc.com node 26257 is down by any reason… how can i access to the other nodes.

The haproxy config file will contain the ports for each of these nodes: abc.com:26257, cde.com:26258, and efg.com:26259. Point your java client at the haproxy server and it will forward your request to one of the running servers.

But why are you using different ports in the first place? As long as they’re on different machines, they should all be able to use :26257. Note that it’s not a good idea to run multiple cockroach processes on one machine (except for demo purposes), because this confuses the replica balancing algorithm and may leave you with less redundancy than expected.

Your app should connect to the listen/bind address of the haproxy. The haproxy will connect to an available node. This assumes that your haproxy is not on one of the cdb nodes.

Thank you Ben, that helped me… i was thinking to have multiple nodes on one server…but now i ll separate them.

Hi nraj13,
I also confuse if the 26257 node was down, how other node can work? as all of the nodes are joined to the 26257. What’s your solution? could you please share it to me? thank you.

WIlliam

Hi William, we will have just one port 26257, but we might have different hosts

for ex if we use jdbc driver to connect we provide multiple hosts with one port
jdbc:postgresql://abc.com,bcd.com,test.com:26257/

if one of the host is down then other two hosts should be providing the data.