이 콘텐츠는 선택한 언어로 제공되지 않습니다.

Chapter 12. Configuring Data Grid Server Datasources


Create managed datasources to optimize connection pooling and performance for database connections.

You can specify database connection properties as part of a JDBC cache store configuration. However, you must do this for each cache definition, which duplicates configuration and wastes resources by creating multiple distinct connection pools.

By using shared, managed datasources, you centralize connection configuration and pooling for more efficient usage.

12.1. Datasource Configuration for JDBC Cache Stores

Data Grid server configuration for datasources is composed of two sections:

  • A connection factory that defines how to connect to the database.
  • A connection pool that defines how to pool and reuse connections.
<data-sources>
   <!-- Defines a unique name for the datasource, JNDI name, and enables statistics. -->
   <data-source name="ds" jndi-name="jdbc/datasource" statistics="true">
      <!-- Specifies the JDBC driver that creates connections. -->
      <connection-factory driver="org.database.Driver"
                          username="db_user"
                          password="secret"
                          url="jdbc:db://database-host:10000/dbname"
                          new-connection-sql="SELECT 1"
                          transaction-isolation="READ_COMMITTED">
         <!-- Sets optional JDBC driver-specific connection properties. -->
         <connection-property name="name">value</connection-property>
      </connection-factory>
      <!-- Defines connection pool properties. -->
      <connection-pool initial-size="1"
                       max-size="10"
                       min-size="3"
                       background-validation="1000"
                       idle-removal="1"
                       blocking-timeout="1000"
                       leak-detection="10000"/>
   </data-source>
</data-sources>
Copy to Clipboard Toggle word wrap

Connection pools can be tuned using the following parameters:

  • initial-size: Initial number of connections the pool should hold.
  • max-size: Maximum number of connections in the pool.
  • min-size: Minimum number of connections the pool should hold.
  • blocking-timeout: Maximum time in milliseconds to block while waiting for a connection before throwing an exception. This will never throw an exception if creating a new connection takes an inordinately long period of time. Default is 0 meaning that a call will wait indefinitely.
  • background-validation: Time in milliseconds between background validation runs. A duration of 0 means that this feature is disabled.
  • validate-on-acquisition: Connections idle for longer than this time, specified in milliseconds, are validated before being acquired (foreground validation). A duration of 0 means that this feature is disabled.
  • idle-removal: Time in minutes a connection has to be idle before it can be removed.
  • leak-detection: Time in milliseconds a connection has to be held before a leak warning.

12.2. Using Datasources in JDBC Cache Stores

Use a shared, managed datasource in your JDBC cache store configuration instead of specifying individual connection properties for each cache definition.

Prerequisites

Create a managed datasource for JDBC cache stores in your Data Grid server configuration.

Procedure

  • Reference the JNDI name of the datasource in the JDBC cache store configuration of your cache configuration, as in the following example:
<distributed-cache-configuration name="persistent-cache" xmlns:jdbc="urn:infinispan:config:store:jdbc:12.1">
    <persistence>
        <jdbc:string-keyed-jdbc-store>
            <!-- Specifies the JNDI name that you provided for the datasource connection in the server configuration. -->
            <jdbc:data-source jndi-url="jdbc/postgres"/>
            <jdbc:string-keyed-table drop-on-exit="true"
                          create-on-start="true"
                          prefix="TBL">
                <jdbc:id-column name="ID" type="VARCHAR(255)"/>
                <jdbc:data-column name="DATA" type="BYTEA"/>
                <jdbc:timestamp-column name="TS" type="BIGINT"/>
                <jdbc:segment-column name="S" type="INT"/>
            </jdbc:string-keyed-table>
        </jdbc:string-keyed-jdbc-store>
    </persistence>
</distributed-cache-configuration>
Copy to Clipboard Toggle word wrap

12.3. Testing Data Sources

Verify that connections to data sources are functioning correctly with the CLI.

Procedure

  1. Start the CLI.

    $ bin/cli.sh
    [disconnected]>
    Copy to Clipboard Toggle word wrap
  2. List all data sources:

    [//containers/default]> server datasource ls
    Copy to Clipboard Toggle word wrap
  3. Test a data source connection.

    [//containers/default]> server datasource test my-datasource
    Copy to Clipboard Toggle word wrap
맨 위로 이동
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2025 Red Hat