We have a Ruby v.2.0.0-p247
on Rails v4.0.1
application using pg gem v0.17.0
.
The application runs smoothly under Mac OS X Mavericks v10.9
with PostgreSQL Server v9.2.4
installed using HomeBrew
but it throws the following exception under Ubuntu v13.04
using PostgreSQL Server 9.1
:
PG::UnableToSend: server closed the connection unexpectedly
This probably means the server terminated abnormally before or while processing the request.
The exception occurs after transactional queries (form submission).
I tried the following with database.yml
:
reconnect: true
port: 5432
socket: /var/run/postgresq/SOCKET_FILE
And tried the following with PostgreSQL configuration under Ubuntu:
DEBUG
and search for possible errors on PostgreSQL Server.Also tried:
What could possible be wrong?
UPDATES:
12/03/2013: Some suggested checking firewall settings. ufw status
said that ufw
is disabled.
12/08/2013: After trying out with a vanilla Rails app and a lot of mangling with the current application, the problem is originating from rails4/activerecord-session_store
gem. Line 47 in lib/active_record/session_store/session.rb
is the culprit.
This basically happens when you use an old version of launchy , and as per this issue on launchy's git repo quoting @infertux
In the rare case when
exec
fails to run the command - typically when the file cannot be opened raisingErrno::ENOENT
- Launchy would raise an exception but not showing any output
You can check your Gemfile.lock
to see if you're using a version of launchy
below 2.4.1, and I doubt that you're using letter_opener
Gem in your development environment which depends on launchy
so updating letter_opener
to 1.2.0 will update launchy
to a version above 2.4.0 mostly 2.4.2 which has this issue fixed
All credit goes to @infertux
It would really help if you provided your database.yml file
The default connection method is a unix domain socket, not to be confused with a TCP/IP socket. The unix domain socket connection method is used by default.
You should check that the unix user that you are trying to run rails under has sufficient permissions to access the domain socket (typically at /var/run/postgresql/.s.PGSQL.5432
)
Try typing the following as your rails user:
psql
If you get a database connection error then its likely a permissions problem if postgres is actually running.
You can check your /etc/postgresql.conf
file and have postgres configure the group and permissions on the socket when it starts:
unix_socket_directory = '/var/run/postgresql' # dont worry if yours is different
#unix_socket_group = '' # default is usually ok
#unix_socket_permissions = 0777 # uncomment this if needed
Another option is to add the user to the group that has write access to the socket, vs allowing all users on the machine access with the 0777 permissions setting above. You may want to create a postres_users
group for this purpose if the default Ubuntu groups provide insufficient granularity for your needs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With