I just updated my gems. And now I have problems connecting to my postgresql database. I get the error:
PGError
could not connect to server: Permission denied
Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?
I tried uninstalling the gem and reinstalling, I also tried to change the paths file and put '/usr/local/bin/' on top. I tried some of the things from post:
Repairing Postgresql after upgrading to OSX 10.7 Lion
This app worked fine before updating my gems, other apps still connect just fine, to the same server. I have the same settings in my database.yml file.. what could be wrong?
The error comes from the PostgreSQL server and I have seen it many times. It tells you that you are trying to connect via Unix domain socket (and not via TCP/IP!) to a server that is running locally and listening at port 5432. But no server can be found that would accept connections like that.
You did not mention where the PostgreSQL server resides - I assume you actually mean to connect to a database server on your local machine.
Check your setup, especially your pg_hba.conf file. You need a line like:
local mydb myuser md5
or
local all all peer
or some other connection method that includes your user and database.
These would not help in your case:
host ...
or
hostssl ...
They concern TCP/IP connections, not local connections via UNIX domain socket. When you connect to localhost you actually use TCP/IP via local loop and these settings apply.
Remember to reload after you edit pg_hba.conf. I quote the manual at the linked site:
If you edit the file on an active system, you will need to signal the
postmaster (using pg_ctl reload or kill -HUP) to make it re-read the
file.
Related
Not possible to connect to PostgreSQL 11.
Event though the server is running. I even installed pgAdmin 4, accessed the server, it is working perfectly. But when I do it from the Rails server it shows:
could not connect to server: No such file or directory
Is the server running locally and accepting connections on Unix domain socket
"/var/run/postgresql/.s.PGSQL.5432"?
I tried every possible thing here in Stackoverflow. Two days straight, and nothing. The same thing with PostgreSQL 10. Log files checked, the file .s.PGSQL.5432 does not appear in the /var/run/postgresql folder.
I am using bash Ubuntu 18.04.2 subsystem on Windows. I checked for permissions already.
You should check the setting of unix_socket_directories on your PostgreSQL server. It probably does not contain /var/run/postgresql.
Here is what to do:
Find a directory in unix_socket_directories.
Make sure that the client has access to the directory and the socket file in it.
Use the name of the directory as host parameter for your database connection.
I am currently trying to run my application on BlueHost.
I already clone, setup, and install the application.
When I tried rails s the application can running on http://my.domain.com:3000
But it's return
could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
I am using PG for the database but I am not sure why this happens.
After did some research this is happen because I need to reconfigure PG user and database manually. And it working like charms. Thanks a lot guys.
When I try to migrate the database I get this error:
rake aborted!
could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
I've tried creating a symbolic link to .s.PGSQL.5432 and it does not work. This file for me is in /tmp/.s.PGSQL.5432
Does anyone have solutions?
OS - Linux Mint
The /var/run/postgresql directory is just the default socket location of the postgres client library (libpq) that ships with Debian and the distributions based on it.
The mismatch in the socket location happens when mixing mixing client libraries shipped with the system packages with a server that is self-compiled or from an alternative source.
You may point the client program to the alternate location through the host parameter, in database.yml (or more generally in the connection parameters wherever they're stored):
host: /tmp
Notes:
this must not be the full socket file name, only the directory. Building the file name is the job of the postgres library (libpq), not of the caller.
the postgres client library understands that this is a path to a server socket as opposed to a hostname because it starts with a slash. Nothing else is needed to indicate a socket. There is no socket parameter in the connection options, unlike with mysql.
Try adding this line to your database.yml
socket: /tmp/.s.PGSQL.5432
Developing RoR app on Windows using RubyMine, trying to connect to Postgres database hosted on Heroku server. No Postgres installed locally. Getting "java.sql.SQLException: FATAL: no pg_hba.conf entry for host..." What to do, what to do?
This is due to Heroku databases needing additional SSL configuration.
You need to enable SSL in your jdbc string by appending:
?ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory
For details see Heroku's help document.
It looks like this is a RubyMine issue. RubyMine will convert the hostname to an IP address and pg_hba.conf includes the hostname but not the IP address hence the error. It works fine from the command line (e.g. rails s).
I'm having trouble running the ActiveRecord gem tests in PostgreSQL and am getting the following error:
rails/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb:1473:in `initialize': could not connect to server: Permission denied (PG::Error)
Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?
I'm able to connect to the server using psql -h localhost and create databases, etc. I'm using http://postgresapp.com/ for the postgresql server. I get the same error when running rake postgresql:build_databases as suggested by the Rails contributing guide.
The rails/activerecord/test/config.yml file has the following settings (all I've changed is the username):
postgresql:
arunit:
username: pete
min_messages: warning
arunit2:
min_messages: warning
username: pete
Is there another setting I need to configure in config.yml? I've tried specifying a host and empty password, but that doesn't help at all.
Your psql is connecting using TCP to localhost, ruby is obviously connecting through a local unix domain socket. Problem with the unix domain socket of postgresql on osx is that not all psql client libraries and database backends agree on the location of the socket.
If you don't pass a -h option to psql it will use a local unix domain socket to. There is a good change it will fail to.
There are two possible solutions for both of which I can't give you details because I do not know ruby on rails and don't have access to a mac right now:
Tell ruby to connect to localhost instead of using the unix domain socket.
Make sure the client library (libpq) used by ruby matches the backend you are running.