Posted in

PostgREST 12.2:Prometheus 指标_AI阅读总结 — 包阅AI

包阅导读总结

1.

关键词:PostgREST 12.2、Prometheus metrics、API 改进、自定义超时、最大影响行数

2.

总结:PostgREST 12.2 发布,带来可观测性和 API 改进。新增与 Prometheus 兼容的指标用于缓存和连接池,可设置每个函数的自定义超时,还引入限制受影响行数的最大影响偏好,新版本已在 Supabase 平台可用。

3.

主要内容:

– PostgREST 12.2 发布,具有可观测性和 API 改进

– 新增与 Prometheus 兼容的指标用于 schema 缓存和连接池,有助于解决连接池连接不足等问题

– 可通过修改配置扩展提升设置列表

– 此前通过在 API 角色设置 statement_timeout 影响所有语句,新版本可针对函数设置

– 新增自定义函数超时设置的功能

– 如 `create or replace function special_function()` 中可设置

– 超时设置在函数中会按事务应用

– 引入最大影响行数偏好 `max-affected`

– 可限制突变操作影响的行数

– 超过限制返回错误

– PostgREST 12.2 在 Supabase 平台的最新补丁版本(v12.2.3)可供新项目使用,现有项目可升级试用

思维导图:

文章地址:https://supabase.com/blog/postgrest-12-2

文章来源:supabase.com

作者:Supabase Blog

发布时间:2024/8/16 0:00

语言:英文

总字数:362字

预计阅读时间:2分钟

评分:85分

标签:PostgREST,Prometheus,API 改进,可观测性,数据库


以下为原文内容

本内容来源于用户推荐转载,旨在分享知识与观点,如有侵权请联系删除 联系邮箱 media@ilingban.com

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

# 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

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

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

_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

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

_10

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

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!