Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/EmptyTag/133.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql 设置pg_trgm的默认限制_Postgresql_Full Text Search - Fatal编程技术网

Postgresql 设置pg_trgm的默认限制

Postgresql 设置pg_trgm的默认限制,postgresql,full-text-search,Postgresql,Full Text Search,这似乎是一个非常基本的问题,但如何更改pg_trgm扩展的默认限制?目前为0.3。我已经做了: select set_limit(0.5) select show_limit() => 0.5 关闭连接,然后重新连接: select show_limit() => 0.3 感谢您的帮助。这可能不是解决方案,而是对潜在解决方案的贡献 (我假设您希望将pg_trgm参数用于DB的所有连接,而不仅仅是交互式连接?) 默认的0.3限值似乎是在函数中硬编码的: trgm_op.c:

这似乎是一个非常基本的问题,但如何更改pg_trgm扩展的默认限制?目前为0.3。我已经做了:

select set_limit(0.5)
select show_limit() => 0.5
关闭连接,然后重新连接:

select show_limit() => 0.3

感谢您的帮助。

这可能不是解决方案,而是对潜在解决方案的贡献

(我假设您希望将pg_trgm参数用于DB的所有连接,而不仅仅是交互式连接?)

默认的0.3限值似乎是在函数中硬编码的:

trgm_op.c:

    PG_MODULE_MAGIC;

float4          trgm_limit = 0.3f;

我不确定它是否可以通过任何配置文件进行控制,因此一个选项是更改源文件中的默认值,并重新构建扩展。

在Ruby on Rails环境中查找如何执行此操作时,偶然发现了这一点。最终猴子修补了我的适配器:

require 'active_record/connection_adapters/postgresql_adapter'

class ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
private
  alias_method :default_configure_connection, :configure_connection

  # Monkey patch configure_connection because set_limit() must be called on a per-connection basis.
  def configure_connection
    default_configure_connection
    begin
        execute("SELECT set_limit(0.1);")
    rescue ActiveRecord::StatementInvalid
        Rails.logger.warn("pg_trgm extension not enabled yet")
    end
  end
end

在看到其他人有这个问题后,我们走了这条路线,例如,自Postgres 9.6以来,
pg_-trgm
使用了大统一配置(GUC)系统,因此可以在集群级别设置默认值,在
postgresql.conf
中添加
pg_-trgm.similarity\u阈值=0.5
,或者在DB级别设置默认值(
alter database myDB set pg_trgm.similarity_threshold=0.5
)或GUC允许的所有其他级别(每个用户、每个函数等)

我也遇到了同样的问题,你解决了吗?为什么会将其标记为答案?这只是一个提示。因为Postgres 9.6,所以请参阅: