이전에 그래왔기에 혹은 거기까지 신경쓸 여유가 없어서 그대로 둔 설정들이 있을 것이다. 담당하는 프로젝트에도 그런 것들이 있었는데, 이번에 HikariCP 설정을 변경할 일이 생겨서 JDBC 설정까지 확인해보았다.
아래는 기존에 설정되어있던 사항이다. 하나씩 확인해보자.
url: jdbc:mariadb://${DB_HOST}:3306/db?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC&tinyInt1isBit=false
autoReconnect
autoReconnect=true
- JDBC에서 제공하는 방법으로 연결이 끊어졌을 때 JDBC 드라이버가 자동으로 연결을 재시도하도록 할 수 있다. 하지만 이 경우 데이터 일관성이 틀어지는 이슈가 발생할 수 있으므로 권장되지 않는다.
Although not recommended, you can make the driver perform failovers without invalidating the activeStatement
orResultSet
instances by setting either the parameterautoReconnect
orautoReconnectForPools
totrue
. This allows the client to continue using the same object instances after a failover event, without taking any exceptional measures. This, however, may lead to unexpected results: for example, if the driver is connected to the primary host with read/write access mode and it fails-over to a secondary host in read-only mode, further attempts to issue data-changing queries will result in errors, and the client will not be aware of that. This limitation is particularly relevant when using data streaming: after the failover, theResultSet
looks to be alright, but the underlying connection may have changed already, and no backing cursor is available anymore.
useUnicode, characterEncoding
useUnicode=true&characterEncoding=UTF-8
- 예전에 유니코드 문자들을 올바로 처리하여 UTF-8로 인코딩 될 수 있도록 사용하던 설정이다.
- 하지만 최근에는 UTF-8이 기본 설정이기에 특별히 지정할 필요가 없는 설정이며, 특히나 useUnicode의 경우에는 현재는 공식 문서에서도 찾아볼 수 없는, 사용하지 않는 설정이다.
- 문자 인코딩 설정에 대한 우선 순위가 있는데, 아래 설정들이 있다면 그 우선 순위에 따라 설정되고 어느 것도 설정되어 있지 않은 경우에는 UTF-8로 설정된다.
passwordCharacterEncoding
passwordCharacterEncoding=UTF-8
- 위 내용과 마찬가지로 기본 설정이 UTF-8이므로 특별한 경우가 아니라면 다시 설정할 필요가 없다.
serverTimezone
serverTimezone=UTC
Former connection option 'serverTimezone' is still valid as an alias of this one but may be deprecated in the future.
By default, the connector adopts the JVM's default time zone. If the client and server reside in different time zones, it's recommended to configure the connection time zone to match the JVM's default by setting forceConnectionTimeZoneToSession to true. This ensures proper operation of time functions.
- 현재는 존재하지 않는 옵션명이며, connectionTimeZone으로 변경되었다.
- 기본적으로 timeZone은 서버의 시간대를 따른다. connectionTimeZone으로 시간대를 지정하려면, forceConnectionTimeZoneToSession 설정을 활성화하여야 한다.
- JVM의 시간대에 따라 timeZone을 설정하도록 하는 것이 기본 설정이기 때문에 forceConnectionTimeZoneToSession은 기본적으로 비활성화 되어 있다.
tinyInt1isBit
tinyInt1isBit=false
Datatype mapping flag, handle MySQL Tiny as BIT(boolean)-
BOOL, BOOLEAN These types are synonyms forTINYINT(1)
. A value of zero is considered false. Nonzero values are considered true:
tinyint(1)
값을 BOOLEAN으로 처리할지 여부를 결정한다. 기본값은true
로,tinyint(1)
은 BOOLEAN으로 반환된다.
- MySQL, MariaDB 등에는 Boolean 역할을 하는 Type이 없다. 그래서 tinyint(1)을 BOOLEAN으로 사용하고 있다.
- 선택의 문제이지만 사실 tinyint(2)이런 식으로 한다고 하더라도 표현 범위는 tinyint(4) 등과 동일하다. 이는 tinyint(1)을 BOOLEAN이 아니라 tinyint로 처리되도록 해도 큰 이점이 없다는 의미이다.
For integer data types,M
indicates the minimum display width. The maximum display width is 255. Display width is unrelated to the range of values a type can store, as described in Section 13.1.6, “Numeric Type Attributes”.
- 주요 데이터베이스 시스템들(MySQL, PostgreSQL, Oracle 등)에서는 정수형 타입의 저장 크기를 직접 지정하는 기능을 제공하지 않는다. 대신 미리 정의된 크기의 정수형 타입(TINYINT, SMALLINT, INT, BIGINT 등)을 사용하여 적절한 크기를 선택해야 한다.
정리
위와 같이 설정된 옵션들을 살펴보았을 때 실제로 동작하거나 설정이 꼭 필요한 옵션은 하나도 없었다. 결국 수정된 값은 다음과 같다. 각 애플리케이션의 특성에 맞춰 수정하도록 하자.
url: jdbc:mariadb://${DB_HOST}:3306/db
Share article