Tag: postgresql 9.2

Postgresql“没有pg_hba.conf条目”错误

我正在为一个rails项目(我正在加入)设置我的本地postgresql数据库,并完成了以下操作: 安装postgres 添加/捆绑’pg’gem 创建名为“foobar”的db用户 创建了一个名为“foobar_development”的数据库 rails应用程序附带了rake db:migrate任务。 当我运行此任务时,我得到以下错误输出: FATAL: no pg_hba.conf entry for host “::1”, user “foobar”, database “foobar_development”, SSL off 我在以下位置找到了一个pg_hba.conf文件: 在/ usr /本地的/ var / Postgres的 这是pg_hba.conf文件的相关部分: # TYPE DATABASE USER ADDRESS METHOD # “local” is for Unix domain socket connections only local all all trust # IPv4 local connections: host all all […]

使用Postgres安装最新版本的Rails 4 – 不推荐使用PGconn,PGresult和PGError常量

我无法在Google上找到此警告,因此请求Stackowerflower的帮助。 我想在新的Centos 7盒子上安装Rails 4.2.8。 Postgres版本是9.2.18。 Ruby版本是2.3.4。 安装Rails时,我像往常一样配置config / database.yml文件,并且非常确定database.yml文件可以成功连接到DB。 Postgres已经成功运行其他应用程序,并为此应用程序创建了新的角色。 在下一步中,存在一个实际问题: [user@server dir]$ rake db:setup The PGconn, PGresult, and PGError constants are deprecated, and will be removed as of version 1.0. You should use PG::Connection, PG::Result, and PG::Error instead, respectively. Called from /home/user/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/activesupport-4.2.8/lib/active_support/dependencies.rb:240:in `load_dependency’ /home/rent/apps/rent/db/schema.rb doesn’t exist yet. Run `rake db:migrate` to create it, then […]

Unicorn不关闭数据库连接

我正在使用rails 3.2 + unicorn + postgres DB,我有一个问题 – 独角兽如何处理数据库连接? 我的理解: 独角兽主进程分叉X子进程。 每个子进程设置DB连接 – 在before_fork中关闭,在after_fork中建立连接。 我们使用每个进程的连接(如果我们使用rails DB连接池,我们创建Y(来自database.yml)每个进程的DB连接) – 即如果进程正在工作(它始终有效,直到我们不杀死它)我们保持连接打开并且每个Web请求使用相同的连接(在after_fork中打开)。 打开的连接将在postgres(或任何其他数据库)中显示为空闲或活动。 这是正确的还是我错过了什么?

Postgres查询包含内容的JSON数组

Postgres有这个JSON数据类型,我想知道如何在JSON数组中查询数据? 我正在使用Postgres 9.3.1 我已插入到PUBLISHER表中,其中包含以下两个字段的名称:string和data:json INSERT INTO PUBLISHER (name, data) VALUES (‘PUB1’, [{“code”:”PA1″,”author”:”James”,”type”:”Novel”},{“code”:”PA2″,”author”:”John”,”type”:”Science”}] INSERT INTO PUBLISHER (name, data) VALUES (‘PUB2’, [{“code”:”PA1″,”author”:”Dickens”,”type”:”Novel”},{“code”:”PA2″,”author”:”Tom”,”type”:”Comic”}] 我想查询并列出“Novel”类型的作者。 在这种情况下,应该是输出的“詹姆斯”和“汤姆”。 这种查询的东西: select name, authorfromdata from publisher where data->type is “Novel”

rails如何正确地“更新”多个列 – (updated_at也应该更新)

我无法使用rails activerecords正确更新多个列。 我想使用像更新基本上更新updated_at的东西,但我不能通过多列。 我可以使用update_all但它不会使用当前时间戳更新updated_at。 这就是我想要的: 这不起作用:(只接受payment_total但不接受其余部分) retval = @invoice.update(:payment_total => 20, :due_amount => 10, :data => clonedata.to_json) :data – this is actually a json field 输出: nothing 这工作: retval = Invoice.where(:id => @invoice.id).update_all(:payment_total => 20, :due_amount => 10, :data => clonedata.to_json) 输出:(注意它没有更新“updated_at”字段) SQL(1.1ms)UPDATE“发票”SET“payment_total”= ’30 .00’,“due_amount”= ’86 .00’,“data”='{“名称”:“测试}’WHERE”发票“。”id“= 6 单个参数可以工作: retval = @invoice.update(:payment_total => 20) 输出: […]

连接被拒绝(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 […]

无法在postgresql(rails)中的json字段中存储数组,无法将数组转换为json

这是我运行db:migrate时遇到的错误 rake aborted! can’t cast Array to json 这是我的桌子 class CreateTrips < ActiveRecord::Migration def change create_table :trips do |t| t.json :flights t.timestamps end end end 这是在我的seeds.rb文件中 flights = [{ depart_time_hour: 600, arrive_time_hour: 700, passengers: [ { user_id: 1, request: true } ] }] trip = Trip.create( { name: ‘Flight’, flights: flights.to_json } ) 出于某种原因,我不能这样做。 如果我这样做 […]

Ruby:输出续集模型关联

我不认为只使用Sequel模型是可能的,但我想做的是让我的父模型( 作者 )在我做Author.to_json这样的事情时输出它的子模型( Book )。 这是我的代码: require ‘sequel’ require ‘json’ db = Sequel.connect(‘postgres://localhost/testing’); class Sequel::Model self.plugin :json_serializer end class Author < Sequel::Model(:author) one_to_many :book, key: :author_id, primary_key: :id def get_author Author.each do |e| books = Array.new e.book.each do |f| books.push(f.values) end e.values[:books] = books puts JSON.pretty_generate(e.values) end end end class Book < Sequel::Model(:book) end author […]