I am using rails 4.2.6 and ruby 2.3 to create an application .The database I am using is postgresql . When I am running the rails s and going to localhost:3000 then the error PG::Connection bad is showing . how to fix it ?
            Asked
            
        
        
            Active
            
        
            Viewed 3,226 times
        
    -4
            
            
         
    
    
        Omar Lahlou
        
- 1,000
- 9
- 33
- 
                    Have you entered the password in database.yml in your rails app? – Sahil Apr 05 '16 at 13:46
- 
                    4can you connect to the database outside of rails? using psql for instance on a command line? Have you double checked the password? have you reviewed other stackoverflow answers? http://stackoverflow.com/questions/19828385/pgconnectionbad-could-not-connect-to-server-connection-refused or http://stackoverflow.com/questions/14225038/postgresql-adapter-pg-could-not-connect-to-server – trh Apr 05 '16 at 13:49
- 
                    generally you may want to create your rails app using `rails new appName --database=postgresql`. This would create the right config files for you. – Omar Lahlou Apr 05 '16 at 14:10
2 Answers
2
            
            
        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"?
when you display such an error, postgresql server is already running.
Check PG status;
pg_ctl -D /usr/local/var/postgres status
Response;
pg_ctl: server is running (PID: 377)
/usr/local/Cellar/postgresql/12.1/bin/postgres "-D" "/usr/local/var/postgres"
Kill the process by pid
kill 377
 
    
    
        Uğur Yılmaz
        
- 81
- 3
- 
                    Actually, when I got that error, postgresql server was NOT running: `pg_ctl: no server running`. In that case, all you need is `pg_ctl -D /usr/local/var/postgres start`. (On a mac with `homebrew`). – JESii Jul 23 '20 at 18:41
0
            
            
        If your postgresql server is running fine, your configuration in rails might be not well set here is an exemple:
file in config/database.yml
default: &default
  adapter: postgresql
  encoding: unicode
  pool: 5
  timeout: 5000
development:
  <<: *default
  host: localhost
  username: your_pg_username
  password: your_pg_password
  port: your_pg_server_port_5432_by_default
  database: your_databasename
 
    
    
        coding addicted
        
- 3,422
- 2
- 36
- 47