rake db:create:all FATAL : password authentication failed - ruby-on-rails

I am trying to follow this railscast tutorial. Now I am in the step, where you create the database with rake db:create:all, but I got this error message :
FATAL: password authentication failed for user aldila
I made the user aldila through pgAdmin, by right-clicking the login role and add user aldila with password.
So, here is my database.yml :
development:
adapter: postgresql
host: localhost
encoding: unicode
database: my_app_development
pool: 5
username: aldila
password: *mypass*
test:
adapter: postgresql
host: localhost
encoding: unicode
database: my_app_test
pool: 5
username: aldila
password: *mypass*
production:
adapter: postgresql
host: localhost
encoding: unicode
database: my_app_production
pool: 5
username: aldila
password: *mypass*
Here is my pg_hba.conf
# TYPE DATABASE USER ADDRESS METHOD
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#host replication postgres 127.0.0.1/32 md5
#host replication postgres ::1/128 md5
Maybe there is something's wrong with the installing of PostreSQL, because if I type
psql --version on my command, this is what I got :
'psql' is not recognized as an internal or external command,
operable program or batch file.
But I have no idea what went wrong. I install it from here and pick download the installer from EnterpriseDB for all supported versions.
I know there are already similar questions like this, but I follow this one and this one, but I still get the same error message. I would be really appreciated, if anyone could help. Thanks

Your postgresSQL password didn't match your database.rb's password.. it depends on what environment you are using..

Related

"could not save history to file "/Library/PostgreSQL/9.6/.psql_history": No such file or directory"

I am building a Rails project with Devise and Postgres.
When trying to migrate, I get this error message:
PG::ConnectionBad: FATAL: password authentication failed for user "kala.wetzler".
I have tried this process a few times: https://www.cyberciti.biz/faq/howto-add-postgresql-user-account/ & after what seems like a success (no error messages) & I \q out, I get this message:
could not save history to file "/Library/PostgreSQL/9.6/.psql_history": No such file or directory.
After this, if I try to migrate again I see that it does not recognize my password (as seen in the first error message listed in this post). Is it not working because of this lack of a file to save to or is that just telling me that this process of assigning a user to the database is not being logged? If it is because of a lack of the file to save to, how do I make sure that file gets created?
My config/database.yml:
default: &default
adapter: postgresql
encoding: unicode
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
host: localhost
username: kala.wetzler
password: <%= ENV['LIT_DATABASE_PASSWORD'] %>
development:
<<: *default
database: lit_development
test:
<<: *default
database: lit_test
production:
<<: *default
database: lit_production
username: kala.wetzler
password: <%= ENV['LIT_DATABASE_PASSWORD'] %>
& then in my .env file I have LIT_DATABASE_PASSWORD assigned.
My pg_hba.conf:
TYPE DATABASE USER ADDRESS METHOD
"local" is for Unix domain socket connections only
local all all trust
IPv4 local connections:
host all all 127.0.0.1/32 trust
IPv6 local connections:
host all all ::1/128 trust
Allow replication connections from localhost, by a user with the replication privilege.
local replication kala.wetzler trust
host replication kala.wetzler 127.0.0.1/32 trust
host replication kala.wetzler ::1/128 trust

PostgreSQL: could not connect to server: Connection timed out

I've been trying to make the switch to PostgreSQL (from SQLite). I'm developing in the environment of Cloud9. However, on db migration I get the error message:
PG::ConnectionBad: could not connect to server: Connection timed out.
Is the server running on host "mydomain.c9.io" (IP address) and
accepting TCP/IP connections on port 5432?
I've been reading all sorts of previously asked questions on this topic but without success. Does anyone see what might be going wrong?
Do I perhaps need to makes change to the pg_hba.conf file? The current version of the file:
# Database administrative login by Unix domain socket
local all postgres peer
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all peer
# IPv4 local connections:
host all all xxx.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication postgres peer
#host replication postgres xxx.0.0.1/32 md5
#host replication postgres ::1/128 md5
database.yml:
default: &default
adapter: postgresql
encoding: unicode
host: 'mydomain.c9.io'
pool: 5
username: my_username
password: my_password
development:
<<: *default
database: app_development
test:
<<: *default
database: app_test
production:
<<: *default
database: app_production
I have gem 'pg' in the Gemfile and have run bundle install. Also, I have created the database app_development (used sudo service postgresql start, sudo sudo -u postgres psql and then create database "app_development";) as well as the database app_test. And lastly, I created a new user in psql with CREATE USER my_username SUPERUSER PASSWORD 'my_password';.
Using sudo nano /etc/postgresql/9.3/main/postgresql.conf I also set listen_addresses = '*' but that made no difference.
What might be causing the error message?
Are you sure that your cloud 9's has postgres port(5432) open for access? I assume the cloud 9 host is not listening on port 5432. You can check out this link for detais
http://www.cyberciti.biz/tips/postgres-allow-remote-access-tcp-connection.html

