Docker and sudden death for PostgreSQL
© Laurenz Albe 2023 This is a short war story from a customer problem. It serves as a warning that there are special considerations when running software in a Docker container. The problem description The customer is running PostgreSQL in Docker containers. They are not using the “official” image, but their own. Sometimes, under conditions […]
Go & PostgreSQL: FOSDEM 2023 talk
Intro On the 5th of February 2023, I had the privilege of giving a talk at the PostgreSQL devroom during FOSDEM 2023 titled “When it all GOes right.” My talk focused on the process of creating programs in the Go language using a PostgreSQL database. It was an incredible opportunity to share my insights and […]
Transaction ID wraparound: a walk on the wild side
© Laurenz Albe 2022 Most people are aware of transaction ID wraparound. The concept has been well explained in Hans’ article, so I won’t repeat all that here. But for most people it is an abstract concept, a bogeyman lurking in the dark around the corner. Many people know horror stories about anti-wraparound autovacuum tanking […]
A unique constraint where NULL conflicts with everything
© Laurenz Albe 2022 I have been faced with a request for an unusual unique constraint that puzzled me for a while. Since the solution I came up with is a nice show-case for range data types, I’ll share it with you. Also, it allows me to rant some about NULL, which is a temptation […]
UNION ALL, data types and performance
© Laurenz Albe 2022 A while ago, I wrote about the performance impact of query parameter data types. Recently I encountered a similar problem with UNION ALL that baffled me for a while, so I’d like to share it with you. UNION ALL to implement polymorphism Different entities can have something in common. For example, […]
PostgreSQL ERROR: permission denied for schema public
In PostgreSQL 15, a fundamental change took place which is relevant to every user who happens to work with permissions: The default permissions of the public schema have been modified. This is relevant because it might hurt you during application deployment. You need to be aware of how it may affect you. Creating users Many […]
EXPLAIN that parameterized statement in PostgreSQL!
© Laurenz Albe 2022 For detailed query performance analysis, you need EXPLAIN (ANALYZE, BUFFERS) output for an SQL statement. With a parameterized statement, it can be difficult to construct a run-able statement for EXPLAIN (ANALYZE). Sometimes, you don’t even know the parameter values. I’ll show you how you can get at least plain EXPLAIN output […]
Rewrite OR to UNION in PostgreSQL queries
Rewriting OR is not always the best solution © Laurenz Albe 2022 In my article that reviles OR, I showed how in certain cases, it is possible to rewrite OR in a WHERE condition to a longer query with UNION that can perform much better (the “ugly” OR). Now people have asked me repeatedly why […]
Why are my PostgreSQL updates getting slower?
© Laurenz Albe 2022 Recently, a customer asked me why a bulk load into a PostgreSQL table kept slowing down as time went by. They saw that it was a trigger on the table that took longer and longer, and in that trigger, the updates were getting slower all the time. Now slow updates are […]
PostgreSQL: Sequences vs. Invoice numbers
Sequences are a core feature of SQL. However, some users are tempted to implement sequences to generate invoices. That’s dangerous and should be avoided. The core question is: Why? What’s the problem with using database-side sequences to put unique invoice numbers to send to clients? Let’s dive in and find out. Getting started with CREATE […]
What is an inner join in SQL? And what is an outer join?
A join is a concept in IT which is widely used and often referred to but rarely really understood. What are the differences between inner joins, outer joins, semi joins and so on? Let’s shed some light on them and see how inner and outer joins really work. Producing sample data Before we can get […]
ERROR: nextval: reached maximum value of sequence
serial is a popular pseudo data type in PostgreSQL which is often used to generate auto-increment columns. However, this can lead to issues which are often underestimated. So what is the problem? Some of you might have already seen the following error message in real life: What happened here is that the underlying integer column […]