gpt4 book ai didi

sql - 同时创建唯一索引超时

转载 作者:行者123 更新时间:2023-11-29 13:58:30 27 4
gpt4 key购买 nike

我正在尝试在我的生产箱上的表格上创建唯一索引。为此:

  1. 已创建表 TABLE1 和 COLUMN1

  2. 在我的生产数据库(即 Postgres)上运行以下命令

     Create UNIQUE INDEX CONCURRENTLY idx_id_unique on TABLE1(COLUMN1)

这是抛出错误(一段时间后):

2014-10-07 20:46:49.056 EDT ERROR: cancelling statement due to statement timeout

2014-10-07 20:46:49.056 EDT STATEMENT: Create UNIQUE INDEX CONCURRENTLY idx_id_unique on TABLE1(COLUMN1)

我的问题是:

  1. 超时失败的可能原因是什么?注意:由于这是生产数据库服务器,我们有数以千计的多个查询/事务同时运行,所以这个 CREATE INDEX.... 将需要大量时间。但是,这个查询仍然会抛出超时异常吗?
  2. Postgres 是否会同时为 CREATE UNIQUE INDEX 抛出语句超时错误?由于此查询需要多个小时才能完成大型表。
  3. 可能的解决方法是什么?

最佳答案

What could be the probable reasons for this timeout failure? Note: As this is production DB server, we have thousands of multiple queries/transactions running concurrently so this CREATE INDEX.... will require a significant amount of time. But still, will this query throw timeout exception?

好吧,它告诉您:由于语句超时而取消语句。所以,是的。

  1. Does POSTGRES throw statement timeout error for CREATE UNIQUE INDEX CONCURRENTLY? As this query requires multiple hours to finish for large tables.

是的,它只是告诉你了。

  1. What could be the probable workaround for this?

增加创建索引的 session 的语句超时限制?


编辑:添加手册链接

有关 statement_timeout 的详细信息在手册中:http://www.postgresql.org/docs/current/static/runtime-config-client.html#GUC-STATEMENT-TIMEOUT

同样如何设置配置设置也是:http://www.postgresql.org/docs/current/static/sql-set.html

我对您正在使用的这个 TransactionTemplate 东西一无所知,但谷歌建议它有文档。如果没有别的,大概有一些方法可以通过它发出原始 SQL。


顺便说一句,如果您:

  1. 仔细阅读提供的错误消息。
  2. 至少对所用软件的手册有一定的了解。
  3. 可以通过谷歌或内置搜索来搜索 #1 和 #2。

关于sql - 同时创建唯一索引超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26650882/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com