Tag: postgresql

连接被拒绝(PGError)(postgresql和rails)

当我尝试使用“$ rails s”运行我的localhost时,我一直收到此错误: (Mac OSX 10.8.3)(ruby 2.0.0p195(2013-05-14修订版40734)[x86_64-darwin12.3.0])(Rails 3.2.11)(psql(PostgreSQL)9.2.2)**用自制软件安装 我一直在做很多卸载postgresql并重新安装,所以我有预感,某些地方可能存在冲突的库……我只是不知道从哪里开始。 我在同一个文件夹中安装了Postgresql 9.1和9.2,只是将9.1移到垃圾箱中。 这是我在终端中运行“rails s”时的输出 Danny$ rails s ^[b=> Booting Thin => Rails 3.2.11 application starting in development on http://0.0.0.0:3000 => Call with -d to detach => Ctrl-C to shutdown server Exiting /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.11/lib/active_record/connection_adapters/postgresql_adapter.rb:1208:in `initialize’: could not connect to server: Connection refused (PGError) Is the server running on […]

查询包含JSON对象数组的jsonb列

我使用PostgreSQL 9.5和Rails 5.我想查询下面显示的jsonb列,它包含一个JSON对象数组,以返回包含{“kind”:”person”}所有JSON数组元素,并执行计数。 我使用的SQL显示在json数据下面。 运行查询只返回一个空数组。 我已经尝试了这里和这里建议的查询。 这就是我的jsonb数据: ‘[ {“kind”:”person”, “filter_term”:”56″,”selected_attr”:”customer”}, {“kind”:”email”, “filter_term”:”marketer”,”selected_attr”:”job_title”} ]’ 我想要一个sql查询返回: data ———————————————————————- ‘{“kind”:”person”, “filter_term”:”56″,”selected_attr”:”customer”}’ (1 row) 和另一个返回数组的查询,以便我可以在我的应用程序中调用count并在其上循环以创建表单: data ———————————————————————- ‘[{“kind”:”person”, “filter_term”:”56″,”selected_attr”:”customer”}]’ (1 row) 我试过这个SQL查询: “SELECT * FROM \”segments\” WHERE (payload @> ‘[{\”kind\”:\”person\”}]’)” 我也试过这个查询: “SELECT payload FROM segments WHERE payload @> ‘[{\”kind\”:\”person\”}]’::jsonb;” 这是第三个查询: “SELECT * FROM segments s WHERE s.payload->’\”#{a}\”‘ @> ‘[{\”kind\”:\”person\”}]’;” […]

Heroku上的Postgres错误与Resque

我不太了解Postgres了解这条消息。 PG::Error: SSL error: decryption failed or bad record mac : SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull FROM pg_attribute a LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum WHERE a.attrelid = ‘”users”‘::regclass AND a.attnum > 0 AND NOT a.attisdropped ORDER BY a.attnum 这是来自resque后端的callstack /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.2/lib/active_record/connection_adapters/postgresql_adapter.rb:1139:in `async_exec’ /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.2/lib/active_record/connection_adapters/postgresql_adapter.rb:1139:in `exec_no_cache’ /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.2/lib/active_record/connection_adapters/postgresql_adapter.rb:663:in `block in exec_query’ […]

Postgres排序问题

我想通过评级DESC来排序。 它适用于MySQL,但适用于PostgreSQL。 我得到了不同的结果。 你可以在这里看到问题: http : //www.vinderhimlen.dk/konkurrencer 我的控制器: def sort_column Konkurrancer.column_names.include?(params[:sort]) ? params[:sort] : “rating” end def sort_direction %w[desc asc].include?(params[:direction]) ? params[:direction] : “desc” end

SQLite在开发中,PostgreSQL在生产中 – 为什么不呢?

由于可能的问题,Heroku建议不要这样做。 我是一个SQL菜鸟,你能解释一下使用不同数据库可能遇到的问题类型吗?

rails postgres适配器支持ssl?

我正在尝试配置rails应用程序以远程连接到postgres数据库。 我注意到mysql的连接适配器有选项,指定设置ssl连接所需的信息,但postgres / pg适配器没有等效的选项。 谷歌搜索后,我也找不到任何东西(只通过ssh隧道连接)。 这么简单,试图让rails postgres适配器通过ssl连接死路? 谢谢。 任何帮助或方向表示赞赏。 -H

如何制作ActiveRecord ThreadSafe

如何使用postgresql在rails 4中创建以下控制器线程安全: def controller_action if Model.exists(column_name:”some_value”) else @model=Model.new(column_name:”some_value”) @model.save end end 我正在运行puma,所以我担心的是,如果两个线程同时运行此控制器,并且不存在具有指定值column_name的行,则将创建两个记录,而我只想要1。

Rails 3.1:在一个时间范围内查询Postgres的记录

在我的应用程序中,我有一个Person模型。 每个Person都有一个属性time_zone ,用于指定其默认时区。 我也有一个Event模型。 每个Event都有一个start_time和end_time时间戳,以UTC时间保存在Postgres数据库中。 我需要创建一个查询,查找特定人员在一天的午夜和下一个午夜之间的事件。 @todays_events控制器变量保存查询结果。 我采用这种方法的部分原因是我可能让其他时区的人查看一个人的事件列表。 我希望他们看到这一天,因为这个人会看到这一天,而不是基于他们作为观察者所在的时区。 无论出于何种原因,我仍然在前一天的@todays_events.结果集中收到一些事件@todays_events. 我的猜测是我将UTC时间戳与非UTC参数进行比较,或者沿着那些线进行比较。 通常,只有在前一天晚上开始或结束的事件才会显示在今天的查询结果列表中。 现在,我正在建立: @today = Time.now.in_time_zone(@person.time_zone).midnight.to_date @tomorrow = (@today + 1.day ).to_datetime @today = @today.to_datetime 我的查询看起来像: @todays_activities = @person.marks.where(“(start_time >= ? AND start_time = ? AND end_time < ?);", @today, @tomorrow, @today, @tomorrow ).order("start_time DESC") 我应该如何改变这一点,以便我保证只收到今天的结果(根据@todays_activities查询中的@person.time_zone @todays_activities ?

如何使用活动记录在多个级别中搜索json类型的postgres

我有下面的json :response_body => { “status” => “ok”, “um” => { “a” => “a”, “b” => { “c” => “ok” } } 实现我的搜索: LogService.where(response_body: {“status” => “ok”})

在Heroku,Cedar,与Unicorn:获取ActiveRecord :: StatementInvalid:PGError:SSL SYSCALL错误:检测到EOF

Heroku支持称这与他们在共享数据库上的libssl版本有关,但我们也在一个专用数据库上的项目中遇到过它。 基本上这个错误经常发生(接近部署之后)我们已经转移到新的Cedar堆栈,而Unicorn配置为3个工作人员: 错误信息: ActiveRecord::StatementInvalid: PGError: SSL SYSCALL error: EOF detected : SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull FROM pg_attribute a LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum WHERE a.at Where: some_controller#index [PROJECT_ROOT]/vendor/bundle/ruby/1.9.1/gems/activerecord-3.0.11/lib/active_record/connection_adapters/postgresql_adapter.rb, line 505 没有heroku的答案,但也许等待谁知道我们升级我们的共享数据库服务器*多久,我没有在谷歌上找到任何东西。 他们还建议它与独角兽的工人重叠有关,我们应该切换到Thin,但性能提升非常值得偶尔出错(我想!)。 我希望有一种方法可以配置Unicorn以防止重叠。 有没有人遇到过这个,如果有的话,你做了什么来解决它? 谢谢! *不是他们的实际用语,而是他们回答后的感受。