rails-postgresql

Heroku + Sidekiq: ActiveRecord::StatementInvalid: PG::UnableToSend: SSL SYSCALL error: EOF detected

余生颓废 提交于 2019-11-30 11:12:31
Hi we are running on Heroku's Cedar stack with Unicorn and Sidekiq. We intermittently get the following errors BurnThis ActiveRecord::StatementInvalid: PG::UnableToSend: SSL SYSCALL error: EOF detected ActiveRecord::StatementInvalid: PG::ConnectionBad: PQconsumeInput() SSL SYSCALL error: Connection timed out Does anyone have any insight what the direct cause of these errors? Is it too many connections to our database? We have our forking set up already in the following way: unicorn.rb worker_processes Integer(ENV["WEB_CONCURRENCY"] || 3) timeout 30 preload_app true before_fork do |server,

How to add sequences to a migration and use them in a model?

限于喜欢 提交于 2019-11-30 11:09:53
I want to have a " Customer " Model with a normal primary key and another column to store a custom "Customer Number". In addition, I want the db to handle default Customer Numbers. I think, defining a sequence is the best way to do that. I use PostgreSQL. Have a look at my migration: class CreateAccountsCustomers < ActiveRecord::Migration def up say "Creating sequenze for customer number starting at 1002" execute 'CREATE SEQUENCE customer_no_seq START 1002;' create_table :accounts_customers do |t| t.string :type t.integer :customer_no, :unique => true t.integer :salutation, :limit => 1 t

Set default value for Postgres JSON column in Rails < 4

旧时模样 提交于 2019-11-30 08:31:24
So I'm starting to use the Postgres JSON datatype, now that there's a lot of fun stuff you can do with it . In one of my Rails apps which is not yet Rails 4 (where support for Postgres JSON has been added ) I added a JSON column like this: create_table :foo do |t| t.column :bar, :json end but I can't figure out how to set a default value for the column. I tried all variations like {} , '{}' , '{}'::json , '[]'::json etc. but I either get an error when the migration runs or it simply doesn't work, meaning the migration runs but, when I create a new Foo , bar is nil . janfoeh Although a bit late

Millisecond resolution of DateTime in Ruby

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-30 04:35:28
I have a string like 2012-01-01T01:02:03.456 that I am storing in a Postgres database TIMESTAMP using ActiveRecord. Unfortunately, Ruby seems to chop off the milliseconds: ruby-1.9.3-rc1 :078 > '2012-12-31T01:01:01.232323+3'.to_datetime => Mon, 31 Dec 2012 01:01:01 +0300 Postgrs supports microsecond resolution. How can I get my timestamp to be saved accordingly? I need at least millisecond resolution. (PS Yes I could hack in a milliseconds integer column in postgres; that kind of defeats the whole purpose of ActiveRecord.) UPDATE: The very helpful responses showed that Ruby's DateTime is not

Heroku db:push fails with segfault

放肆的年华 提交于 2019-11-30 03:09:33
I am installing a new Heroku app for Rails 3.1, Ruby 1.9.2. The problem is in doing 'heroku db:push' to populate the database (which has been duly schematized--the only problem now is getting it some data). It fails with the following report: /Users/upstill/.rvm/gems/ruby-1.9.2-p290/gems/sqlite3-1.3.5/lib/sqlite3/sqlite3_native.bundle: [BUG] Segmentation fault ruby 1.8.7 (2010-01-10 patchlevel 249) [universal-darwin11.0] Abort trap: 6 This is puzzling for two reasons: one, I am using a postgresql database both locally and on heroku (duly declared in config/database.yml). And two, where has

Rails 4.0.1 on Heroku, can't create database

ぃ、小莉子 提交于 2019-11-30 01:13:08
I can't get rake db:migrate to run on my rails 4.0.1 app on Heroku. I'm guessing that I don't have postgres configured properly... but reading the docs on heroku hasn't really helped and I'm not sure what to do. I don't know too much about heroku or postgres. Any help or resources would be greatly appreciated. Let me know if there's anything else I can post. (Also, I'm using devise, if that matters) When I run heroku run rake db:migrate I get this: Running `rake db:migrate` attached to terminal... up, run.5077 PG::UndefinedTable: ERROR: relation "users" does not exist LINE 5: WHERE a.attrelid

Calendar tables in PostgreSQL 9

半腔热情 提交于 2019-11-29 05:57:27
I am building an analytics database (I have a firm understanding of the data and the business objectives and only basic-to-moderate database skills). I have come across some references to building similar warehouses which implement the concept of 'calendar tables'. This makes sense and is easily enough done. Most examples I see, however, are calendar tables that limit scope to 'day'. My data will need to be analyzed down to hour-level. Possibly minutes. My question: would an implementation of calendar tables for hour/minute-level granularity be of value in terms of space-efficiency and query

Heroku Rails could not fork new process for connection: Cannot allocate memory

Deadly 提交于 2019-11-29 05:49:00
I have 3 Rails applications that all use the same code base. 2/3 of the applications are running fine, but one of them gives me this error: could not fork new process for connection: Cannot allocate memory Upon trying to look at the Postgres logs, it is a little more specific: psql: bin//psql-9.2.1-64bit pv: bin//pv-1.1.4-64bit psql-9.2.1-64bit: could not fork new process for connection: Cannot allocate memory could not fork new process for connection: Cannot allocate memory could not fork new process for connection: Cannot allocate memory bin/brie: line 146: [: : integer expression expected

Millisecond resolution of DateTime in Ruby

六月ゝ 毕业季﹏ 提交于 2019-11-29 02:24:10
问题 I have a string like 2012-01-01T01:02:03.456 that I am storing in a Postgres database TIMESTAMP using ActiveRecord. Unfortunately, Ruby seems to chop off the milliseconds: ruby-1.9.3-rc1 :078 > '2012-12-31T01:01:01.232323+3'.to_datetime => Mon, 31 Dec 2012 01:01:01 +0300 Postgrs supports microsecond resolution. How can I get my timestamp to be saved accordingly? I need at least millisecond resolution. (PS Yes I could hack in a milliseconds integer column in postgres; that kind of defeats the

How to solve privileges issues when restore PostgreSQL Database

拥有回忆 提交于 2019-11-28 16:27:23
I have dumped a clean, no owner backup for Postgres Database with the command pg_dump sample_database -O -c -U Later, when I restore the database with psql -d sample_database -U app_name However, I encountered several errors which prevents me from restoring the data: ERROR: must be owner of extension plpgsql ERROR: must be owner of schema public ERROR: schema "public" already exists ERROR: must be owner of schema public CREATE EXTENSION ERROR: must be owner of extension plpgsql I digged into the plain-text SQL pg_dump generates and I found it contains SQL CREATE SCHEMA public; COMMENT ON