我正在尝试将Postgresql Redshift数据库添加到我的Rails 4应用程序中,以便在本地和生产中使用。我首先在开发中测试。
我已将我的database.yml文件更改为如下所示:
development:
adapter: postgresql
encoding: unicode
database: new_db
pool: 5
username: test
password: password
host: test_db.us-east-1.redshift.amazonaws.com
port: 5439
现在,当我点击localhost:3000
时,我收到此错误:
权限被拒绝设置参数" client_min_messages"警告"警告" :SET client_min_messages TO' warning'
我似乎无法找出造成这种情况的原因 - 似乎我的新数据库可能不允许SET命令?我不太确定,但感谢任何帮助。
答案 0 :(得分:1)
刚才在其他地方回答了这个问题,但我今天遇到了同样的问题,这就是我做了什么以及它现在在做什么:
#app/models/data_warehouse.rb
class DataWarehouse < ActiveRecord::Base
establish_connection "redshift_staging"
#or, if you want to have a db per environment
#establish_connection "redshift_#{Rails.env}"
end
请注意,我们在5439上连接,而不是默认的5432,因此我指定了端口 另外,我指定了一个模式,beta,这是我们用于不稳定聚合的模式,您可以在上面提到的每个环境中使用不同的数据库,或者使用各种模式并将它们包含在ActiveRecord的搜索路径中
#config/database.yml
redshift_staging:
adapter: postgresql
encoding: utf8
database: db03
port: 5439
pool: 5
schema_search_path: 'beta'
username: admin
password: supersecretpassword
host: db03.myremotehost.us #your remote host here, might be an aws url from Redshift admin console
###选项2,直接PG连接
class DataWarehouse < ActiveRecord::Base
attr_accessor :conn
def initialize
@conn = PG.connect(
database: 'db03',
port: 5439,
pool: 5,
schema_search_path: 'beta',
username: 'admin',
password: 'supersecretpassword',
host: 'db03.myremotehost.us'
)
end
end
[DEV] main:0> redshift = DataWarehouse
E, [2014-07-17T11:09:17.758957 #44535] ERROR -- : PG::InsufficientPrivilege: ERROR: permission denied to set parameter "client_min_messages" to "notice" : SET client_min_messages TO 'notice'
(pry) output error: #<ActiveRecord::StatementInvalid: PG::InsufficientPrivilege: ERROR: permission denied to set parameter "client_min_messages" to "notice" : SET client_min_messages TO 'notice'>
<强>更新强>
https://github.com/fiksu/activerecord-redshift-adapter
原因1:ActiveRecord postgresql适配器设置client_min_messages 原因2:适配器还尝试设置时区,红移不允许(http://docs.aws.amazon.com/redshift/latest/dg/c_redshift-and-postgres-sql.html) 原因3:即使您在ActiveRecord中更改了前两个错误的代码,您也会遇到其他错误,这些错误抱怨Redshift正在使用Postgresql 8.0,此时我转向适配器,如果我找到更好的东西,将重新访问和更新后面。
#Gemfile:
gem 'activerecord4-redshift-adapter', github: 'aamine/activerecord4-redshift-adapter'
#config/database.yml
redshift_staging:
adapter: redshift
encoding: utf8
database: db03
port: 5439
pool: 5
username: admin
password: supersecretpassword
host: db03.myremotehost.us
timeout: 5000
#app/models/base_aggregates_redshift_test.rb
#Model named to match my tables in Redshift, if you want you can set_table like I have commented out below
class BaseAggregatesRedshiftTest < ActiveRecord::Base
establish_connection "redshift_staging"
self.table_name = "beta.base_aggregates_v2"
end
在控制台中使用self.table_name [DEV] main:0> redshift = BaseAggregatesRedshiftTest.first
D, [2014-07-17T15:31:58.678103 #43776] DEBUG -- : BaseAggregatesRedshiftTest Load (45.6ms) SELECT "beta"."base_aggregates_v2".* FROM "beta"."base_aggregates_v2" LIMIT 1
#app/models/base_aggregates_redshift_test.rb
class BaseAggregatesRedshiftTest < ActiveRecord::Base
set_table "beta.base_aggregates_v2"
ActiveRecord::Base.establish_connection(
adapter: 'redshift',
encoding: 'utf8',
database: 'staging',
port: '5439',
pool: '5',
username: 'admin',
password: 'supersecretpassword',
search_schema: 'beta',
host: 'db03.myremotehost.us',
timeout: '5000'
)
end
#in console, abbreviated example of first record, now it's using the new name for my redshift table, just assuming I've got the record at base_aggregates_redshift_tests because I didn't set the table_name
[DEV] main:0> redshift = BaseAggregatesRedshiftTest.first
D, [2014-07-17T15:09:39.388918 #11537] DEBUG -- : BaseAggregatesRedshiftTest Load (45.3ms) SELECT "base_aggregates_redshift_tests".* FROM "base_aggregates_redshift_tests" LIMIT 1
#<BaseAggregatesRedshiftTest:0x007fd8c4a12580> {
:truncated_month => Thu, 31 Jan 2013 19:00:00 EST -05:00,
:dma => "Cityville",
:group_id => 9712338,
:dma_id => 9999
}
祝你好运!
答案 1 :(得分:0)
你的postgresql版本是什么?还是中间件?它不是原始的postgresql版本?
你可以使用\ set VERBOSITY verbose 然后再次执行,找到@ code引发错误的函数。 然后分析为什么你不能设置client_min_messages。
我使用postgresql 9.3.3没有这个问题。 超级用户和普通用户可以设置client_min_messages正确。
digoal=# \c digoal digoal
You are now connected to database "digoal" as user "digoal".
digoal=> set client_min_messages=debug;
SET
digoal=> set client_min_messages=warning;
SET
digoal=> SET client_min_messages TO 'warning';
SET
digoal=> \c postgres digoal
You are now connected to database "postgres" as user "digoal".
postgres=> SET client_min_messages TO 'warning';
SET
答案 2 :(得分:0)
我能够通过打开Activerecord的postgresql适配器并注释掉所有SET命令来解决问题。
但是,这根本不是最佳做法。在编辑postgresql适配器结束时,由于过时的postgres版本(80002),我遇到了错误。
正确的答案只是更新postgres,遗憾的是,在我位于亚马逊的共享Redshift数据库中,这是不可能的。