教Rails 3与Amazon Redshift交谈 - 权限被拒绝设置参数“client_min_messages”

时间:2015-01-21 21:30:51

标签: ruby-on-rails ruby-on-rails-3 postgresql amazon-redshift

背景

我刚在AWS上创建了一个新的Redshift实例,我可以通过psql cli客户端连接到它,没有问题。

问题

我正在尝试将我的Rails 3应用程序连接到Redshift框。我有pg gem和正确的适配器。我的database.yml文件包含以下详细信息:

redshift_development:
  adapter: postgresql
  encoding: utf8
  database: db_name
  port: 5439
  pool: 5
  schema_search_path: schema_name
  username: my_uname
  password: password
  host: host

我手动在名为cellphones的框中创建了一个表格,并在我的应用app/models/cellphone.rb中创建了一个模型:

class Cellphone < ActiveRecord::Base
  establish_connection 'redshift_development'
end

当我尝试在rails控制台中加载应用程序并调用Cellphone时,收到以下错误消息:

[1] pry(main)> Cellphone
PG::InsufficientPrivilege: ERROR:  must be superuser to examine "client_min_messages"
: SHOW client_min_messages
PG::InsufficientPrivilege: ERROR:  permission denied to set parameter "client_min_messages" to ""
: SET client_min_messages TO ''
=> #<Devise::Models:0x3feef95050b4>

真正奇怪的部分

我已经以超级用户身份登录。

psql=# \c
psql (9.4.0, server 8.0.2)
SSL connection (<unimportant stuff>)
You are now connected to database "db_name" as user "my_uname".

psql=# \du
                     List of roles
 Role name |          Attributes           | Member of
-----------+-------------------------------+-----------
 rdsdb     | Superuser, Create DB         +|
           | Password valid until infinity |
 my_uname  | Superuser, Create DB          |

我该如何解决这个问题?


可选信息

出现此问题是因为Redshift是旧PostgreSQL版本的高度自定义分支。允许无用户致电show client_min_messages。随Rails 3.2.14一起提供的activerecord版本试图在引擎盖下调用此函数(以及Redshift不允许的其他一些函数)。

我会非常惊讶地发现AWS没有针对Rails应用程序的正式解决方法。目前我正在使用我修改的activerecord Postgres适配器版本来删除有问题的代码 - 但我真的而不是在生产中使用它。

1 个答案:

答案 0 :(得分:0)