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
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 have a rails project, that works with postgresql and pg.
I installed postgres in my computer, but when I try to create/migrate the db of the aplication, I get the following error:
ConnectionBad: 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 created already the user for the application.
I didn't have the postgresql folder at least, I had to create it.
What could be the problem?
I'm using Ubuntu 14.04
By default the socket connection file is located in the /tmp folder, you can find it in /tmp/.s.PGSQL.5432. To change the location check ~/.parts/var/postgresql/postgresql.conf file, but /var/run directory is not writable now, you can't select /var/run as the socket file location.
I'm on osx and I have problems creation of user postgresql.
when I write the command:
createuser myapp -s
I get the following error:
could not connect to database postgres: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?
I do not know if it's just PATH directory problem.
PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
I installed postgresql with this solution : http://tammersaleh.com/posts/installing-postgresql-for-rails-3-1-on-lion
thanks for your help and sorry for my bad english.
Are you sure the postgres server is running? (Use "ps ax | grep postgres"). Has it opened a TCP port (per default 5432)? Is this unix socket "/var/pgsql_socket/.s.PGSQL.5432" available and do you have the permissions to read/write it?
Furthermore, you may want to check the pg_hba.conf file where the permissions on the postgres server itself are configured.
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.
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.