我使用tomcat7和c3p0-0.9.5.2和postgresql-9.3-1102-jdbc41,在产品Only中永远不会使用preferredTestQuery(select 1)。
相同的配置在测试环境中正常工作(使用更新查询检查)。
在产品中有很多调用getTable postgresql查询。 (> 1000cpm - New Relic数据)。
<Resource name="jdbc/database_read_only"
auth="Container"
type="com.mchange.v2.c3p0.ComboPooledDataSource"
description="Ma description"
jdbcUrl="jdbc:postgresql://hostname:5432/mabase"
driverClass="org.postgresql.Driver"
user="monuser"
password="monpassword"
initialPoolSize="10"
minPoolSize="10"
maxPoolSize="100"
acquireIncrement="10"
maxIdleTime="300"
maxConnectionAge="1800"
connectionTesterClassName="com.mchange.v2.c3p0.impl.DefaultConnectionTester"
preferredTestQuery="select 2"
testConnectionOnCheckout="true"
testConnectionOnCheckin="false"
idleConnectionTestPeriod="300"
maxIdleTimeExcessConnections="60"
unreturnedConnectionTimeout="10"
factory="org.apache.naming.factory.BeanFactory"/>
日志看起来很好:
2016-12-23 15:26:10,138 : Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 10, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, contextClassLoaderSource -> caller, dataSourceName -> ddsdsdsqd, debugUnreturnedConnectionStackTraces -> false, description -> ma description, driverClass -> org.postgresql.Driver, extensions -> {}, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, forceSynchronousCheckins -> false, forceUseNamedDriverClass -> false, identityToken -> mytoken, idleConnectionTestPeriod -> 300, initialPoolSize -> 10, jdbcUrl -> jdbc:postgresql://hostname:5432/monapp, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 1800, maxIdleTime -> 300, maxIdleTimeExcessConnections -> 60, maxPoolSize -> 100, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 10, numHelperThreads -> 3, preferredTestQuery -> select 1, privilegeSpawnedThreads -> false, properties -> {user=******, password=******}, propertyCycle -> 0, statementCacheNumDeferredCloseThreads -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> true, unreturnedConnectionTimeout -> 0, userOverrides -> {}, usesTraditionalReflectiveProxies -> false ]
为什么c3p0使用复合请求而不是&#34;选择1&#34; ?
复杂的重新抽样样本:
SELECT * FROM (SELECT n.nspname,c.relname,a.attname,a.atttypid,a.attnotnull OR (t.typtype = 'd' AND t.typnotnull) AS attnotnull,a.atttypmod,a.attlen,row_number() OVER (PARTITION BY a.attrelid ORDER BY a.attnum) AS attnum, pg_catalog.pg_get_expr(def.adbin, def.adrelid) AS adsrc,dsc.description,t.typbasetype,t.typtype FROM pg_catalog.pg_namespace
SELECT NULL AS TABLE_CAT, n.nspname AS TABLE_SCHEM, c.relname AS TABLE_NAME, CASE n.nspname ~ '^pg_' OR n.nspname = 'information_schema' WHEN true THEN CASE WHEN n.nspname = 'pg_catalog' OR n.nspname = 'information_schema' THEN CASE c.relkind WHEN 'r' THEN 'SYSTEM TABLE' WHEN 'v' THEN 'SYSTEM VIEW' WHEN 'i' THEN 'SYSTEM INDEX' ELSE NULL END WHEN n.nspname = 'pg_toast' THEN CASE c.relkind WHEN 'r' THEN 'SYSTEM TOAST TABLE' WHEN 'i' THEN 'SYSTEM TOAST INDEX' ELSE NULL END ELSE CASE c.relkind WHEN 'r' THEN 'TEMPORARY TABLE' WHEN 'i' THEN 'TEMPORARY INDEX' WHEN 'S' THEN 'TEMPORARY SEQUENCE' WHEN 'v' THEN 'TEMPORARY VIEW' ELSE NULL END END WHEN false THEN CASE c.relkind WHEN 'r' THEN 'TABLE' WHEN 'i' THEN 'INDEX' WHEN 'S' THEN 'SEQUENCE' WHEN 'v' THEN 'VIEW' WHEN 'c' THEN 'TYPE' WHEN 'f' THEN 'FOREIGN TABLE' WHEN 'm' THEN 'MATERIALIZED VIEW' ELSE NULL END ELSE NULL END AS TABLE_TYPE, d.description AS REMARKS FROM pg_catalog.pg_namespace n, pg_catalog.pg_class c LEFT JOIN pg_catalog.pg_description d ON (c.oid = d.objoid AND d.objsubid = 0) LEFT JOIN pg_catalog.pg_class dc ON (d.classoid=dc.oid AND dc.relname='pg_class') LEFT JOIN pg_catalog.pg_namespace dn ON (dn.oid=dc.relnamespace AND dn.nspname='pg_catalog') WHERE c.relnamespace = n.oid AND c.relname LIKE 'availability_table' ORDER BY TABLE_TYPE,TABLE_SCHEM,TABLE_NAME
我接受了所有的想法。
感谢
答案 0 :(得分:1)
我不认为你正在使用你认为你正在使用的东西。
c3p0-0.9.5.2针对Postgres运行的JDBC 4.1驱动程序永远不会使用旧的默认表名查询。如果没有设置AS
,它将使用INNER JOIN ON
方法。我怀疑你的应用程序的SELECT venues.venuename, venues.street, venues.city, venues.state,
venues.zip, shows.date, shows.cost, shows.ages, shows.showid
FROM venues
INNER JOIN shows
ON venues.showid = shows.showid;
中有一个旧版本的c3p0和/或Postgres JDBC。
请注意,您应该尝试追查您发布的内容,这很奇怪。您实际配置的Connection.isValid(...)
是“select 2”,而日志中DataSource的preferredTestQuery
是“select 1”。同样,您配置的CLASSPATH
为10,但在记录的配置中,它未设置(0)。您正在记录与您正在配置的DataSource类似但不相同的DataSource。
我怀疑生产中出现问题的原因是因为在您的生产环境中而不是您的测试环境中,您拥有较旧的库(c3p0和/或postgres驱动程序)以及为旧应用程序设置的其他preferredTestQuery
。
请注意preferredTestQuery
对其语义非常稳定。如果你到处升级到0.9.5.2,它不太可能损害你的旧应用程序。 (请确保包含其依赖项unreturnedConnectionTimeout
0.2.11或更高版本。)
答案 1 :(得分:0)
最后,
我改变了请求:选择1;通过一个简单的“从singleRowTable中选择值”
=&GT; Newrelic请求“从singleRowTable中选择值”是几次
=&GT;首选的工作。
详细查看请求和链接堆栈跟踪后,她来自org.springframework.jdbc.core.simple.SimpleJdbcInsert。
事实上,SimpleJdbcInsert像每个插入的原型一样使用。我将此更改为实例dao变量,metaData仅按实例请求。