I am running Rails 4.2.2 and my postgres gem is 0.17.1 and everything was running fine yesterday but today when I opened the console and tried connecting to the database I saw this error:
PG::ConnectionBad: 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"?
...then when I tried connecting to the database through running psql, I see the following:
dyld: Library not loaded: /usr/local/opt/readline/lib/libreadline.6.dylib
Referenced from: /usr/local/bin/psql
Reason: image not found
Abort trap: 6
As far I know I havent changed anythingsince yesterday so I'm not sure why this is happenning. I tried adding host: localhost to my database.yml with no luck. It may be worth noting when I try to connect to the DB using a program like PSequel, I see the following:
could not connect to server: Connection refused
is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432?
Has anyone seen this?
Neara's response to this post provided an answer for me: PostgreSQL server won't stop.
Basically had to run:
$ brew services list
$ brew services restart postgresql
They posted a workaround in case services cannot be found.
Related
I am running a Ruby on Rails app on Heroku with Postgres Database.
I used to be able to connect to my database from my terminal using heroku pg:psql command
Recently, things have changed. After running heroku pg:psql command, I get the following error.
--> Connecting to postgresql-perpendicular-94363
psql: could not connect to server: Connection refused
Is the server running on host "ec2-23-23-130-158.compute-1.amazonaws.com" (23.23.130.158) and accepting
TCP/IP connections on port 5432?
I tried to search online about it, but nothing useful has been found.
Please help. Thanks 😄
I've just tried connect to your database:
psql "dbname=postgresql-perpendicular-94363 host=ec2-23-23-130-158.compute-1.amazonaws.com user=test_user port=5432 sslmode=require"
And I've got:
psql: FATAL: password authentication failed for user "test_user"
Because, of course I don't know you credentials :)
However, it seems that connection works. I suppose, that you forgot set sslmode. As you can see in documentation, it is required:
All connections require SSL: sslmode=require.
Update:
I've checked connection without sslmode, and message is other than yours:
FATAL: no pg_hba.conf entry for host "31.42.24.63", user "test_user", database "postgresql-perpendicular-94363", SSL off
So, I suppose that this is a problem with you internet connection. Check you firewall setup.
As per the description mentioned in the post, the way you have specified is correct.
Moreover you can also try the below mentioned command where you specify the database as well.
heroku pg:psql DATABASE_URL
Note: This is only used when there are multiple databases linked.
I switched my database from sqlite to postgres for deployment on heroku. When I did that and attempted to run heroku run rake db:migrate -a I saw this error:
ActiveRecord::StatementInvalid: PG::DatatypeMismatch: ERROR: column "pay_date" cannot be cast automatically to type date HINT: You might need to specify "USING pay_date::date". : ALTER TABLE "recurring_payments" ALTER COLUMN "pay_date" TYPE date
So i created a migration to fix this, but when I run rake db:migrate to run the migration, I see this error:
PG::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"?
However, when I check my services, I see that it is running, and it is configured to listen on port 5432. What else could be causing this issue?
Also, if I add this line to database.yml:
host: localhost
The error changes to this:
PG::ConnectionBad: could not translate host name "localhost" to address: Name or service not known
Perhaps this is more promising?
You seem to have multiple problems:
By default Rails uses Unix sockets to connect to PostgreSQL. Hence the original error message.
Adding the host key switches Rails to a TCP/IP connection instead, which is what you want in Windows.
Now you seem to have another problem: localhost cannot be resolved to an IP address, which suggests that you have general configuration problems on your Windows machines which are unrelated to Rails or PostgreSQL.
Check if your hosts file is messed up or if your (personal) firewall is blocking Rails or PostgreSQL. Try running ping localhost.
If all else fails try using host: 127.0.0.1 instead.
Can anyone help me fix this problem?? when i run localhost:3000 i encounter this?
"could not connect to server: Connection refused (0x0000274D/10061)
Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432? could not connect to server: Connection refused (0x0000274D/10061)
Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432?..... Now, again when i try to run "net start postgresql-9.5" in CMD line it says
'system error 5 has occured,access is denied'.
what is wrong i cant understand?
I know in windows it's struggling to learn rails but if you want to continue below is some tips when I test running rails with windows
for rails installer, you can download from http://railsinstaller.org/en it include git , ruby and rails
for postgres, I think it's easier to install from this site, you just follow windows instruction and make sure you write down the password as you will need it later for your database.yml (database configuration)
after you install both programs, when you want to open command prompt, make sure you choose command prompt with ruby on rails, as this command prompt will include git, ruby and rails command.
hopefully can help
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.