will_paginate, Rails 4.1.1 pg error with count - postgresql

I receive this error:
Completed 500 Internal Server Error in 73ms
2014-06-24T16:23:01.334241+00:00 app[web.1]: Processing by CollectionsController#index as HTML
2014-06-24T16:23:01.409751+00:00 app[web.1]: PG::SyntaxError: ERROR: syntax error at or near "as"
2014-06-24T16:23:01.409757+00:00 app[web.1]: LINE 1: ...T(collections.*, count(favorites.favoriteable_id) as "collec...
2014-06-24T16:23:01.409760+00:00 app[web.1]: ^
2014-06-24T16:23:01.409763+00:00 app[web.1]: : SELECT COUNT(collections.*, count(favorites.favoriteable_id) as "collection_count") AS count_collections_all_count_favorites_favoriteable_id_as_collec, collections.id AS collections_id FROM "collections" INNER JOIN "favorites" ON "favorites"."favoriteable_id" = "collections"."id" AND "favorites"."favoriteable_type" = 'Collection' GROUP BY collections.id
2014-06-24T16:23:01.410758+00:00 app[web.1]: Rendered collections/index.html.erb within layouts/application (63.4ms)
When running this:
#collections = Collection.joins(:favorites).select('collections.*, count(favorites.favoriteable_id) as "collection_count"').group("collections.id").order('collection_count desc').paginate(:page => params[:page], :per_page => 12)
Here is the relevant parts of my Gemfile:
gem 'rails', '4.1.1'
gem 'will_paginate', '~> 3.0'
gem 'will_paginate-bootstrap'
I'm aware of this discussion https://github.com/Casecommons/pg_search/issues/167
as well as this stackoverflow question Rails 4.1.1 w/ pg_search - "PG::SyntaxError: ERROR: syntax error at or near "AS"" Bug
I believe I am experiencing the same or related issue but I am not using the .count activerecord method but rather writing some custom SQL to get a count. So, I'm not sure how I could mirror their fix to fix my situation. They say that calling .count(:all) instead of just .count fixed their problem.
If you need anymore information, please ask.
Thanks!
**** Update ****
When I remove pagination the server no longer crashes. This is expected but thought I would still add the update. Obviously, I would like to fix the error but still have pagination.

Related

Upgrading gitlab to version higher than 13.1.11

We are upgrading our GITLAB to version higher than 13.1.11, but we are facing DB related issues in proceeding with same.
DB migrations are not getting completed.
ERROR :
LINE 5: daterange(start_date, due_date, '[]') WITH &&
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
/opt/gitlab/embedded/service/gitlab-rails/db/migrate/20200515153633_iteration_date_range_constraint.rb:7:in `up'
/opt/gitlab/embedded/bin/bundle:23:in `load'
/opt/gitlab/embedded/bin/bundle:23:in `<main>'
We are not able to proceed since migrations are not getting completed. We have installed btree_gist after that we are getting these errors.

HTTP error 500 when trying to go to localhost/phpmyadmin on centos 8

when I'm trying to go to localhost/phpmyadmin then I'm getting HTTP error 500.i have installed PHP, PHP-MySQL, MySQL,apache...please help me to solve this problem.
Check your log
if you have this error
PHP Fatal error: Uncaught Error: Call to a member function getCookie() on null in /usr/share/phpmyadmin/libraries/classes/Url.php:217
Try to install php-json package
I hope this can be useful.

Meteor app crashes periodically with a Mongo error

Meteor app crashes every two-three minutes with this error:
TypeError: Error.captureStackTrace is not a function
at Error.MongoError (/Users/alex/.meteor/packages/npm-mongo/.1.5.45.1i7w6an++os+web.browser+web.cordova/npm/node_modules/mongodb-core/lib/error.js:13:9)
at Function.MongoError.create (/Users/alex/.meteor/packages/npm-mongo/.1.5.45.1i7w6an++os+web.browser+web.cordova/npm/node_modules/mongodb-core/lib/error.js:29:11)
at Socket.<anonymous> (/Users/alex/.meteor/packages/npm-mongo/.1.5.45.1i7w6an++os+web.browser+web.cordova/npm/node_modules/mongodb-core/lib/connection/connection.js:161:20)
at Socket.g (events.js:260:16)
at emitNone (events.js:67:13)
at Socket.emit (events.js:166:7)
at Socket._onTimeout (net.js:332:8)
at _runOnTimeout (timers.js:524:11)
at _makeTimerTimeout (timers.js:515:3)
at Timer.unrefTimeout (timers.js:584:5)
This started after I updated my project to Meteor 1.4. Is Meteor doing something in the background? How can I debug it to find out what's going on?
Additional details: I'm using React, react-router and reactrouter:react-router-ssr. So there is server side rendering. Maybe this will trigger something...
Guys. The most important detail as I see it is this:
Error.captureStackTrace is not a function
This is a core node function! If I run node and enter Error I see the function: captureStackTrace: [Function: captureStackTrace]. So the issue looks like Meteor is maybe running an older version of node that doesn't have captureStackTrace in Error yet? Well, I followed the instructions here to check the version:
MonsterMac:/ alex$ cd ~/.meteor/packages/meteor-tool/1.4.0-1/mt-os.osx.x86_64/dev_bundle/bin/
MonsterMac:bin alex$ ./node -v
v4.4.7
According to the Change log captureStackTrace is there in version 4.4.7. Now what?
Meteor uses node 4.4.7. Also, with Meteor 1.4, Mongo is updated to a newer version. To resolve this error, try meteor reset. This will refresh Mongo to the latest version, when you start meteor next.

ERROR: attempt to redefine parameter "postgis.backend"

I just install "SFCGAL". When I use "ST_3DIntersection", It get below error:
ERROR: attempt to redefine parameter "postgis.backend" SQL state:
XX000
How can I fix?
I already saw http://postgis.net/docs/postgis_installation.html, but I do not know how should I do.
SFCGAL require to at least CGAL (Geospatial Data Abstraction Library) 4.1 and I already dose not install that. It has provided on : http://trac.osgeo.org/gdal/wiki/DownloadSource

Sinatra App on Heroku ActiveRecord::StatementInvalid: PGError: ERROR:

SCENARIO:
I currently have anapplication on Heroku that is Sinatra Application + ActiveRecord. What currently works:
• I am able to view static pages of my site
• I am able to run migrations
• I am able to push my local development db to my Heroku DB (heroku db:push postgres://localhost/dev)
• I am able to pull from the Heroku DB down to my localhost DB (heroku db:pull postgres://localhost/dev)
THE ERROR:
When I navigate to a page that makes a simple query like:
#pics = Picture.find(:all)
I get this error in my log file
DEBUG -- : NoMethodError: undefined method `values' for #<PGresult:0x00000002844098>: SHOW client_min_messages
DEBUG -- : PGError: ERROR: invalid value for parameter "client_min_messages": ""
: SET client_min_messages TO ''
ActiveRecord::StatementInvalid - PGError: ERROR: invalid value for parameter "client_min_messages": ""
/app/.bundle/gems/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/connection_adapters/postgresql_adapter.rb:592:in `async_exec'
At this point I'm not sure what is wrong so I decided to log onto the heroku console and run this command to see if my tables are in the DB
> heroku console
> ActiveRecord::Base.connection.tables
AND I get a similar errors
ActiveRecord::StatementInvalid: PGError: ERROR: invalid value for parameter "client_min_messages": ""
: SET client_min_messages TO ''
/app/.bundle/gems/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/connection_adapters/postgresql_adapter.rb:592:in `async_exec'
/app/.bundle/gems/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/connection_adapters/postgresql_adapter.rb:592:in `block in execute'
/app/.bundle/gems/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/connection_adapters/abstract_adapter.rb:244:in `block in log'
/app/.bundle/gems/ruby/1.9.1/gems/activesupport-3.1.3/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
Then I decided to try this in the console...
> ActiveRecord::Base.establish_connection
> ActiveRecord::AdapterNotSpecified: ActiveRecord::AdapterNotSpecified
/app/.bundle/gems/ruby/1.9.1/gems/activerecord-3.1.3/lib/active_record/connection_adapters/abstract/connection_specification.rb:54:in `establish_connection'
/home/heroku_rack/lib/console.rb:158:in `block (2 levels) in <top (required)>'
/home/heroku_rack/lib/console.rb:148:in `eval'
/home/heroku_rack/lib/console.rb:148:in `_eval'
At this point it would seem that I have no tables and adapter connection but how can that be when I'm able to run migrations and push and pull from the Heroku DB?
UPDATE 1 - NOT MUCH FURTHER ALONG BUT MORE INSIGHT
So I decided to start from scratch and do this over again. I seem to have made some progress but I'm stuck. At re-ran my scenario I mentioned above and succeed. So my database, migration and data are all in the DB. But my app still cannot connect to the DB. BUT what's weird is my console interaction.
> heroku console
> ActiveRecord::Base.connection_config
> {:adapter=>"postgresql", :database=>"1e2e12e21e", :username=>"1e2e12e21e", :password=>"i2j3i23joo12", :host=>"1e2-12e-2e1212-e2e2e1.compute-1.amazonaws.com", :port=>5432, :encoding=>"unicode"}
NOTE: I replaced the real details with this fake stuff just to illustrate
> ActiveRecord::Base.connection_handler
> #<ActiveRecord::ConnectionAdapters::ConnectionHandler:0x00000002f8a578 #connection_pools={"….
NOTE: This a really long string but it has content
> ActiveRecord::Base.connected?
> false
At this point I really don't get it? I don't get how I can keep running db migrations, keeping push and pulling data, log into Heroku Console see my connection_config details, BUT when I run my app internal server error. AND when I run ActiveRecord::Base.connection.tables in heroku console I get ActiveRecord::StatementInvalid: PGError: ERROR: invalid value for parameter "client_min_messages": ""
Any thoughts on what I could be doing wrong?
FINAL UPDATE
Here is what the problem is:
Heroku support kindly pointed to me to a known issue with activerecord 3.1.3. It's a bug that should be fixed in future updates: https://github.com/rails/rails/commit/92a3c487bb0d125c437e53a7f45c31fcca97f2d9
How to solve the problem:
I decided to use a much lower version of activerecord in my gemfile gem "activerecord", "~> 3.0.9 and my site is up and running with no problems so far.
Why I never tried this out before I don't know. I hope this post anyone else.
I had this problem for a long time and it was driving me nuts. I couldn't find a solution anywhere (and many rails updates passed by not solving the "problem"), so i decided to just hunt down the issue myself. It turned out to be an easy fix. Just add an additional key, value pair: :min_messages => "warn" (or whatever message level you want) to the ActiveRecord setup in your configure block. here's what I'm using in my Sinatra app's right now, using Sinatra 1.3.2 and ActiveRecord 3.2.2:
db = URI.parse(ENV['DATABASE_URL'] || "postgres://user:password#localhost/database")
adapter = (db.scheme == "postres") ? "postgresql" : db.scheme
ActiveRecord::Base.configurations[:production] = {
:adapter => adapter,
:username => db.user,
:password => db.password,
:port => db.port,
:database => db.path.sub(%r(^/),""),
:host => db.host,
:min_messages => "warn"
}
unless ActiveRecord::Base.connected?
ActiveRecord::Base.establish_connection ActiveRecord::Base.configurations[:production]
ActiveRecord::Base.logger = Logger.new(STDOUT)
end
hope this helps you and any other people having these issues!
None of the other suggestions worked for me. I ultimately fixed this by switching to the Heroku cedar stack:
heroku create your app --stack cedar
I had this problem on both bamboo-ree-1.8.7 and bamboo-mri-1.9.2 stacks. The application worked fine on localhost, and migrated OK on heroku, but reading the database inside the heroku web stack failed with a client_min_messages complaint.
Setting the :min_messages (as suggested in another answer) to either "warn" or "warning" produced different errors.
Forcing my ActiveRecord down to 3.0.11 (from 3.2.3) resolved the issue. (Not that I see anything in AR to explain this. I speculate it's related to differing postgres versions ... I'm using 9.0.3, suspect the heroku bamboo shared is 8.4)
Pushing this up in my gem file worked for me.
group :production do
gem 'pg'
gem 'activerecord', '~> 3.0.9'
end