pljava https://www.e-learn.cn/tag/pljava zh-hans Postgres pl/java caveats [closed] https://www.e-learn.cn/topic/2253015 <span>Postgres pl/java caveats [closed]</span> <span><span lang="" about="/user/109" typeof="schema:Person" property="schema:name" datatype="">試著忘記壹切</span></span> <span>2019-12-11 11:26:19</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><aside class="s-notice s-notice__info js-post-notice mb16" aria-hidden="false" role="status"><div class="grid fd-column fw-nowrap"> <div class="grid fw-nowrap"> <div class="grid--cell fl1 lh-lg"> <div class="grid--cell fl1 lh-lg"> <b>Closed</b>. This question is opinion-based. It is not currently accepting answers. </div> </div> </div> </div> <hr class="my12 outline-none baw0 bb bc-powder-2" /><div class="grid fw-nowrap fc-black-600"> <div class="grid--cell mr8"> <svg aria-hidden="true" class="svg-icon iconLightbulb" width="18" height="18" viewbox="0 0 18 18"><path d="M9.5.5a.5.5 0 0 0-1 0v.25a.5.5 0 0 0 1 0V.5zm5.6 2.1a.5.5 0 0 0-.7-.7l-.25.25a.5.5 0 0 0 .7.7l.25-.25zM1 7.5c0-.28.22-.5.5-.5H2a.5.5 0 0 1 0 1h-.5a.5.5 0 0 1-.5-.5zm14.5 0c0-.28.22-.5.5-.5h.5a.5.5 0 0 1 0 1H16a.5.5 0 0 1-.5-.5zM2.9 1.9c.2-.2.5-.2.7 0l.25.25a.5.5 0 1 1-.7.7L2.9 2.6a.5.5 0 0 1 0-.7z" fill-opacity=".4"></path><path opacity=".4" d="M7 16h4v1a1 1 0 0 1-1 1H8a1 1 0 0 1-1-1v-1z" fill="#3F3F3F"></path><path d="M15 8a6 6 0 0 1-3.5 5.46V14a1 1 0 0 1-1 1h-3a1 1 0 0 1-1-1v-.54A6 6 0 1 1 15 8zm-4.15-3.85a.5.5 0 0 0-.7.7l2 2a.5.5 0 0 0 .7-.7l-2-2z" fill="#FFC166"></path></svg></div> <div class="grid--cell lh-md"> <p class="mb0"> <b>Want to improve this question?</b> Update the question so it can be answered with facts and citations by editing this post. </p> <p class="mb0 mt6">Closed <span title="2014-06-25 13:19:47Z" class="relativetime">5 years ago</span>.</p> </div> </div> </aside><p>I would very much prefer writing DB side code in Java but would like to know if doing so has any disadvantages compared to pl/pgsql (especially performance &amp; error handling related).</p> <br /><h3>回答1:</h3><br /><p>As of my expirience pl/java has some major issues:</p> <ol><li>It's difficult to install it into a postgresql server. Even if you find binary build for your postgresql version (which is difficult too) - it needs some config and library path juggling.</li> <li>First call to java stored procedure will result in a new JVM process. JVM processes are connection-scoped and require some amount of memory for java heap, so if you use connection pool you'll end up with 10-20 JVMs started and unused most of time, consuming your server RAM</li> <li>pl/java can communicate with postgresql database using self-made JDBC driver which emulates common JDBC usage, but has some implementation issues which may surprise you. Especially if you want to use JDBC cusrors or other not-so-common things.</li> <li>pl/java logging is rather special - it's because of postgresql internal error handling implementation. For example - if you log something with java logging api at ERROR log level - it will terminate your server connection.</li> <li>pl/java has very good data processing performance compared to application-server based java logic, but it's totally unscalable - pl/java procedures are fully single-threaded - postgresql forbids multi-threaded procedures</li> <li>If you use internal JDBC driver and your SQL statement contains errors - you'll end up with cryptic error message in postgresql log - totally unrelated to real problem.</li> </ol><p>As result - you can use pl/java procedures with some success but you need to do it very carefully and probably you need to think about improving your application design.</p> <br /><br /><br /><h3>回答2:</h3><br /><p>Usually the only major difference is with round-trips. If your Java code has a low-latency connection to the DB, you should find client-side logic to perform quite well.</p> <p><em>Update</em>: Ian says you mean PL/Java, i.e in-database execution. If that's what you meant, I would <em>not</em> recommend PL/Java. It is nearly unmaintained; also, the Java model (heavy on threads, big expensive startup) isn't a great match for PostgreSQL's (processes not threads, very lightweight startup).</p> <p>It'd be great to have people committing work to PL/Java, but right now there's not much happening.</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/24406415/postgres-pl-java-caveats</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/postgresql" hreflang="zh-hans">postgresql</a></div> <div class="field--item"><a href="/tag/plpgsql" hreflang="zh-hans">plpgsql</a></div> <div class="field--item"><a href="/tag/pljava" hreflang="zh-hans">pljava</a></div> </div> </div> Wed, 11 Dec 2019 03:26:19 +0000 試著忘記壹切 2253015 at https://www.e-learn.cn