Detect Slow SQL Queries With Payara Slow SQL Logger

Community
No Image

Slow SQL queries can silently undermine your application’s efficiency and the overall user experience. These sluggish queries not only frustrate users with long load times, but they can also have significant costs:

  • Reduced Productivity: Waiting for slow queries can impact efficiency and lower overall productivity within your business.
  • Increased Infrastructure Expenses: A quick fix to compensate for poor database performance is scaling hardware prematurely, which can unnecessarily increase infrastructure costs.
  • Lost Opportunities: Slow response times directly impact user experience, potentially leading to abandoned transactions and lost revenue.

Detecting and Analyzing Slow Queries

Payara Server offers the slow SQL logger feature that can help pinpoint the root cause of slow database interactions. The feature works by:

  1. Monitoring: The Slow SQL Logger keeps track of all SQL queries executed through your JDBC connection pool.
  2. Thresholding: You define a time threshold, in seconds or milliseconds. When a query exceeds this limit, it gets logged.
  3. Providing Detailed Warnings: The logger generates a warning message in the server log that contains:
    • The SQL query itself.
    • The execution time.
    • A stack trace pinpointing to the exact lines of code where the slow query originated.

Setting Up The Slow SQL Logger

You can configure the slow SQL logger on Payara Server through the following options:

  • Administration Console: Navigate to your JDBC connection pool’s “Advanced Properties” tab and set your desired ‘Slow Query Log Threshold’ time.

Asadmin Commands: Use the set command to modify the slow-query-threshold-in-seconds property of your connection pool

asadmin set domain.resources.jdbc-connection-pool.__TimerPool.slow-query-threshold-in-seconds=50

Application Deployment: If you use Jakarta EE, you can embed configuration directly within your application code using the @DataSourceDefinition annotation.

@DataSourceDefinition(

    name = "java:app/MyApp/MyDS",

    className = "org.h2.jdbcx.JdbcDataSource",

    url = "jdbc:h2:mem:test",

    properties = {"fish.payara.slow-query-threshold-in-seconds=5"})

Proactive Problem Solving

 With the Payara Server slow SQL logger, you can analyze those slow queries and target the underlying causes:

  • Database Optimization: Are your tables properly indexed? Would query restructuring improve performance?
  • Application Logic: Could you reduce the number of unnecessary queries or implement caching mechanisms within your code?

Payara Micro 

Payara Micro also supports the slow SQL logger feature. This allows you to have in-depth insights into your cloud applications and potentially reduce cost by proactively identifying slow database queries that take up precious CPU cycle times. You can activate the slow SQL logger on Payara Micro through the @DataSourceDefinition as shown above. Otherwise, you can do so through the web.xml deployment descriptor.

Don’t Let Slow SQL Queries Undermine You

By proactively detecting and analyzing slow SQL queries with Payara Server, you can safeguard your application’s performance, save on infrastructure costs, and create a smoother, more satisfying user experience. Download Payara Server Community or Payara Micro Community to get started.

Branding Tagline_Hubspot Banner-1

 

Comments (0)

Post a comment

Your email address will not be published. Required fields are marked *

Payara needs the contact information you provide to us to contact you about our products and services. You may unsubscribe from these communications at any time. For information on how to unsubscribe, as well as our privacy practices and commitment to protecting your privacy, please review our Legal & Privacy Policy.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Posts

Webinar banner for “High-Frequency Trading on Jakarta EE: GC Stress Testing with Azul C4 and Payara Micro,” March 25, 2026, 2 PM GMT. Features Azul and Payara Micro logos and speaker photos of Luqman Saeed, Jakarta EE Specialist, and Simon Ritter, Deputy CTO and Java Champion. 1 minute
Cloud & Microservices

High-Frequency Trading on Jakarta EE: Join Our Upcoming Live Webinar

Modern high-frequency trading (HFT) platforms operate under extreme performance constraints, processing tens of thousands of messages per second while […]

Illustration promoting the Payara Platform Community Survey, featuring bold text on a blue background alongside a clipboard with a checklist, star ratings, and check marks, with coral and fish graphics in an underwater theme. 1 minute
Community

Help Shape the Future of Payara Platform Community – Take Our 2026 Survey

Earlier this week, we’ve launched the 2026 Payara Platform Community Survey and we’d love to hear from you. If […]

Blue background with coral and fish. Left text: 'MONTHLY CATCH'. Right: laptop screen with tech tabs and Payara Community logo. 5 minutes
Community

The Payara Monthly Catch – February 2026

February brought strong momentum across the enterprise Java ecosystem – from Agentic AI discussions and Jakarta EE evolution, to […]