setting ip address of database on different server

I deployed a sample Rails app to a remote server with postgres hosted on the same server. The database.yml file was like this.
production:
adapter: postgresql
encoding: unicode
database: remotepg_production
pool: 5
host: localhost
username: mrmann
password: secret
Everything worked fine. I then went into the database.yml file and replaced host: localhost with the ip address of a postgres database on another server host: 178.XXX.XXX like this
production:
adapter: postgresql
encoding: unicode
database: remotepg_production
pool: 5
host: 178.XXX.XXX.XXX #ip address of server with other postgres database
username: mrmann
password: secret
When I restarted postgres on the server with the Rails app, the sample application now gave me the 'something went wrong' page for Rails.
The username and the password for the username are the same on both dbs. Can you suggest what the problem might be? Thanks
Update
These are the settings in pg_hba.conf on the server with the database that I want to connect to.
local all postgres peer
local all all peer
host all all 127.0.0.1/32 md5
host all all ::1/128 md5
Fake Rails app IP: 192.241.XXX.X
Fake Database IP: 192.34.XX.XXX
Do you have access to the database logs? If your connection got as far as attempting to connect to the database, there should be some messages there. My WAG is that you need to add that IP to server's pg_hba.conf file and reload Postgres.
To be more clear, the IP to add to the server's pg_hba.conf is the IP that your application is connecting from, and you should also check the value of the database's listen_addresses setting. If the latter is not set to '*' or to the IP of your application, you'll need to change it in the postgresql.conf and restart the db cluster.
[edit, new information provided]
The line in your pg_hba.conf should be
host all all 192.241.XXX.X md5
Reload (not restart) postgres (eg. pg_ctl reload) and then try connecting again. If it fails, find the db log and see what it shows. If there is no message, then it might be a firewall problem. If the latter is suspected, look for any rules relating to port 5432 in the output of iptables -nvL

rake db:migrate Could not connect to server error

Hey I want to see someone example app. So I downloaded it off github and installed the version of ruby they are using ruby 2.0.0 but when I try to do $ rake db:migrate I get this error:
rake db:migrate
rake aborted!
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?
/home/alain/.rvm/gems/ruby-2.0.0-preview2/gems/activerecord-4.0.0.rc1/lib/active_record/connection_adapters/postgresql_adapter.rb:796:in `initialize'
/home/alain/.rvm/gems/ruby-2.0.0-preview2/gems/activerecord-4.0.0.rc1/lib/active_record/connection_adapters/postgresql_adapter.rb:796:in `new'
...(etc)
Any idea what I should do ?
database.yml
development:
adapter: postgresql
host: localhost
encoding: unicode
database: rentmybike_dev
pool: 5
username: alain
password: obama
test:
adapter: postgresql
encoding: unicode
database: rentmybike_test
pool: 5
# Add the below...
production:
adapter: postgresql
host: localhost
encoding: unicode
database: rentmybike_production
pool: 5
username: alain
password: obama
To install postgres you may use these commands:
sudo apt-get install postgresql-9.1 postgresql-server-dev-9.1
Then you should set password to newly user
sudo passwd postgres
You have to ensure that database configuration parameters(like username, password etc) in config/database.yml are correct.
And then:
rake db:setup
will create databases and restore schemas if any.

can't connect to rds at ec2 server, missing mysql socket

I have an ec2 server and rds server.
and a Ruby On Rails App
connecting to the rds with these settings worked for me in local ENV:
host: myappnameandhash.us-west-2.rds.amazonaws.com
adapter: mysql2
encoding: utf8
reconnect: false
database: mainDb
pool: 20
username: root
password: xxxx
socket: /var/run/mysqld/mysqld.sock
port: 3306
but on my EC2 server I don't have that mysqld.sock file
so i get this error:
FATAL: failed to connect to MySQL (error=Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2))
what do i need to install in order to have the socket?
thanks
update:
I removed the socket definition and the port.
I deploy using capistrano , now i ssh to my server and go to the "current" folder. there i try to run: rake ts:start
and i get the following:
rake aborted!
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
but i don't even have the socket definition in my database.yml file anymore
Remove the socket and port number from your database.yml file and then try, it will work.
You must specify the "host" of your RDS, and also configure the security groups in the RDS to allow your instance to connect to it.
I know this has been a while, just encountered this issue with my EC2 server connecting to RDS. Would like to share how I resolve this.
First removing socket and port from the database.yml help
#In your database.yml
development:
#some configuration
staging:
#some configuration
production:
adapter: mysql2
encoding: utf8
reconnect: false
pool: 20
host: url.to.rds.server
database: your-database
username: your-username
password: your-password
To run this rake command on production, you need to specify your rails-env, e.g. if you are using production environment, it should be
bundle exec rake ts:start RAILS_ENV=production

Resources