bea.com | products | dev2dev | support | askBEA |
|
e-docs > WebLogic Server > Administration Console Online Help > JDBC Connection Pools |
Administration Console Online Help |
Configuring JDBC Connection Pools
A connection pool contains a group of JDBC connections that are created when the connection pool is registered—when starting up WebLogic Server or when deploying the connection pool to a target server or cluster. Connection pools use a JDBC driver to create physical database connections. Your application borrows a connection from the pool, uses it, then returns it to the pool by closing it.
Figure 11-1 Connection Pool Architecture
All of the settings you make with the Administration Console are static; that is, all settings persist even after you stop and restart WebLogic Server. You can create dynamic connection pools—those that you expect to use and delete while the server is running—using the command line (see Commands for Managing JDBC Connection Pools in the WebLogic Server Command Reference at ../admin_ref/cli.html#jdbc) or programmatically using the API (see Creating a Connection Pool Dynamically in Programming WebLogic JDBC).
Connection pool settings are persisted in the config.xml file, including settings for dynamically created connection pools (until you programmatically delete the connection pool). For information about entries in the config.xml file, see the JDBCConnectionPool section of the Configuration Reference Guide.
Using the JDBC Connection Pool Assistant
You use the JDBC Connection Pool Assistant to create JDBC connection pools. The JDBC Connection Pool Assistant helps you create and deploy a connection pool by prompting you for database and driver information and then constructing the connection attributes required by your JDBC driver, such as the driver class name and the database URL.
Notes: JDBC drivers listed in the JDBC Connection Pool Assistant are not necessarily certified for use with WebLogic Server. In keeping with the goal of the JDBC Connection Pool Assistant, JDBC drivers are listed as a convenience to help you create a connection to many of the database management systems available.
You must install JDBC drivers in order to use them to create database connections in a connection pool. Drivers are listed in the JDBC Connection Pool Assistant with known required configuration options to help you configure a connection pool. The JDBC drivers in the list are not necessarily installed. Driver installation can include setting system Path, Classpath, and other environment variables.
When a JDBC driver is updated, configuration requirements may change. The JDBC Connection Pool Assistant uses known configuration requirements at the time the WebLogic Server software was released. If configuration options for your JDBC driver have changed, you may need to manually override the configuration options displayed in Step 3 of the JDBC Connection Pool Assistant or in the property pages for the connection pool.
Creating and Configuring a JDBC Connection Pool
Note: You must install JDBC drivers in order to use them to create database connections in a connection pool. Drivers are listed in the JDBC Assistant with known required configuration options to help you configure a connection pool. Driver installation also includes setting system Path, Classpath, and other environment variables.
If the test is successful, Step 4 - Create and deploy is displayed. If the test is unsuccessful, an error message is displayed at the top of the page. Check the values on the page and correct any errors, then test the connection again.
You can click Skip this Step to skip the test and continue configuring the connection pool. Note that if you create and deploy a connection pool with errors, the connection pool configuration will be created, but the connection pool will not actually be deployed to servers or clusters. Also, when you restart servers, the servers will start with errors.
In most cases, you should create a data source to use with a connection pool. To create a data source, see Creating and Configuring a JDBC Data Source.
Database Passwords in Connection Pool Configuration
When you create a connection pool, you typically include at least one password to connect to the database. If you use an open string to enable XA, you may use two passwords. You can enter the passwords as a name-value pair in the Properties field or you can enter them in their respective fields:
openString=Oracle_XA+Acc=P/userName/+SesTm=177+DB=demoPool+Threads=true=Sqlnet=dvi0+logDir=.
If you specify a password in the Properties field when you first configure the connection pool, WebLogic Server removes the password from the Properties string and sets the value as the Password value in an encrypted form the next time you start WebLogic Server. If there is already a value for the Password attribute for the connection pool, WebLogic Server does not change any values. However, the value for the Password attribute overrides the password value in the Properties string. The same behavior applies to any password that you define as part of an open string. For example, if you include the following properties when you first configure a connection pool:
user=scott;
password=tiger;
openString=Oracle_XA+Acc=p/scott/tiger+SesTm=177+db=jtaXaPool+Threads=true+Sqlnet=lcs817+logDir=.+dbgFl=0x15;server=lcs817
The next time you start WebLogic Server, it moves the database password and the password included in the open string to the Password and Open String Password attributes, respectively, and the following value remains for the Properties field:
user=scott;
openString=Oracle_XA+Acc=p/scott/+SesTm=177+db=jtaXaPool+Threads=true+Sqlnet=lcs817+logDir=.+dbgFl=0x15;server=lcs817
After a value is established for the Password or Open String Password attributes, the values in these attributes override the respective values in the Properties attribute. That is, continuing with the previous example, if you specify tiger2 as the database password in the Properties attribute, WebLogic Server ignores the value and continues to use tiger as the database password, which is the current encrypted value of the Password attribute. To change the database password, you must change the Password attribute.
Note: The value for Password and Open String Password do not need to be the same.
Cloning a JDBC Connection Pool
Deploying a JDBC Connection Pool to One or More Servers or Clusters
When deploying a JDBC connection pool on a cluster, in most cases you should deploy the connection pool to the entire cluster. You should deploy the related data source to the same targets.
Testing a JDBC Connection Pool
On the JDBC Connection Pool
When you test a connection pool, WebLogic Server reserves and releases a connection from the connection pool.
To make the test more meaningful, make sure that Test Reserved Connections or Test Released Connections is selected on the Configuration
To see a description of the information displayed on the JDBC connection Pool
To test a connection in a connection pool, follow these steps:
Configuring the Statement Cache for a JDBC Connection Pool
On the JDBC Connection Pool
See Statement Cache Algorithms for more information.
Adding a Note to a JDBC Connection Pool
Application-Scoped JDBC Connection Pools
When you package your enterprise applications, you can include the weblogic-application.xml supplemental deployment descriptor, which you use to configure application scoping. Within the weblogic-application.xml file, you can configure JDBC connection pools that are created when you deploy the enterprise application.
An instance of the connection pool is created with each instance of your application. This means an instance of the pool is created with the application on each node that the application is targeted to. It is important to keep this in mind when considering pool sizing.
Connection pools created in this manner are known as application-scoped connection pools, app scoped pools, application local pools, app local pools, or local pools, and are scoped for the enterprise application only. That is, they are isolated for use by the enterprise application.
For more information about application scoping and application scoped resources, see:
Connection Pool and Data Source Configuration Guidelines
Drivers Supported for Local Transactions
JDBC 2.0 drivers that support the JDBC Core 2.0 API (java.sql), such as the WebLogic jDriver for Oracle. The API allows you to create the class objects necessary to establish a connection with a data source, send queries and update statements to the data source, and process the results.
Drivers Supported for Distributed Transactions Using XA
Any JDBC driver that supports JDBC 2.0 distributed transactions standard extension interfaces (javax.sql.XADataSource, javax.sql.XAConnection, javax.transaction.xa.XAResource), such as the WebLogic jDriver for Oracle/XA.
Drivers Supported for Distributed Transactions without XA
Any JDBC driver that supports JDBC 2.0 Core API but does not support JDBC 2.0 distributed transactions standard extension interfaces (non-XA). Only one non-XA JDBC driver can participate in a distributed transaction. See Configuring Non-XA JDBC Drivers for Distributed Transactions
Configuring JDBC Drivers for Local Transactions
To configure JDBC drivers for local transactions, set up the JDBC connection pool as follows:
For more information on WebLogic two-tier JDBC drivers, refer to the BEA documentation for the specific driver you are using: Using WebLogic jDriver for Oracle and Using WebLogic jDriver for Microsoft SQL Server. If you are using a third-party driver, refer to Using Third-Party JDBC XA Drivers with WebLogic Server in Programming WebLogic JTA and the vendor-specific documentation. The following tables show sample JDBC connection pool and Data Source configurations using the WebLogic jDrivers.
The following table shows a sample connection pool configuration using the WebLogic jDriver for Oracle.
Note: The following configuration examples use a Password attribute. The Password attribute value overrides any password defined in Properties (as a name/value pair). This attribute is passed to the 2-tier JDBC driver when creating physical database connections. The value is stored in an encrypted form in the config.xml file and can be used to avoid storing passwords in clear text in that file.
General Tab (JDBC Connection Pool --> Configuration --> General) |
|
tiger (This value overrides any password defined in Properties as a name value pair) |
|
Connections Tab (JDBC Connection Pool --> Configuration --> Connections) |
|
Target and Deploy (JDBC Connection Pool --> Target and Deploy) |
|
The following table shows a sample Data Source configuration using the WebLogic jDriver for Oracle.
Configuration Tab (JDBC Data Source --> Configuration) |
|
Target and Deploy Tab (JDBC Data Source --> Target and Deploy) |
|
The following table shows a sample connection pool configuration using the IBM Informix JDBC Driver.
General Tab (JDBC Connection Pool --> Configuration --> General) |
|
Connections Tab (JDBC Connection Pool --> Configuration --> Connections) |
|
Target and Deploy (JDBC Connection Pool --> Target and Deploy) |
|
Configuring XA JDBC Drivers for Distributed Transactions
To allow XA JDBC drivers to participate in distributed transactions, configure the JDBC connection pool as follows:
The following table shows an example of a JDBC connection pool configuration using the WebLogic jDriver for Oracle in XA mode.
General Tab (JDBC Connection Pool --> Configuration --> General) |
|
tiger (This value overrides any password defined in Properties as a name value pair) |
|
Connections Tab (JDBC Connection Pool --> Configuration --> Connections) |
|
Target and Deploy (JDBC Connection Pool --> Target and Deploy) |
|
The following table shows an example of a Tx Data Source configuration using the WebLogic jDriver for Oracle in XA mode.
Configuration Tab (JDBC Data Source --> Configuration) |
|
Target and Deploy Tab (JDBC Data Source --> Target and Deploy) |
|
You can also configure the JDBC connection pool to use a third-party vendor's driver in XA mode. In such cases, the data source properties are set via reflection on the XADataSource instance using the JavaBeans design pattern. In other words, for property abc, the XADataSource instance must support get and set methods with the names getAbc and setAbc, respectively.
The following attributes are an example of a JDBC connection pool configuration using the Oracle Thin Driver.
General Tab (JDBC Connection Pool --> Configuration --> General) |
|
tiger (This value overrides any password defined in Properties as a name value pair) |
|
Connections Tab (JDBC Connection Pool --> Configuration --> Connections) |
|
Target and Deploy (JDBC Connection Pool --> Target and Deploy) |
|
The following table shows an example of a Tx Data Source configuration using the Oracle Thin Driver.
Configuration Tab (JDBC Data Source --> Configuration) |
|
Target and Deploy Tab (JDBC Data Source --> Target and Deploy) |
|
The following table shows an example of a JDBC connection pool configuration for distributed transactions using the PointBase JDBC driver.
General Tab (JDBC Connection Pool --> Configuration --> General) |
|
Connections Tab (JDBC Connection Pool --> Configuration --> Connections) |
|
Target and Deploy (JDBC Connection Pool --> Target and Deploy) |
|
Configure the Tx Data Source for use with a PointBase driver as follows.
Configuration Tab (JDBC Data Source --> Configuration) |
|
Target and Deploy Tab (JDBC Data Source --> Target and Deploy) |
|
WebLogic jDriver for Oracle/XA Data Source Properties
Table 11-10 lists the data source properties supported by the WebLogic jDriver for Oracle. The JDBC 2.0 column indicates whether a specific data source property is a JDBC 2.0 standard data source property (S) or a WebLogic Server extension to JDBC (E).
The Optional column indicates whether a particular data source property is optional or not. Properties marked with Y* are mapped to the corresponding fields of the Oracle xa_open string (value of the openString property) as listed in Table 11-10. If they are not specified, their default values are taken from the openString property. If they are specified, their values should match those specified in the openString property. If the properties do not match, a SQLException is thrown when you attempt to make an XA connection.
Mandatory properties marked with N* are also mapped to the corresponding fields of the Oracle xa_open string. Specify these properties when specifying the Oracle xa_open string. If they are not specified or if they are specified but do not match, an SQLException is thrown when you attempt to make an XA connection.
Property Names marked with ** are supported but not used by WebLogic Server.
Table 11-11 lists the mapping between Oracle's xa_open string fields and data source properties.
Note: You must specify Threads=true in Oracle's xa_open string.
For a complete description of Oracle's xa_open string fields, see your Oracle documentation.
Additional XA Connection Pool Properties
When using connections from a connection pool in distributed transactions, you may need to set additional properties for the connection pool so that the connection pool handles the connection properly within WebLogic Server in the context of the transaction. You set these properties in the configuration file (config.xml) within the JDBCConnectionPool tag. By default, all additional properties are set to false. You set the properties to true to enable them.
In many cases, WebLogic Server automatically sets the proper value for these properties internally so that you do not have to set them manually.
Some DBMSs require that you start and end a transaction in the same physical database connection. In some cases, a transaction in WebLogic Server may start in one physical database connection and end in another physical database connection. To force a connection pool to reserve a physical connection and provide the same connection to an application throughout transaction processing until the transaction is complete, you set KeepXAConnTillTxComplete="true". For example:
<JDBCConnectionPool KeepXAConnTillTxComplete="true" DriverName="com.sybase.jdbc2.jdbc.SybXADataSource" CapacityIncrement="5" InitialCapacity="10" MaxCapacity="25" Name="demoXAPool" Password="{3DES}vIF8diu4H0QmdfOipd4dWA==" Properties="User=dbuser;DatabaseName=dbname;ServerName=server_name_or_IP_address;PortNumber=serverPortNumber;NetworkProtocol=Tds;resourceManagerName=Lrm_name_in_xa_config;resourceManagerType=2" />
Note: This property is required to support distributed transactions with DB2 and Sybase.
Configuring Non-XA JDBC Drivers for Distributed Transactions
When configuring the JDBC connection pool to allow non-XA JDBC drivers to participate with other resources in distributed transactions, select the Emulate Two-Phase Commit for non-XA Driver attribute (EnableTwoPhaseCommit in the JDBCTxDataSource MBean) for the JDBC Tx Data Source. This parameter is ignored by resources that support the XAResource interface. Note that only one non-XA connection pool may participate in a distributed transaction. See Emulating Two-Phase Commit for more information.
Note: There are risks to data integrity when using the Emulate Two-Phase Commit for non-XA Driver option. BEA recommends that you use an XA-compliant JDBC driver rather than use this option. Make sure you consider the risks below before enabling this option. See Limitations and Risks.
If you are using only one non-XA driver and it is the only resource in the transaction, leave the Emulate Two-Phase Commit for non-XA Driver option unselected in the Console (accept the default EnableTwoPhaseCommit = false). In this case, the Transaction Manager performs a one-phase optimization.
Non-XA Driver/Multiple Resources
If you are using one non-XA JDBC driver with other XA resources, select Emulate Two-Phase Commit in the Administration Console (EnableTwoPhaseCommit = true).
When the Emulate Two-Phase Commit for non-XA Driver option is selected (EnableTwoPhaseCommit is set to true), the non-XA JDBC resource always returns XA_OK during the XAResource.prepare() method call. The resource attempts to commit or roll back its local transaction in response to subsequent XAResource.commit() or XAResource.rollback() calls. If the resource commit or rollback fails, a heuristic error results. Application data may be left in an inconsistent state as a result of a heuristic failure.
When the Emulate Two-Phase Commit for non-XA Driver option is not selected in the Console (EnableTwoPhaseCommit is set to false), the non-XA JDBC resource causes XAResource.prepare() to fail. This mechanism ensures that there is only one participant in the transaction, as commit() throws a SystemException in this case. When there is only one resource participating in a transaction, the one phase optimization bypasses XAResource.prepare(), and the transaction commits successfully in most instances.
The following table shows configuration attributes for a sample JDBC connection pool using a non-XA JDBC driver.
General Tab (JDBC Connection Pool --> Configuration --> General) |
|
tiger (Displayed as ***** when typed, hidden thereafter; this value overrides any password defined in Properties as a name value pair) |
|
Connections Tab (JDBC Connection Pool --> Configuration --> Connections) |
|
Target and Deploy (JDBC Connection Pool --> Target and Deploy) |
|
The following table shows configuration attributes for a sample Tx Data Source using a non-XA JDBC driver.
Configuration Tab (JDBC Data Source --> Configuration) |
|
Target and Deploy Tab (JDBC Data Source --> Target and Deploy) |
|
Security for JDBC Connection Pools
You can optionally restrict access to JDBC connection pools. In WebLogic Server, security policies answer the question "who has access" to a WebLogic resource. A security policy is created when you define an association between a WebLogic resource and a user, group, or role. A WebLogic resource has no protection until you assign it a security policy. For instructions on how to set up security for all WebLogic Server resources, see Protecting WebLogic Resources.
Managing JDBC Connection Pools
From the JDBC Connection Pool property tabs in the Administration Console, you can manage the connections pools in your domain. The following sections provide detailed instructions for manually performing management tasks on JDBC connection pools.
Resetting All Connections in a JDBC Connection Pool
When you reset a connection pool, WebLogic Server shuts down and recreates all database connections in the connection pool.
Shrinking a JDBC Connection Pool
If you configure a connection pool so that it can add database connections as demand for connections increases, you can click the Shrink button on the Control tab to manually shrink the connection pool. When you shrink a connection pool, WebLogic Server reduces the number of connections in the pool to the greater of either the initial capacity or the number of connections currently in use.
Suspending a JDBC Connection Pool
When you suspend a connection pool, you make the connections in the pool unavailable for applications to use. WebLogic Server provides the following options for suspending a connection pool:
Connections is a suspended connection pool remain intact. The connections are not recreated when you resume the connection pool.
To suspend a connection pool, follow these steps:
Resuming a JDBC Connection Pool
After manually suspending a connection pool, you can re-enable it by clicking Resume on the JDBC Connection Pool
Shutting Down a JDBC Connection Pool
To shut down an instance of a connection pool, you can un-deploy the connection pool on the server. This operation closes all physical database connections in the connection pool. To shut down the connection pool on more than on target, you must un-deploy on each deployment target.
See the following related information:
Restarting a JDBC Connection Pool
To restart a connection pool after shutting it down by undeploying it (see Shutting Down a JDBC Connection Pool), you re-deploy the connection pool to servers and clusters. See Deploying a JDBC Connection Pool to One or More Servers or Clusters for instructions.
Destroying or Deleting a JDBC Connection Pool
When you destroy a JDBC connection pool, all database connections in all instances of the connection pool are closed and the connection pool configuration is removed from the domain.
Note: When you destroy a connection pool, you destroy all instances of the connection pool, not just the instance for which you clicked the Destroy button.
There are two Destroy options for connection pools in WebLogic Server:
To destroy a connection pool, follow these steps:
Clearing the Statement Cache for a JDBC Connection Pool
To clear the statement cache for all connections in a connection pool, follow these steps:
For more information about the statement cache for a connection pool, see Increasing Performance with the Statement Cache.
Monitoring a JDBC Connection Pool
Monitoring Connections in a JDBC Connection Pool
For details about the information displayed, see JDBC Connection Pool --> Monitoring.
By properly configuring connection pools in your WebLogic Server domain, you can improve application and system performance.
Increasing Performance with the Statement Cache
When you use a prepared statement or callable statement in an application or EJB, there is considerable processing overhead for the communication between the application server and the database server and on the database server itself. To minimize the processing costs, WebLogic Server can cache statements used in your applications. When an application or EJB calls any of the statements stored in the cache, WebLogic Server reuses the statement stored in the cache. Reusing statements reduces CPU usage on the database server, improving performance for the current statement and leaving CPU cycles for other tasks.
Each connection in a connection pool has its own individual cache of prepared and callable statements used on the connection. However, you configure statement cache options per connection pool. That is, the statement cache for each connection in a connection pool uses the statement cache options specified for the connection pool. Statement cache configuration options include:
You can use the following methods to set statement cache options for a connection pool:
To set the prepared statement cache size for a connection pool using the configuration file, before starting the server, open the config.xml file in an editor, then add an entry for the PreparedStatementCacheSize attribute in the JDBCConnectionPool tag. For example:
<JDBCConnectionPool CapacityIncrement="5"
DriverName="com.pointbase.jdbc.jdbcUniversalDriver"
InitialCapacity="5" MaxCapacity="20" Name="demoPool"
Password="{3DES}ANfMduXgaaGMeS8+CR1xoA=="
PreparedStatementCacheSize="10" StatementCacheType="LRU"
Properties="user=examples"
RefreshMinutes="0" ShrinkPeriodMinutes="15"
ShrinkingEnabled="true" Targets="examplesServer"
TestConnectionsOnRelease="false"
TestConnectionsOnReserve="false"
URL="jdbc:pointbase:server://localhost/demo"/>
You can also manually clear the statement cache for a connection pool. See Clearing the Statement Cache for a JDBC Connection Pool.
The Statement Cache Type (or algorithm) determines which prepared and callable statements to store in the cache for each connection in a connection pool. You can choose from the following options:
When you select LRU (Least Recently Used, the default) as the Statement Cache Type, WebLogic Server caches prepared and callable statements used on the connection until the statement cache size is reached. When an application calls connection.prepare statement, WebLogic Server checks to see if the statement is stored in the statement cache. If so, WebLogic Server returns the cached statement (if it is not already being used). If the statement is not in the cache, and the cache is full (number of statements in the cache = statement cache size), Weblogic Server determines which existing statement in the cache was the least recently used and replaces that statement in the cache with the new statement.
The LRU statement cache algorithm in WebLogic Server uses an approximate LRU scheme.
When you select FIXED as the Statement Cache Type, WebLogic Server caches prepared and callable statements used on the connection until the statement cache size is reached. When additional statements are used, they are not cached.
With this statement cache algorithm, you can inadvertently cache statements that are rarely used. In many cases, the LRU algorithm is preferred because rarely used statements will eventually be replaced in the cache with frequently used statements.
The Statement Cache Size attribute determines the total number of prepared and callable statements to cache for each connection in each instance of the connection pool. By caching statements, you can increase your system performance. However, you must consider how your DBMS handles open prepared and callable statements. In many cases, the DBMS will maintain a cursor for each open statement. This applies to prepared and callable statements in the statement cache. If you cache too many statements, you may exceed the limit of open cursors on your database server.
For example, if you have a connection pool with 10 connections deployed on 2 servers, if you set the Statement Cache Size to 10 (the default), you may open 200 (10 x 2 x 10) cursors on your database server for the cached statements.
Usage Restrictions for the Statement Cache
Using the statement cache can dramatically increase performance, but you must consider its limitations before you decide to use it. Please note the following restrictions when using the prepared statement cache.
There may be other issues related to caching statements that are not listed here. If you see errors in your system related to prepared or callable statements, you should set the prepared statement cache size to 0, which turns off prepared statement caching, to test if the problem is caused by caching prepared statements.
Calling a Stored Statement After a Database Change May Cause Errors
Prepared statements stored in the cache refer to specific database objects at the time the prepared statement is cached. If you perform any DDL (data definition language) operations on database objects referenced in prepared statements stored in the cache, the statements may fail the next time you run them. For example, if you cache a statement such as select * from emp and then drop and recreate the emp table, the next time you run the cached statement, the statement may fail because the exact emp table that existed when the statement was prepared, no longer exists.
Likewise, prepared statements are bound to the data type for each column in a table in the database at the time the prepared statement is cached. If you add, delete, or rearrange columns in a table, prepared statements stored in the cache are likely to fail when run again.
These limitations depend on the behavior of your DBMS.
Using setNull In a Prepared Statement
When using the WebLogic jDriver for Oracle to connect to the database, if you cache a prepared statement that uses a setNull bind variable, you must set the variable to the proper data type. If you use a generic data type, as in the following example, the statement may fail when it runs with a value other than null.
java.sql.Types.Long sal=null
.
.
.
if (sal == null)
setNull(2,int)//This is incorrect
else
setLong(2,sal)
if (sal == null)
setNull(2,long)//This is correct
else
setLong(2,sal)
This issue occurs consistently when using the WebLogic jDriver for Oracle. It may occur when using other JDBC drivers.
Statements in the Cache May Reserve Database Cursors
When WebLogic Server caches a prepared or callable statement, the statement may open a cursor in the database. If you cache too many statements, you may exceed the limit of open cursors for a connection. To avoid exceeding the limit of open cursors for a connection, you can change the limit in your database management system or you can reduce the prepared statement cache size for the connection pool.