Questions tagged [rails-postgresql]

Open source RDBMS (relational database management system) when used in conjunction with the Ruby on Rails framework.

PostgreSQL is an open source object-relational database system that has the features of traditional proprietary database systems with enhancements to be found in next-generation DBMS systems. PostgreSQL is free and the complete source code is available.

This tag should be used for questions about using PostgreSQL within the Ruby on Rails framework, particularly where the solution desired is to be done "the Rails way" as opposed to directly mucking around in SQL and the like.

488 questions
859
votes
43 answers

Can't find the 'libpq-fe.h header when trying to install pg gem

I am using the Ruby on Rails 3.1 pre version. I like to use PostgreSQL, but the problem is installing the pg gem. It gives me the following error: $ gem install pg Building native extensions. This could take a while... ERROR: Error installing pg: …
demonchand
  • 9,861
  • 6
  • 19
  • 25
118
votes
11 answers

How to solve privileges issues when restore PostgreSQL Database

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…
steveyang
  • 8,588
  • 7
  • 48
  • 75
66
votes
15 answers

Postgresql adapter (pg): could not connect to server

I get this error every this I run my Rails app (It cannot connect to my local Postgresql) /Users/leonardo/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-3.2.11/lib/ active_record/connection_adapters/postgresql_adapter.rb:1208:in `initialize': could…
sparkle
  • 6,527
  • 18
  • 58
  • 92
60
votes
4 answers

PostgreSQL date() with timezone

I'm having an issue selecting dates properly from Postgres - they are being stored in UTC, but not converting with the Date() function properly. Converting the timestamp to a date gives me the wrong date if it's past 4pm PST. 2012-06-21 should be…
58
votes
3 answers

Postgres JSON data type Rails query

I am using Postgres' json data type but want to do a query/ordering with data that is nested within the json. I want to order or query with .where on the json data type. For example, I want to query for users that have a follower count > 500 or I…
Mohamed El Mahallawy
  • 11,102
  • 12
  • 44
  • 77
43
votes
4 answers

Batch insertion in rails 3

I want to do a batch insert of few thousand records into the database (POSTGRES in my case) from within my Rails App. What would be the "Rails way" of doing it? Something which is fast and also correct way of doing it. I know I can create the SQL…
36
votes
2 answers

Error when creating unaccent extension on PostgreSQL

I am trying to configure PostgreSQL to use fulltext search in my rails app as mentioned in this Railscast. I am using a fresh Ubuntu 12.04 server running PostgreSQL 9.1.5 installed using apt-get with the ppa:pitti/postgresql with precise. I get the…
29
votes
4 answers

Millisecond resolution of DateTime in Ruby

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…
SRobertJames
  • 6,827
  • 12
  • 48
  • 89
28
votes
3 answers

How to set up Postgres database for local Rails project?

I recently got a new machine and would now like to work on my projects from Github. I'm curious as to how to properly set up the Postgres database on my local machine. I have postgresql, pgadmin3 and libpq-dev installed on Ubuntu (12.04). I pull…
Connor Leech
  • 15,156
  • 27
  • 91
  • 133
22
votes
8 answers

Rails 5 how to clear or delete production postgres database

I am trying to delete a production database so I can start fresh. When I upgraded to rails 5 from rails 4, it is now protecting the production database from accidental deletion. It shows the following error message when I run rake db:reset. /app#…
Scott B
  • 1,348
  • 2
  • 13
  • 25
21
votes
2 answers

Heroku db:push fails with segfault

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…
Steve Upstill
  • 332
  • 4
  • 15
19
votes
4 answers

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

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…
18
votes
2 answers

pghero on PostgresApp pg_stat_statements must be loaded via shared_preload_libraries

I have this error PG::ObjectNotInPrerequisiteState: ERROR: pg_stat_statements must be loaded via shared_preload_libraries on localhost. Using osx (10.9.5), PostgresApp 9.3.1.0 and pghero gem Going to postgresql.conf located in…
Nick Ginanto
  • 26,414
  • 39
  • 123
  • 214
18
votes
3 answers

How can I update a data record's value with Ruby on Rails 4.0.1/PostgreSQL Hstore?

I'm encountering a strange issue that must be user error on my part but can't figure it out. I'm using Ruby 1.9.3-p194, Rails 4.01, PostgreSQL. I have a model, Customer, with a column called data that is a hstore type. For some reason, I am not able…
james
  • 489
  • 6
  • 14
18
votes
1 answer

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

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:…
1
2 3
32 33