Posts

Showing posts with the label Database

A New Collection of Thoughtful Learning Apps — Now Available on iOS & Android

Image
I’m excited to share a set of mobile apps I’ve recently completed and published on both the Google Play Store and the Apple App Store. These apps are designed with a simple goal in mind: to make meaningful, structured content more accessible, whether you’re studying theology or improving your English vocabulary. 📱 Now Available on Both Platforms All apps are live and available for download: Google Play Developer Page: https://play.google.com/store/apps/dev?id=5835943159853189043 Apple App Store Developer Page: https://apps.apple.com/ca/developer/q-z-l-corp/id1888794100 📖 Theology & Confession Study Apps For those interested in Reformed theology and classical Christian teachings, I’ve developed a series of apps that present foundational texts in a clean, focused reading format: The Belgic Confession Canons of Dort Heidelberg Catechism Westminster Shorter Catechism Each app is designed to provide a distraction-free experience, making it easier to read, reflect, and revisit these im...

Fix “Value Too Long for Column” Error: UTF-8 String Truncation by Bytes in Java

Image
Fix “Value Too Long for Column” Error: UTF-8 String Truncation by Bytes in Java If you've ever encountered the "value too long for column" database error, especially in a Java backend, the root cause may not be obvious. In this post, we’ll walk through a real production issue caused by UTF-8 encoding , explain why string length is not equal to byte length , and show how to correctly truncate strings by bytes without breaking multibyte characters. The Production Issue We hit a production error during a database insert: value too long for column Database column limit: 50 bytes Input string length: 53 characters Code already truncated to 50 characters At first glance, everything looked correct—but the insert still failed. Root Cause: UTF-8 Encoding The issue comes down to this: 50 characters does NOT equal 50 bytes in UTF-8 In UTF-8 encoding: ASCII characters → 1 byte Chinese characters → 3 bytes Emoji → 4 bytes This mean...

A Lesson Learned: Slow DELETE Caused by Missing FK Indexes

Image
A Lesson Learned: Slow DELETE Caused by Missing FK Indexes Recently, I was working on a data purge task. The logic itself was simple: delete old records based on certain conditions. I had done similar work before, so I did not expect any major issues. However, this time the DELETE operation got stuck . No errors were reported, but the SQL just kept running without making progress. What Happened? With help from our DBA, we started investigating the issue at the database level. After some analysis, we identified the root cause: Several foreign key (FK) columns were missing supporting indexes. Because of this, every DELETE on a parent table forced Oracle to perform full table scans on related child tables to validate referential integrity. As data volume increased, the performance impact became severe. The Fix After adding indexes on the missing foreign key columns (across related tables), the results were immediate: DELETE operations completed much faster ...

Why PostgreSQL Idle Connections Remain After Vercel Deployments

Image
Why PostgreSQL Idle Connections Remain After Vercel Deployments If you are running a Next.js application on Vercel with PostgreSQL , you may have encountered this error: remaining connection slots are reserved for roles with the SUPERUSER attribute This issue often appears right after a redeploy or during traffic spikes, even when your application traffic is relatively low. The Symptom PostgreSQL shows many connections in idle state Connections remain even after Vercel instances are shut down New requests fail with connection slot errors Manually terminating idle connections only fixes the problem temporarily What Is Really Happening This behavior is expected in serverless environments . Here is what happens behind the scenes: Vercel spins up serverless function instances Each instance creates its own PostgreSQL connection or connection pool When the instance finishes, it may shut down without gracefully closing the DB connection Post...

How a JPA save() Call Silently Overwrote My Data (and How to Fix It)

Image
How a JPA save() Call Silently Overwrote My Data (and How to Fix It) I recently encountered a subtle but dangerous issue in a Spring Boot + JPA application. There were no errors, no exceptions, and no failed transactions — yet a database column was silently overwritten with NULL . If you are using Spring Data JPA and updating the same table from multiple endpoints, this is something you should be aware of. The Simplified Scenario We had two REST endpoints updating the same entity, but different fields. The code below is simplified and mangled for illustration. Endpoint A – updates an external reference EntityX entity = repository.findByKey(refId); // update external reference entity.setExternalRef("ABC123"); repository.save(entity); Endpoint B – updates customer email EntityX entity = repository.findByKey(refId); // update email only entity.setEmail("user@example.com"); repository.save(entity); The assumption was that Endpoint B would ...