Skip to content

Avoiding timeouts in long running queries

有些查询,比如给表建立索引或修改列的数据类型,本身就是很耗时间的。仪表板的 SQL 编辑器 有一分钟的超时限制。

🌐 Certain queries, like indexing a table or changing a column's data type, are inherently time-consuming. The Dashboard's SQL Editor has a 1-minute timeout limit.

要执行长时间运行的查询,请按照以下步骤操作。

🌐 To execute long-running queries, follow the below steps.

安装一个外部 SQL 客户端 #

🌐 Install an external SQL client

本指南主要讲解 psql,但你也可以使用任何 Postgres 客户端。

🌐 The guide focuses on psql but you can use any Postgres client.

其他一些选项包括:

🌐 Some other options include:

你可以通过以下链接和说明在 macOSWindows 上安装 PSQL。对于 Linux(Debian),你可以运行以下命令:

🌐 You can install PSQL in macOS and Windows by following these links and instructions. For Linux (Debian) you can run the following:

1
sudo apt-get update
2
sudo apt-get install postgresql-client

安装完成后,你可以在仪表板上点击 connect 找到你的 PSQL 字符串。如果你使用的是连接池,确保它是 Session pooler(端口 5432)。

🌐 Once installed, you can find your PSQL string on the dashboard by clicking connect. Make sure if you are using the pooler connection that it is the Session pooler (port 5432).

增加查询超时 #

🌐 Increase the query timeout

然后你可以只为你的会话增加查询超时时间:

🌐 Then you can increase the query timeout solely for your session:

超时很久

🌐 Long timeout

1
set statement_timeout = '120min';

禁用超时

🌐 Disable timeout

1
set statement_timeout = '0';

如果你的任务特别长,你可能想考虑暂时提升你的计算能力。Supabase 的计算资源按小时收费,所以你可以增加一两个小时,加快完成任务,然后再把它缩减回去。

🌐 If your task is particularly long, you can may want to consider boosting your computing power temporarily. Compute size on Supabase is charged by the hour, so you can increase it for an hour or two, complete your task faster, then scale it back afterwards.

如果你想暂时升级,可以在你的 仪表板的附加组件设置 中找到你项目的附加组件。

🌐 If you want to temporarily upgrade, you can find the add-ons for your project in your Dashboard's Add-ons Settings.