pg_later - Native Asynchronous Queries Within Postgres

submited by
Style Pass
2023-09-14 18:00:17

pg_later is an interesting project and extension built by Tembo which enables Postgres to execute queries asynchronously.  Fire your query - but don't forget to check later for the result.

Until now in order to interrogate your database asynchronously (i. e queries that return control to the user before the query completes) you would use a framework of a programming language, say Spring Framework, Java and CompletableFuture, to call a callback when the database operation completes, or for instance wait for it using the Snowflake Connector driver for Python which supports asynchronous queries. There's more to it though as you'll find out in Hibernate goes Reactive - What Does That Mean? 

This case is about native async queries within PostgreSQL, moving all that from the application layer to the database layer making it a feature of Postgres itself. So what's a good use case for it?

A primary one that is also detailed in the extension's blog, is when on a laptop you fire a long-running job and walk away, only to find out later on that the job was interrupted due to laptop going to sleep, or kernel dieing. Running asynchronously avoids that.

Leave a Comment