pwshub.com

PostgREST 12.2: Prometheus compatibility and statement timeouts

PostgREST 12.2: Prometheus compatibility and statement timeouts

PostgREST 12.2 is out! It comes with Observability and API improvements. In this post, we'll see what's new.

Version 12.2 ships with Prometheus-compatible metrics for PostgREST's schema cache and connection pool. These are useful for troubleshooting, for example, when PostgREST's pool is starved for connections.


_10

curl localhost:3001/metrics

_10

_10

# HELP pgrst_db_pool_timeouts_total The total number of pool connection timeouts

_10

# TYPE pgrst_db_pool_timeouts_total counter

_10

pgrst_db_pool_timeouts_total 7.0

_10

_10

# ....


A full list of supported metrics is available in the PostgREST documentation.

Sometimes it's handy to set a custom timeout per function. You can now do this on 12.2 projects with:


_10

create or replace function special_function()

_10

returns void as $$

_10

select pg_sleep(3); -- simulating some long-running process

_10

$$

_10

language sql

_10

set statement_timeout to '4s';


And calling the function with the RPC interface.

When doing set statement_timeouton the function, the statement_timeout will be “hoisted” and applied per transaction.

By default this also works for other settings, namely plan_filter.statement_cost_limit and default_transaction_isolation. The list of hoisted settings can be extended by modifying the db-hoisted-tx-settings configuration.

Before 12.2, this could be done by setting a statement_timeout on the API roles, but this affected all the SQL statements executed by those roles.

In prior versions of PostgREST, users could limit the number of records impacted by mutations (insert/update/delete) to 1 row using vendor media type application/vnd.pgrst.object+json. That supports a common use case but is not flexible enough to support user defined values.

12.2 introduces the max-affected preference to limit the affected rows up to a custom value.

For example:


_10

curl -i "http://localhost:3000/items?id=lt.15" -X DELETE \

_10

-H "Content-Type: application/json" \

_10

-H "Prefer: handling=strict, max-affected=10"


If the number of affected records exceeds max-affected , an error is returned:


_10

HTTP/1.1 400 Bad Request

_10

{

_10

"code": "PGRST124",

_10

"message": "Query result exceeds max-affected preference constraint",

_10

"details": "The query affects 14 rows",

_10

"hint": null

_10

}


PostgREST v12.2 is already available on the Supabase platform on its latest patch version (v12.2.3) for new projects. Spin up a new project or upgrade your existing project to try it out!

Source: supabase.com

Related stories
1 month ago - As the Supabase community has grown, so has demand for a diverse collection of client libraries and framework specific SDKs. This demand for the...
1 month ago - There's always a lot to cover in Launch Weeks. Here are the top 10, ranked by my own statistical reasoning. #10 Snaplet is now open source Snaplet...
1 month ago - Supabase offers comprehensive features that make it easy for frontend devs to build complex backends and focus on crafting exceptional UIs. The post Supabase adoption guide: Overview, examples, and alternatives appeared first on LogRocket...
2 weeks ago - PHP hosting providers offer specialized hosting for web applications and sites developed using PHP programming language – a popular server-side scripting language. It provides a technical environment for PHP scripts to work optimally. As...
1 month ago - I’m always amazed by the talent and passion of our Amazon Web Services (AWS) community members, especially in their efforts to increase diversity, equity, and inclusion in the tech community. Last week, I had the honor of speaking at the...
Other stories
21 minutes ago - Four Prometheus metric types that all developers and DevOps pros should know form the building blocks of an effective observability strategy
1 hour ago - The 2024 Gartner Magic Quadrant positions AWS as a Leader, reflecting our commitment to diverse virtual desktop solutions and operational excellence - driving innovation for remote and hybrid workforces.
2 hours ago - Understanding design patterns are important for efficient software development. They offer proven solutions to common coding challenges, promote code reusability, and enhance maintainability. By mastering these patterns, developers can...
2 hours ago - APIs (Application Programming Interfaces) play an important role in enabling communication between different software systems. However, with great power comes great responsibility, and securing these APIs is necessary to protect sensitive...
2 hours ago - This article aims to celebrate the power of introversion in UX research and design. Victor Yocco debunks common misconceptions, explores the unique strengths introverted researchers and designers bring to the table, and offers practical...