[JAVA] JDBC URL for connecting to DB in cluster configuration

JDBC URL for connecting to a DB in a cluster configuration with spring-boot.

Oracle RAC

String DB_URL= "jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=" +
                     "(LOAD_BALANCE=OFF)(FAILOVER=ON)" +
                     "(ADDRESS=(PROTOCOL=TCP)(HOST=host1)(PORT=port1))" +
                     "(ADDRESS=(PROTOCOL=TCP)(HOST=host2)(PORT=port2)))" +
                     "(CONNECT_DATA=(SERVICE_NAME=service_name)))"

By combining the above settings of LOAD_BALANCE = ON and FAILOVER = ON, the two functions of "load balancing" and "connection failover" are enabled.

When ʻapplication.properties` is specified, describe as follows.

spring.datasource.url=jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(LOAD_BALANCE=OFF)(FAILOVER=ON)(ADDRESS=(PROTOCOL=TCP)(HOST=host1)(PORT=1521))(ADDRESS=(PROTOCOL=TCP)(HOST=host2)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=testDB)))
spring.datasource.username=user
spring.datasource.password=password

AWS Aurora DB Cluster

You can use the MariaDB JDBC driver's automatic failover feature to quickly switch between master and replica under failover conditions.

There are two ways to specify a JDBC URL: specify the Aurora DB cluster endpoint directly, or specify both the master and replica endpoints.

Cluster endpoint specification

String DB_URL = "jdbc:mariadb:aurora//auroradbcluster.auroradbtest.com::3306/testDB";

When ʻapplication.properties` is specified, describe as follows.

spring.datasource.url=jdbc:mariadb:aurora//auroradbcluster.auroradbtest.com::3306/testDB
spring.datasource.username=user
spring.datasource.password=password

Specify both master and replica endpoints

String DB_URL = "jdbc:mariadb:aurora//rds.auroradbtest.com:3306,rds-ro.auroradbtest.com:3306/testDB";

When ʻapplication.properties` is specified, describe as follows.

spring.datasource.url=jdbc:mariadb:aurora//rds.auroradbtest.com:3306,rds-ro.auroradbtest.com:3306/testDB
spring.datasource.username=user
spring.datasource.password=password

Recommended Posts

JDBC URL for connecting to DB in cluster configuration
JDBC basics ① (connecting / disconnecting to DB) Summary memorandum
[For beginners] How to debug in Eclipse
Convert to a tag to URL string in Rails
How to prevent direct URL typing in Rails
Things to watch out for in Java equals
How to implement Pagination in GraphQL (for ruby)