best mysql datasource properties for grails tomcat jndi -


most examples of jndi, mysql 5.6 , tomcat 7 have defined in datasource.groovy:

datasource {    pooled = true    driverclassname = "com.mysql.jdbc.driver"    dialect = 'org.hibernate.dialect.mysql5innodbdialect' } environments:    production {         datasource {         dbcreate = "update"         jndiname = "java:comp/env/mydatasourcename     } } 

and in conf/context.xml in tomcat:

<context>    <watchedresource>web-inf/web.xml</watchedresource>       <resource name="mydatasourcename" auth="container" type="javax.sql.datasource"        maxactive="100" maxidle="30" maxwait="10000"        username="root" password="password" driverclassname="com.mysql.jdbc.driver"        url="jdbc:mysql://localhost:3306/my_db_name"/>  </context>  

the question is, correct setup basic low volume production system, should reconnect if db goes down etc?

in datasource.xml hugely complex example:

    datasource {         dbcreate = "update"         //url = "jdbc:h2:proddb;mvcc=true;lock_timeout=10099;db_close_on_exit=false"         properties {            // documentation tomcat jdbc pool            // http://tomcat.apache.org/tomcat-7.0-doc/jdbc-pool.html#common_attributes            // https://tomcat.apache.org/tomcat-7.0-doc/api/org/apache/tomcat/jdbc/pool/poolconfiguration.html            jmxenabled = true            initialsize = 5            maxactive = 50            minidle = 5            maxidle = 25            maxwait = 10000            maxage = 10 * 60000            timebetweenevictionrunsmillis = 5000            minevictableidletimemillis = 60000            validationquery = "select 1"            validationquerytimeout = 3            validationinterval = 15000            testonborrow = true            testwhileidle = true            testonreturn = false            ignoreexceptiononpreload = true            // http://tomcat.apache.org/tomcat-7.0-doc/jdbc-pool.html#jdbc_interceptors            jdbcinterceptors = "connectionstate;statementcache(max=200)"            defaulttransactionisolation = java.sql.connection.transaction_read_committed // safe default            // controls leaked connections             abandonwhenpercentagefull = 100 // settings active when pool full            removeabandonedtimeout = 120000            removeabandoned = true            // use jmx console change setting @ runtime            logabandoned = false // causes stacktrace recording overhead, use debugging            /*            // jdbc driver properties            // mysql example            dbproperties {                // mysql specific driver properties                // http://dev.mysql.com/doc/connector-j/en/connector-j-reference-configuration-properties.html                // let tomcat jdbc pool handle reconnecting                autoreconnect=false                // truncation behaviour                 jdbccomplianttruncation=false                // mysql 0-date conversion                zerodatetimebehavior='converttonull'                // tomcat jdbc pool's statementcache used instead, disable mysql driver's cache                cacheprepstmts=false                cachecallablestmts=false                // tomcat jdbc pool's statementfinalizer keeps track                donttrackopenresources=true                // performance optimization: reduce number of sqlexceptions thrown in mysql driver code                holdresultsopenoverstatementclose=true                // enable mysql query cache - using server prep stmts disable query caching                useserverprepstmts=false                // metadata caching                cacheserverconfiguration=true                cacheresultsetmetadata=true                metadatacachesize=100                // timeouts tcp/ip                connecttimeout=15000                sockettimeout=120000                // timer tuning (disable)                maintaintimestats=false                enablequerytimeouts=false                // misc tuning                nodatetimestringsync=true            }            */         }     } 

now dont know 95% of parameters do, guess need them all?

what dont understand this

  1. surely tomcat pool connections, should pooled=true in grails datasource?
  2. surely tomcat handle reconnecting , validation of connection, why define validationquery = "select 1"? expecially saying "autoreconnect=false in mysql dbprperties section.
  3. could come general purpose default datasource definition suitable mysql small number of users? can tune min/max active/idle etc, not done in tomcat, not grails?
  4. "userserverprepstmts=false" why want disable prepared statements? have been drilled last 15 years ever use prepared statements otherwise db cant cache them.
  5. if ignore complex example, , went super smiple 1 posts, work properly? e.g. reconnect when db goes down , up? not leak etc.

thanks!

afaik, tomcat has nothing managing database connection. since grails 2.3.6, these recommended default datasource properties:

properties {   //see http://grails.org/doc/latest/guide/conf.html#datasource documentation    jmxenabled = true    initialsize = 5    maxactive = 50    minidle = 5    maxidle = 25    maxwait = 10000    maxage = 10 * 60000    timebetweenevictionrunsmillis = 5000    minevictableidletimemillis = 60000    validationquery = "select 1"    validationquerytimeout = 3    validationinterval = 15000    testonborrow = true    testwhileidle = true    testonreturn = false    jdbcinterceptors = "connectionstate;statementcache(max=200)"    defaulttransactionisolation = java.sql.connection.transaction_read_committed } 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -