I used Docker compose to create a 3 node cluster(n1,n2,n3) with replication factor 3 with one master (yb-master). I am able to access the sql query layer of these nodes through the terminal but I am not able to figure out correct url to connect to these nodes using jdbc.
“jdbc:postgresql://172.18.0.5:5433/yugabyte?user=yugabyte&password=yugabyte&ssl=true&sslmode=verify-full&sslrootcert=~/.postgresql/root.crt”
This is the url I am using where 172.18.0.5 is the ip address for my n1 node.
Hi Mayunish, this address works only within the docker-compose network. If you run the java application in the same docker-compose, this should work, but not sure if you have the right certificate. CAn you share the error message? If you access from outside of the docker network, you should use port redirection.
org.postgresql.util.PSQLException: The connection attempt failed.
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:331)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
at org.postgresql.jdbc.PgConnection.(PgConnection.java:223)
at org.postgresql.Driver.makeConnection(Driver.java:402)
at org.postgresql.Driver.connect(Driver.java:261)
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:681)
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:252)
at org.example.usersTableWrite.main(usersTableWrite.java:8)
Caused by: java.net.SocketTimeoutException: Connect timed out
at java.base/sun.nio.ch.NioSocketImpl.timedFinishConnect(NioSocketImpl.java:546)
at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:597)
at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:327)
at java.base/java.net.Socket.connect(Socket.java:633)
at org.postgresql.core.PGStream.createSocket(PGStream.java:241)
at org.postgresql.core.PGStream.(PGStream.java:98)
at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:109)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:235)
… 7 more
This is my error message. Also, can you help me with how to use port redirection if it is needed here.
To tunnel the port, here is an example: https://github.com/FranckPachot/ybdemo/blob/main/docker/yb-lab/example-docker-compose-rf3.yaml#L164
This forwards the port 5433 within the container to the 5433 on my laptop where I run docker. And then I can connect with jdbc:postgresql://localhost:5433/yugabyte