- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试设置 statement_timeout。我在 database.yml
中尝试了这两种设置像这样的文件
variables:
statement_timeout: 1000
ActiveRecord::Base.connection.execute("SET statement_timeout = 1000")
ActiveRecord::Base.connection.execute("select pg_sleep(4)")
最佳答案
我无法使用以下方法在本地复制此问题:Postgresql 9.4.26。但是分享我尝试过的内容以及围绕服务器问题的一些想法可能会很有用。
这是我尝试过的(有用的一点可能是从 rails 验证 PG 版本的查询):
# Confirming I am executing against 9.4.x PG:
irb(main):002:0> ActiveRecord::Base.connection.execute("select version()")
(10.8ms) select version()
=> #<PG::Result:0x00007ff74782e060 status=PGRES_TUPLES_OK ntuples=1 nfields=1 cmd_tuples=1>
irb(main):003:0> _.first
=> {"version"=>"PostgreSQL 9.4.26 on x86_64-apple-darwin18.7.0, compiled by Apple clang version 11.0.0 (clang-1100.0.33.17), 64-bit"}
# Set timeout:
irb(main):004:0> ActiveRecord::Base.connection.execute("SET statement_timeout = 1000")
(0.4ms) SET statement_timeout = 1000
=> #<PG::Result:0x00007ff7720a3d88 status=PGRES_COMMAND_OK ntuples=0 nfields=0 cmd_tuples=0>
# Confirm it works - it is ~1s and also stacktrace is pretty explicit about it:
irb(main):005:0> ActiveRecord::Base.connection.execute("select pg_sleep(4)")
(1071.2ms) select pg_sleep(4)
.... (stacktrace hidden)
ActiveRecord::StatementInvalid (PG::QueryCanceled: ERROR: canceling statement due to statement timeout)
: select pg_sleep(4)
这是尝试的内容
statement_timeout
适用于其他次要版本和本地,我想到的一件事是缺乏更新权限
statement_timeout
从哪里尝试。也许用于建立数据库连接的 rails pg login 不允许更新该设置。
irb(main):004:0> ActiveRecord::Base.connection.execute("SET statement_timeout = 1000")
irb(main):004:0> irb(main):003:0> ActiveRecord::Base.connection.execute("show statement_timeout").first
(0.2ms) show statement_timeout
=> {"statement_timeout"=>"1s"}
或者,它可以通过 psql 控制台直接检查(某些部署也允许这样做):
psql myserveruser # if this was heroku's pg: heroku pg:psql
postgres=# set statement_timeout = 1000;
SET
postgres=# select pg_sleep(4);
ERROR: canceling statement due to statement timeout
Time: 1068.067 ms (00:01.068)
其他要记住的事情(取自
https://dba.stackexchange.com/a/83035/90903 ):
The way statement_timeout works, the time starts counting when theserver receives a new command from the client...
And if a function does SET statement_timeout = 100; it will have an effect only starting atthe next command from the client.
关于ruby-on-rails - Rails 4.2 Postgres 9.4.4 statement_timeout 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53160535/
当我的网络用户突然激增时,一些语句开始无限期地排队,即使我设置了超时,如: SET STATEMENT_TIMEOUT TO 5000; SELECT get_user_properties(1234
我想设置 postgres statement_timeout对于个人迁移。我似乎无法做到这一点。这是我的实验: def change execute <<~SQL SET LOCAL s
我有一个需求,在postgresql中指定的时间限制内执行查询操作。如果查询没有在那个时间限制内执行,我们需要捕获一个异常/一个 Action ,并且需要杀死所有其他阻止这个查询操作发生的操作,然后执
假设我有: untimedStatement = connection.createStatement() ; timedStatement = connection.createStatement(
在事务模式下使用 pgBouncer 似乎是在任何给定时间减少事件连接数的最佳方式,但它也带来了一个我不确定如何有效解决的问题。 假设您希望在数据库级别设置 5 分钟的 statement_timeo
在事务模式下使用 pgBouncer 似乎是在任何给定时间减少事件连接数的最佳方式,但它也带来了一个我不确定如何有效解决的问题。 假设您希望在数据库级别设置 5 分钟的 statement_timeo
我正在使用 Django 1.10 和 PostgreSQL 数据库。我想弄清楚我是否可以从 Django 设置 statement_timeout。似乎我不能像 connect_timeout 那样
我们可以为 Client 设置 2 个超时时间: statement_timeout : 查询语句超时前的毫秒数,默认不超时 query_timeout查询调用超时前的毫秒数,默认为无超时 我是这样理
我为我的 Postgres 数据库中的用户将 statement_timeout 设置为 10000(10 秒)。但是,当我查看 pg_stat_activity 中的事件查询时,我发现查询运行了超过
是否可以为 db (Postgres) 设置 statement_timeout 仅用于 Ruby on Rails 中的 web 查询(vs sidekiq workers/jobs)?原因是 He
我已经在 database.yml 中将我的 statement_timeout 配置为几秒钟,但是我的应用程序中有一些昂贵的查询,需要更长的查询执行时间。在每个查询级别上实现此目标的推荐方法是什么?
我正在尝试设置 statement_timeout。我在 database.yml 中尝试了这两种设置像这样的文件 variables: statement_timeout: 1000 和这个 A
我是一名优秀的程序员,十分优秀!