Latest Blog Posts

How to handle files?
Posted by Sergey Solovev on 2025-05-03 at 15:21

Greetings!

Fault tolerance is a very important aspect of every non-startup application.
It can be described as a definition:

Fault tolerance is the ability of a system to maintain proper operation despite failures or faults in one or more of its components.

But this gives only slight overview - fault tolerance concerns many areas especially when we are talking about software engineering:

  • Network failures (i.e. connection halt due to power outage on intermediate router)
  • Dependent service unavailability (i.e. another microservice)
  • Hardware bugs (i.e. Pentium FDIV bug)
  • Storage layer corruptions (i.e. bit rot)

As a database developer I'm interested in latter - in the end all data stored in disks.

But you should know that not only disks can lead to such faults. There are other pieces that can misbehave or it's developer's mistake that he/she didn't work with these parts correctly.

I'm going to explain how this 'file write stack' (named in opposite to 'network stack') works.
Of course, main concern will be about fault tolerance.

Application

Everything starts in application's code. Usually, there is separate interface to work with files.

Each PL (programming language) has own interface. Some examples:

  • fwrite - C
  • std::fstream.write - C++
  • FileStream.Write - C#
  • FileOutputStream.Write - Java
  • open().write - Python
  • os.WriteFile - go

These all means given by PL itself: read, write, etc...
Their main advantage - platform independence: runtime (i.e. C#) or compiler (i.e. C) implements this.
But this have drawbacks. Buffering in this case - all calls to this virtual "write" function store going to be written data in special buffer to later write it all at once (make syscall to write).

Due to documentation, each of all PL above support buffering:

[...]

Postgres 18 Release Notes
Posted by Bruce Momjian in EDB on 2025-05-03 at 00:15

I have just completed the first draft of the Postgres 18 release notes. It includes a little developer community feedback but still needs more XML markup and links.

The release note feature count is 206. There is a strong list of optimizer, monitoring, and constraint improvements. Postgres 18 Beta 1 should be released soon. The final Postgres 18 release is planned for September/October of this year.

Anatomy of a Database Operation
Posted by Karen Jex in Crunchy Data on 2025-05-02 at 16:49

Slides and transcript from my talk, "Anatomy of a Database Operation", at DjangoCon Europe in Dublin on 25 April 2025.

I'll share the recording as soon as it's available.

Introduction

This talk seemed like a great idea back in December 2024 when I asked the Django community for suggestions of database topics people wanted to hear about:

I'd love to be a DjangoCon Europe speaker again, because it's one of my favourite events. To that end, I'm looking for help to put together an irresistible talk submission! If you have suggestions for database/Postgres related topics that you'd really like to hear about, or burning database questions that you want to know the answer to, please let me know. I'm counting on you!

One of the suggestions was:

"how databases work and store data under the hood [so I can] build a complete mental model of what happens once you call SELECT … or INSERT."

Great idea, I thought. And then I realised just how much there was behind that one simple request!

So here goes...


I even learnt Django for the purpooses of this talk!

For demonstration purposes, I created this highly sophisticated web site that displays beer information that’s stored in a Postgres database. You can list beers, types of beer and breweries, and you can search for your favourite beer or add a new one.

But what’s happening behind the scenes when you do those things?

  • How is the request passed to the database?
  • How are the results retrieved and returned to you?
  • How’s the data stored, retrieved and modified?
  • And why should you even care?

One reason you might care is that users probably aren't happy when they see this ("LOADING, please wait...").


Or this ("DATABASE ERROR!").


This is me!
As you can see, from the diagram representing my career so far, (and as you already know if you've read my posts or watched my talks before), I have a database background.

I was a DBA for 20 years before I moved into database consultan

[...]

Mini Summit 4 Transcript: The User POV
Posted by David Wheeler in Tembo on 2025-05-01 at 21:02
Orange card with large black text reading “The User POV”. Smaller text above reads “04.23.2025” and below reads “Celeste Horgan (Aiven), Sonia Valeja (Percona), & Alexey Palazhchenko (FerretDB)”

On April 23, we hosted the fourth of five (5) virtual Mini-Summits that lead up to the big one at the Postgres Development Conference (PGConf.dev), taking place May 13-16, in Montreál, Canada. Celeste Horgan, Developer Educator at Aiven, Sonia Valeja, PostgreSQL DBA at Percona, and Alexey Palazhchenko, CTO FerretDB, joined for a panel discussion moderated by Floor Drees.

Amd now, the transcripts of “The User POV” panel, by Floor Drees

Introduction

My name is Floor, I’m one of the organizers of these Extension Ecosystem Mini-Summits. Other organizers are also here:

The stream and the closed captions available for the recording are supported by PGConf.Dev and their gold level sponsors, Google, AWS, Huawei, Microsoft, and EDB.

Next, and last in this series, on May 7 we’re gonna have Gabriele Bartolini talk to us about Extension Management in CloudNativePG. Definitely make sure you head over to the Meetup page, if you haven’t already, and RSVP for that one!

The User POV

Floor: For the penultimate edition of this series, we’re inviting a couple of Postgres extension and tooling users to talk about how they pick and choose projects that they want to use, how they do their due diligence and, their experience with running extensions.

But I just wanted to set the context for the meeting today. We thought that being in the depth of it all, if you’re an extension developer, you kind of lose the perspective of what it’s like to use extensions and other auxiliary tooling. You lose that user’s point of view. But users, maybe they’re

[...]

Waiting for PostgreSQL 18 – Allow NOT NULL constraints to be added as NOT VALID
Posted by Hubert 'depesz' Lubaczewski on 2025-05-01 at 10:55
On 7th of April 2025, Álvaro Herrera committed patch: Allow NOT NULL constraints to be added as NOT VALID   This allows them to be added without scanning the table, and validating them afterwards without holding access exclusive lock on the table after any violating rows have been deleted or fixed.   Doing ALTER TABLE … Continue reading "Waiting for PostgreSQL 18 – Allow NOT NULL constraints to be added as NOT VALID"

Queries on Vacuum
Posted by Dave Stokes on 2025-04-30 at 15:22

 I am (slowly) adding handy PostgreSQL queries to my GitHub, and Vacuum is the newest category.  The end goal is to have a compilation of queries for those of us who need to keep an instance healthy.

Over the years, I have collected hundreds of various queries and hate hunting them down in my code snippet library. Finally, they will be in one place and easy to search. 

Please contribute if you have similar or better queries (hint, hint!).

PostgreSQL Trusted Extensions for Beginners
Posted by Pavlo Golub in Cybertec on 2025-04-30 at 08:09

Introduction

Recently, we had a long discussion in our internal chat about the concept of Trusted Extensions in PostgreSQL. It became clear that while the feature is very useful, it’s often misunderstood — especially by beginners. Let's fix that!

This post explains what trusted extensions are, why they exist, how they work, and provides some important hints and warnings for everyday use.

What Are PostgreSQL Extensions?

An extension is a package of SQL scripts, types, functions, and sometimes even compiled C code that extends PostgreSQL's capabilities.
Extensions are installed on the server and then enabled inside a database using:

CREATE EXTENSION my_extension;

Normally, installing or enabling an extension requires superuser privileges, because extensions can modify how the database server behaves.

What Does "Trusted" Mean?

Trusted extensions allow non-superusers (regular database users) to enable certain extensions themselves using CREATE EXTENSION, without needing superuser rights.

In simple words:

  • If an extension is trusted, a user with CREATE privilege on a database can activate it.
  • If an extension is not trusted, only a superuser can activate it.

Important:
"Trusted" does not mean:

  • The extension is bug-free.
  • The code has been officially audited by PostgreSQL core developers.
  • It is completely safe in every possible scenario.

It simply means:

"We believe that enabling this extension should not allow users to bypass security or harm the database server."

How Does PostgreSQL Know if an Extension is Trusted?

Each extension has a control file (.control) where its properties are described.
Inside that file, the line:

trusted = true

tells PostgreSQL that the extension can be enabled by non-superusers.

If the line is missing, the extension is considered untrusted by default.

Example of a simple control file:

comment = 'Extension for text search'
default_version = '1.0'
relocatable = false
superuser = fal
[...]

A PostgreSQL planner gotcha with CTEs DELETE and LIMIT
Posted by Shayon Mukherjee on 2025-04-29 at 12:00
I recently discovered an unexpected behavior in PostgreSQL involving a pattern of using a Common Table Expression (CTE) with DELETE ... RETURNING and LIMIT to process a batch of items from a queue-like table. What seemed straightforward turned out to have a surprising interaction with the query planner. The scenario Let’s say you have a task_queue table and want to pull exactly one task for a specific queue_group_id. A common approach is using a CTE:

The Tux and the Pachyderm
Posted by Federico Campoli on 2025-04-29 at 07:00

In the previous blog post we have seen how plenty of ram doesn’t necessary results in a faster instance.

This time we’ll quickly see how PostgreSQL and Linux relate to each other in particular if we want to run our RDBMS at scale.

Then we’ll have a look to the virtual memory in Linux and how to make it more friendly to PostgreSQL.

Let’s dig in.

PG Day Chicago 2025
Posted by Henrietta Dombrovskaya on 2025-04-29 at 06:33

We did it!

Thank you so much to everyone who made this event a success! Starting with the great talks selection (thank you, CfP committee!), to our amazing sponsors (thank you, Pat Wright!), to volunteers, to attendees!

My highlights were having multiple new speakers, new topics, and seeing a lot of new attendees for many of whom this was their first Postgres conference! I hope you all enjoyed it, and I hope to see you again!

And please don’t forget to leave us feedback here!

Orphaned files after a PostgreSQL crash
Posted by Laurenz Albe in Cybertec on 2025-04-29 at 05:00

A computer screen where "ls --orphaned" ran on a data directory and returned files with all kinds of funny orphan names
© Laurenz Albe 2025

PostgreSQL is famous for its stability, and rightly so. But that does not mean that it can never crash. And while PostgreSQL usually cleans up after itself, it has no good way to do so after a crash (after all, it has lost its memory). As a consequence, you can end up with orphaned files in your data directory. If these files are small, they probably won't worry you. But sometimes you can end up with a lot of junk in your data directory. It is notoriously difficult to deal with that problem, so I decided to write about it.

Why would PostgreSQL crash?

In case the title of this article gives you bad feelings about PostgreSQL, I'll try to dispel them. PostgreSQL is not in the habit of crashing. But sometimes a crash is not PostgreSQL's fault. Let me enumerate a few possible causes for a crash:

In fact, the most frequent cause of a crash that leaves large orphaned files in its wake is people running VACUUM (FULL). This command creates a copy of the table and all its indexes. If you run out of disk space and PostgreSQL cannot create a new WAL segment, the database server will crash. Such a crash will leave the partly created copy of the table behind. To avoid that kind of problem, I recommend that you keep pg_wal and the data directory o

[...]

Source code line numbers for database queries in Ruby on Rails with Marginalia and Query Logs
Posted by Andrew Atkinson on 2025-04-29 at 00:00

Back in 2022, we covered how to log database query generation information from a web app using pg_stat_statements for Postgres. https://andyatkinson.com/blog/2022/10/07/pgsqlphriday-2-truths-lie

The application context annotations can look like this. They’ve been re-formatted for printing:

application=Rideshare
controller=trip_requests
source_location=app/services/trip_creator.rb:26:in `best_available_driver'
action=create

I use pg_stat_statements to identify costly queries generated in the web application, often ORM queries (the ORM is Active Record in Ruby on Rails), with the goal of working on efficiency and performance improvements.

The annotations above are included in the query field and formatted as SQL-compatible comments.

Application context usually includes the app name and app concepts like MVC controller names, action names, or even more precise info which we’ll cover next.

How can we make these even more useful?

What’s the mechanism to generate these annotations?

For Ruby on Rails, we’ve used the Marginalia Ruby gem to create these annotations.

Besides the context above, a super useful option is the :line option which captures the source code file and line number.

Given how dynamic Ruby code can be, including changes that can happen at runtime, the :line level logging takes these annotations from “nice to have” to “critical” to find opportunities for improvements.

What’s more, is that besides Marginalia, we now have a second option that’s built-in to Ruby on Rails.

What’s been added since then?

In Rails 7.1, Ruby on Rails gained similar functionality to Marginalia directly in the framework.

While nice to have directly in the framework, the initial version didn’t have the source code line-level capability.

That changed in the last year! Starting from PR 50969 to Rails linked below, for Rails 7.2.0 and 8.0.2, the source_location option was added to Active Record Query Logs, equivalent to the :line option in Marginalia.

PR: Support :sou

[...]

PostgreSQL 18: part 4 or CommitFest 2025-01
Posted by Pavel Luzanov in Postgres Professional on 2025-04-29 at 00:00

We continue to follow the news about PostgreSQL 18. The January CommitFest brings in some notable improvements to monitoring, as well as other new features.

You can find previous reviews of PostgreSQL 18 CommitFests here: 2024-07, 2024-09, 2024-11.

  • EXPLAIN (analyze): buffers on by default
  • pg_stat_io: input/output statistics in bytes instead of pages
  • pg_stat_io: WAL statistics
  • pg_stat_get_backend_io: I/O statistics for a specific process
  • VACUUM(verbose): visibility map information
  • Total vacuum and analysis time per table
  • autovacuum: change the number of workers without restarting the server
  • psql: connection service information
  • psql: expanded display for \d* commands
  • psql: leakproof flag in \df* output
  • jsonb: null conversion to other types
  • MD5 encryption algorithm: end-of-support preparations
  • New function uuidv7
  • postgres_fdw: SCRAM authentication without storing the password
  • passwordcheck: minimum password length
  • New function casefold and pg_unicode_fast collation
  • DML commands: RETURNING with OLD and NEW
  • to_number: convert a string of roman numberals to numeric

...

Update Your Control Files
Posted by David Wheeler in Tembo on 2025-04-28 at 20:08

Reviews of the extension search path patch, now committed and slated for PostgreSQL 18, revealed a few issues with extension configuration. Based on the ensuing discussion, and even though PostgreSQL 18 will include workarounds, it’s best to make adjustments to the extensions you maintain, the better to serve existing PostgreSQL versions and to hew closer to best practices.

Thus, a couple of recommendations for extension maintainers.

  1. Remove the $libdir/ prefix from the module_pathname directive in the control file. The $libdir/ requires extension modules to live in pkglibdir (see pg_config), and no other directories included in dynamic_library_path, which limits where users can install it. Although PostgreSQL 18 will ignore the prefix, the docs will also no longer recommend it.

  2. Remove the directory parameter from the control file and the MODULEDIR directive from the Makefile. Honestly, few people used these directives, which installed extension files in subdirectories or even completely different absolute directories. In some cases they may have been useful for testing or extension organization, but the introduction of the extension search path alleviates its use cases.

These changes will future-proof your extensions and make them better ecosystem citizens. Plus, they clean out some otherwise funky configurations that just aren’t necessary. Make the changes today — and while you’re at it, test your extensions with PostgreSQL 18 pre-releases!

Look, I’ll go first.

Adam Hendel
Posted by Andreas 'ads' Scherbaum on 2025-04-28 at 14:00
PostgreSQL Person of the Week Interview with Adam Hendel: My name is Adam Hendel and I live in Minnesota (USA). I grew up playing ice hockey and it was a very important part of my life up until age 21. Then I went on to get bachelor degrees in finance and physics and amasters in data science. I served in the U.S. Army military intelligence corps after college. I’ve been working in data science, machine learning, and software engineering ever since.

Taming large datasets in PostgreSQL: archiving and retention without the pain
Posted by DARIA NIKOLAENKO in Data Egret on 2025-04-28 at 11:16

PostgreSQL databases tend to grow silently. One day, you notice queries slowing down, backups taking forever, and no one remembering what is in that 500 GB log table. If this sounds familiar, you’re not alone.

Partitioning makes things manageable

If your database has one massive table that keeps growing, partitioning can be a lifesaver. PostgreSQL has supported native declarative partitioning since version 10, and recent versions (13 and up) have made it much easier to work with.

  • You don’t need any extensions — you can define a parent table and split it by range, list, or hash. For example, for time-based data:

CREATE TABLE events (
id serial,
created_at timestamptz,
payload jsonb
) PARTITION BY RANGE (created_at);

What makes partitioning useful is how it improves query planning and makes deleting old data trivial (dropping a partition is faster and cleaner than a DELETE).

To migrate an existing table, you can:

  • Create a partitioned version of the table

  • Move data in batches using scripts

  • Add triggers to route new inserts into the partitioned version

  • Swap the old and new tables once the migration is complete

Note: Define indexes on the partitioned table itself — PostgreSQL will automatically create corresponding indexes on all partitions, including ones added in the future. You can’t use concurrently, though.

Compression: saving space on cold data

PostgreSQL uses a mechanism called TOAST (The Oversized-Attribute Storage Technique) to handle large field values such as text, jsonb, and bytea. By default, it compresses these using the pglz algorithm.
Since PostgreSQL 14, you can explicitly choose a compression algorithm per column — if your build includes LZ4 support (–with-lz4), you can use the faster and often more efficient lz4 algorithm:

CREATE TABLE logs_lz4 (
id serial PRIMARY KEY,
message text COMPRESSION lz4
);

Bonus: compressing backups

[...]

[PATCH IDEA] adaptive execution for `IN` queries
Posted by Tomas Vondra on 2025-04-28 at 10:00

Last week I visited the Malmö PUG to talk about performance cliffs. It’s a really nice meetup - cozy environment, curious audience asking insightful questions. I highly recommend attending or even giving a talk there.

After the meetup I realized it’s been a while since I posted about some patch idea, and the performance cliff talk has a couple good candidates. Some might be a bit too hard for the first patch, for example improving the JIT costing. But improving the very first example about queries with IN clauses seems feasible. It’s quite well defined and isolated.

PgPedia Week, 2025-04-27
Posted by Ian Barwick on 2025-04-27 at 20:52

A very minimal edition this week, due to lack of time, and it's been relatively quiet anyway.

more...

Exploring the limits of Postgres
Posted by KUNTAL GHOSH in EDB on 2025-04-27 at 01:30

Postgres is a powerful and feature-rich database, but like any system, it has certain limits that are good to be aware of. In this post, we'll take a look at a few interesting limits in Postgres.

63 Character Limit on Identifiers

Postgres has a limit of 63 characters for identifiers such as table names, column names, and function names. This is a common limit across many database systems and helps ensure efficient storage and processing.

Maximum Number of Function Arguments

Postgres allows up to 100 arguments to be passed to a function. This generous limit should be sufficient for most use cases, but it's good to keep in mind if you're working with particularly complex functions.

Index and Partition Key Limits

Postgres has a limit of 32 columns that can be included in an index, including INCLUDE columns. Similarly, the maximum number of columns in a partition key is also 32. These limits help maintain efficient index and partition management.

Table Column Limit

Postgres tables cannot have more than 1600 columns. While it's unlikely you'll ever need a table with that many columns, it's good to know the upper bound.

Query Planning Optimization

Postgres will generate custom query plans until it has done at least 5 planning attempts before choosing a cheaper generic plan. This helps ensure that Postgres explores various planning options to find the most efficient execution strategy.


These are just a few of the interesting limits in Postgres. As you work with the database, it's a good idea to familiarize yourself with these and other limits to ensure your application is designed and optimized accordingly.

For more information, you can check the Postgres documentation.

Disclaimer: This blog post is partially generated by AI.

Incremental Backups in PostgreSQL 17
Posted by Dave Stokes on 2025-04-26 at 15:26
 The old adage that a DBA or SRE is only as good as their last backup is true.  PostgreSQL 17 added the ability to combine multiple incremental backups with a full backup to provide a complete data dictionary to recover a failed system. It is very easy to use.

This is a quick example of using incrementals. I recommend watching this video by Robert Haas for more details and some discussion of backup strategies.

Step 1 - Enable WALL Summerization


The incremental backups require Write Ahead Log Summarization. It is likely not on your instance by default. But it is easy to enable.

demo=# alter system set summerize_wal = 'on';
ALTER SYSTEM
demo=# select pg_reload_conf();
pg_reload_conf 
----------------
 t
(1 row)

Step 2 - Full Backup

The examples below are much simpler than you will run into in real life.  The scenario is that we make a full backup on Sunday and do incrementals the rest of the week. Wednesday through Saturday are omitted below. 

stoker@ThinkPad:~$ mkdir full monday tuesday

stoker@ThinkPad:~$ pg_basebackup -D full --verbose
Password: 
pg_basebackup: initiating base backup, waiting for checkpoint to complete
pg_basebackup: checkpoint completed
pg_basebackup: write-ahead log start point: 6/12000028 on timeline 1
pg_basebackup: starting background WAL receiver
pg_basebackup: created temporary replication slot "pg_basebackup_21051"
pg_basebackup: write-ahead log end point: 6/12000158
pg_basebackup: waiting for background process to finish streaming ...
pg_basebackup: syncing data to disk ...
[...]

FROM function or SELECT function
Posted by Regina Obe in PostGIS on 2025-04-26 at 00:47

When I have set returning functions and even non-set returning functions, I love putting them in the FROM clause instead of the SELECT part. I often take it for granted that the results are usually the same, but in some important situations, they are different. It's not guaranteed to be the same when your function is not immutable.

Continue reading "FROM function or SELECT function"

TRAKTOR 2 is out!
Posted by Ernst-Georg Schmid on 2025-04-25 at 12:35

Check TRAKTOR 2 - less complicated, more stable, cloud ready! Compatible with PostgreSQL 16 and 17.

Contributions for the weeks 16 & 17 (2025)
Posted by Cornelia Biacsics in postgres-contrib.org on 2025-04-25 at 09:08

Stacey Haysler created a document which lists all the available volunteer options for the PostgreSQL project.


Luigi Nardi organized the Malmö PostgreSQL Meetup. Tomas Vondra presented.


April 23 the Postgres Extensions Ecosystem Mini-Summit #4 hosted a panel of users - Celeste Horgan, Sonia Valeja, Alexey Palazhchenko - to gain their POV (recording).


At the April 22 Barcelona PostgreSQL User Group meetup run by Andrea Cucciniello, Dave Pitts, and Nacho Alonso Portillo, Gabriele Bartolini presented "CloudNativePG: The Past, The Present, The Future".


On April 24th Gerard Zuidweg hosted the PostgreSQL User Group NL Spring 2025 Meetup. The following talks were held: Frank Sidi about “Analytics for PostgreSQL: From OLTP to Lakehouse to Petabyte-Scale AI” Hans-Jürgen Schönig about “Running PostgreSQL in Kubernetes made easy” Lightning Talk held by Ellert van Koperen about “Defaults and logical replication do not get along”


On April 23rd Karren Jex gave a lightning talk at DjangoCon Europe about the Diversity Task Force and encouraging folks to get involved in the PostgreSQL community and come along to PostgreSQL events.


Tom Kincaid organized the Boston PostgreSQL Meetup, Adam Wright spoke at the event.


Alastair Turner and Chris Ellis organized the PostgreSQL London Meetup. Tushar Ghotikar, Mauro Parada Crespo and Alastair Turner presented at the event.


Tobias Bussman, Andreas Geppert and Daniel Westermann have been part of the organization team for Swiss Database Synergy Day 2025. [Dirk Krautschick] (https://www.linkedin.com/in/dirk-krautschick), Laurenz Albe, Stephan Keller, Maurizio De Giorgi and Daniel Westermann presented talks.

Striping Postgres data volumes - a free lunch?
Posted by Kaarel Moppel on 2025-04-23 at 21:00
A small follow up on my previous post on various Postgres scale-up avenues in my preferred order. The post received quite a bit of interest - meaning people at least still “wish” performant databases :) And - the ones who are willing to put in a bit of effort with...

TRAKTOR revisited
Posted by Ernst-Georg Schmid on 2025-04-22 at 14:52

Working on TRAKTOR again. The good news is, it still works with PostgreSQL 17.x and I have completely replaced psycopg2 with pg8000 to remove all native dependencies. The bad news is, if you don't want to run the arbiter as superuser it's a complicated dance of permissions, some of which can only be GRANTed by a superuser, and I have to find a way to automate this as far as possible.

On expressions' reordering in Postgres
Posted by Andrei Lepikhov in Postgres Professional on 2025-04-22 at 11:08

Today, I would like to discuss additional techniques to speed up query execution. Specifically, I will focus on rearranging conditions in filter expressions, JOINs, HAVING clauses, and similar constructs. The main idea is that if you encounter a negative result in one condition within a series of expressions connected by the AND operator, or a positive result in one of the conditions linked by the OR operator, you can avoid evaluating the remaining conditions. This can save computing resources. Below, I will explain how much execution efforts this approach saves and how to implement it effectively.

Occasionally, you may come across queries featuring complex filters similar to the following:

SELECT * FROM table
WHERE
  date > min_date AND
  date < now() - interval '1 day' AND
  value IN Subplan AND
  id = 42';

And in practice, it happens that a simple rearrangement of the order of conditions in such an expression allows for speeding up (sometimes quite notably) the query execution time. Why? Each individual operation costs little. However, if it is performed repeatedly on each of millions of the table's rows, then the price of the operation becomes palpable. Especially if other problems, like the table blocks getting into shared buffers, are successfully solved.

This effect is particularly evident on wide tables that contain many variable-length columns. For instance, I often encounter slow IndexScans that become slow when the field used for additional filtering is located somewhere around the 20th (!) position in the table, containing many variable-width columns. Accessing this field requires calculating its offset from the beginning of the row, which takes up processor time and slows down the execution.

The PostgreSQL community has already addressed this issue, as observed in the code. In 2002, commit 3779f7f, which was added by T. Lane, reorganised the clauses by positioning all clauses containing subplans at the end of the clause list (see order_qual_clauses). This change was logical because

[...]

8 Steps to Proactively Handle PostgreSQL Database Disaster Recovery
Posted by Ibrar Ahmed on 2025-04-22 at 06:13

When disaster strikes, whether a natural disaster or a technical event, its impact on your network, database, and end-users can cause both costly downtime and data corruption. Data corruption, whether sparked by hardware failures like dying disks or faulty RAM, software glitches such as operating system bugs, or human missteps like accidental overwrites, is a terrifying prospect for any administrator. Yet, it’s not a death sentence.Your PostgreSQL database is typically a dependable cornerstone of your operations. Still, when disaster strikes, it can swiftly morph into an inaccessible liability, bringing applications to a grinding halt and leaving critical data at risk. PostgreSQL 17 arms you with an enhanced arsenal to tackle this challenge head-on, offering built-in tools like for pinpointing corruption, improved failover slot synchronization to keep replication intact during recovery, and finer-grained Write-Ahead Logging (WAL) control for precise restoration. In this blog, we'll dive deep into the disaster management process, equipping you with real-world commands and expected outputs to diagnose corruption accurately and recover effectively, whether you’re restoring from a robust backup or salvaging scraps from a crippled cluster with no safety net. With the right approach, you can turn panic into a plan and restore order to your database.

Step 1: Detecting Corruption in PostgreSQL

Corruption usually doesn’t introduce itself politely; it sneaks in through failed queries, panicked logs, or startup errors. Identifying corruption is the first step towards resolving it.
Check the PostgreSQL Log Files
Start by inspecting the log files.  Typically, you'll find the log files in or . Within the log files, entry headers indicate the severity level of the log entry; for example:Severity levels indicate:
● ERROR: Read failure, possibly a disk-level issue.
● PANIC: Serious corruption PostgreSQL crashed to prevent further damage.
● FATAL: The server is trying to recover from an unclean shutdown.If your database is [...]

Type alignment and padding bytes: how to not waste space in PostgreSQL tables
Posted by Laurenz Albe in Cybertec on 2025-04-22 at 05:00

Padding bytes in real life: a man tells his child to stand between two big-bellied men so that they can all fit into the elevator
© Laurenz Albe 2025

Saving storage space should not be your first objective in a PostgreSQL database. Very often, the desire to conserve space aggressively comes at the expense of performance. But there is also no reason to needlessly waste space. Therefore, it is a good idea to be familiar with the concepts of data type alignment and padding bytes in PostgreSQL.

What is data type alignment?

When the CPU reads or writes a value from memory, the performance is best if the address of the value is a multiple of the size of the value. For example, a 4-byte integer should start at an address that is a multiple of four. PostgreSQL tries to optimize for performance. Therefore, it makes sure that all values are correctly aligned in memory. Note that alignment is only relevant for data types with a fixed length: PostgreSQL stores variable length data types like text, varchar and numeric without respecting the type alignment.

Whenever PostgreSQL persists data on disk, it organizes these data in pages (also known as buffers or, when on disk, as blocks) of 8kB. To keep things simple and efficient, the layout of a block on disk is exactly the same as the page in memory. As a consequence, PostgreSQL respects the type alignment on disk as well.

PostgreSQL data types can have an alignment of 1, 2, 4 or 8 bytes. You can see the alignment of a data type in the typalign column of the system catalog pg_type:

SELECT typalign,
       string_agg(typname, ', ' ORDER BY length(typname)) AS types
FROM pg_type
WHERE typtype = 'b'            -- base type
  AND typelem = 0              -- no array
  AND typlen <> -1             -- fixed length
  AND typnamespace = 'pg_catalog'::regnamespace  -- system type
  AND typname NOT LIKE 'reg%'  -- no object identifier type
GROUP BY typalign;

 typalign │                                               types
══════════╪════════════════════════════════════════════════════════════════════════════════════════════════════
 c        │ bool, char, uuid
 d        │ xid8, time, int8,
[...]

Mini Summit 4: The User POV
Posted by David Wheeler in Tembo on 2025-04-21 at 17:26
Orange card with large black text reading “The User POV”. Smaller text above reads “04.23.2025” and below reads “Celeste Horgan (Aiven), Sonia Valeja (Percona), & Alexey Palazhchenko (FerretDB)”

And we’re back.

This Wednesday, April 9 at noon America/New_York (16:00 UTC) for Extension Mini Summit #4, where our panel consisting of Celeste Horgan (Aiven), Sonia Valeja (Percona), and Alexey Palazhchenko (FerretDB) will discuss “The User POV”. This session will be a terrific opportunity for those of us who develop extensions to get an earful from the people who use them, in both anger and joy. Bang on the Meetup to register for this live video session.

PgPedia Week, 2025-04-20
Posted by Ian Barwick on 2025-04-20 at 20:10
PostgreSQL 18 changes this week

With all five CommitFests over, we're now into the testing and bugfix phase, and no new features are likely to be added. Having said that, there have been a few tweaks to SQL function performance and handling this week.

PostgreSQL 18 articles Waiting for PostgreSQL 18 – Add modern SHA-2 based password hashes to pgcrypto. (2025-04-17) - Hubert 'depesz' Lubaczewski Waiting for PostgreSQL 18 – Non text modes for pg_dumpall, correspondingly change pg_restore (2025-04-15) - Hubert 'depesz' Lubaczewski Improvements in Expanded Objects in PostgreSQL 18 (2025-04-12) - Jim Mlodgenski

more...

Top posters

Number of posts in the past two months

Top teams

Number of posts in the past two months

Feeds

Planet

  • Policy for being listed on Planet PostgreSQL.
  • Add your blog to Planet PostgreSQL.
  • List of all subscribed blogs.
  • Manage your registration.

Contact

Get in touch with the Planet PostgreSQL administrators at planet at postgresql.org.