I'm attempting to create a Ruby on Rails web app that uses postgres as its database. I am having trouble connecting to the server with postgres
I have installed PostgreSQL and have successfully created a Rails app that uses postgres. However, when I run "rails server", it returns..
=> Booting WEBrick
=> Rails 3.2.13 application starting in development on XXX:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/usr/lib/ruby/vendor_ruby/active_record/connection_adapters/postgresql_adapter.rb:1215:in `initialize': could not connect to server: Connection refused (PG::ConnectionBad)
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
I believe I have an authentication problem. I've tried to follow two SO links, which appear to have worked for a great number of people, but for which the first steps have failed for me.
How to configure postgresql for the first time?
The first step of this link (su root) resulted in: "su: Authentication Failure".
I am trying to use this guide:
https://www.digitalocean.com/community/articles/how-to-install-and-use-postgresql-on-ubuntu-12-04
If I use "sudo -i", the "su - postgres" command works.
"createuser" then results in:
Enter name of role to add: XXX(root username)
Shall the new role be a superuser? (y/n) n
Shall the new role be allowed to create databases? (y/n) y
Shall the new role be allowed to create more new roles? (y/n) n
createuser: 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/run/postgresql/.s.PGSQL.5432"?
When trying to follow the Ubuntu Postgres guide at https://help.ubuntu.com/community/PostgreSQL I had less success, with
sudo -u postgres psql postgres
returning:
psql: 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"?
Thanks! I'm still a beginner, so please explain things as simply as possible and elaborate.
You still need to start the postgres server. In ubuntu sudo /etc/init.d/postgresql-8.4 restart
Related
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 am new to Ruby/Rails and PostgreSQL. Is it possible to have to multiple rails apps access a psql local database at the same, if not how do you switch between applications?
Currently RailsApp1 is interacting with my psql db as expected, however RailsApp2 cannot connect and rake commands abort.
Running on: OSX Mountain Lion, ruby 1.9.3p194, rails 3.2.8, psql 9.2.1.
~/RailsApp2 #: rake db:migrate
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/pgsql_socket/.s.PGSQL.5432"?
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
Thank you in advance for the help.
PostgreSQL uses a client-server model, so the fact is you just connect to the server and multiple applications can make it work. Your specific problem sounds like the server isn't running or isn't accepting connections. Steps to try in order:
ps -A | grep post looking for postgres or postmaster processes. If not found start the server using the pg_ctl program.
Assuming it is running try setting the PGHOST environment variable to "localhost" so that it forces rake, psql, etc. to connect over TCP/IP. This would help if the UNIX socket is missing or just not where the client apps expect it to be.
If those two fail, find your postgresql logs (sometimes called serverlog, and sometimes in a pg_log directory) and post error messages.
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.