I`m getting some troubles after installing in Windows 7 ruby 1.8.6, rails 2.3.8, some basic gems(also ruby-postgres) and the IDE Rubymine from Jetbrains.
So, after creating a simple project with Rubymine(default PostgresSQL configuration in database.yml), I run it in localhost:3000 but it seems not be recognizing nothing like:
When I first click on the main page of Ruby on Rails at "About your application’s environment"
it returns an Error: "We're sorry, but something went wrong." and even when I create a simple controller with a view and opens the right URL it tells the same problem.
I don't know if the problem is about database or something like this, but also I would like to know how to configure it in database.yml.
Default:
adapter: postgresql
encoding: unicode
database: (name of the project)_(type: test, production or development)
pool: 5
username: (name of the project)
password: (no password)
What I did:
adapter: postgresql
encoding: utf-8
database: (name of database)_(type: test, production or development)
pool: 5
username: ruby
password: (no password)
host: localhost
port: 3000
Is it right?
I don't know much about running Rails on Windows, but looking at your database.yml file above, you shouldn't be saying port: 3000. That's the default port for the rails application to run on. You need to be putting the port that PostgreSQL is running, which is typically 5432.
assuming your project is called foo, and you've created the correct databases in postgres, and postgres is listening on the default port on localhost
development:
adapter: postgresql
encoding: utf-8
database: foo_development
pool: 5
user: ruby
As stated port 3000 is where rails listens, so that will cause problems. Also you need to make sure the pga_hba.conf allows connections to the database.
Related
I have a Rails app that has been using sqlite3 for the DB. Deployed to Heroku. Then find out that Heroku recommends switching to PostgreSQL. So now I'm trying to switch over without any luck. Was trying to use this Railscasts video for help.
I installed Homebrew. Installed PostgreSQL via Homebrew. After installation, there was no mention of creating a username or password for postgres.
I edited my Gemfile to
gem 'pg'
for both production and development and did bundle install.
I edited my database.yml file to this:
development:
adapter: postgresql
database: isement_dev
encoding: unicode
pool: 5
timeout: 5000
test:
adapter: postgresql
database: isement_test
encoding: unicode
pool: 5
timeout: 5000
production:
adapter: postgresql
database: isement_production
encoding: unicode
pool: 5
timeout: 5000
Like Ryan says to do in the video, I try this command:
rake db:create:all
Only to get this error:
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 do some more searching, and see that some tutorials show username and password included in the database.yml file. I then find out how to setup a user for Postgresql
After entering in the command $ createuser joe, I was never given the options that the docs say you'll be asked. Such as "Shall the new role be a superuser? (y/n)" So really not sure if the user was created, but there wasn't any errors either.
So, I'm assuming, after creating the user "joe", I reedited my database.yml file to include the user field I just created:
development:
adapter: postgresql
database: isement_dev
encoding: unicode
pool: 5
timeout: 5000
username: joe
password:
test:
adapter: postgresql
database: isement_test
encoding: unicode
pool: 5
timeout: 5000
Only to still get the same error of not being able to connect.
I've ran the command
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
to make sure the server is running as well.
Just in case it's needed, when I run
which psql
I receive this:
/usr/local/bin/psql
Is there something that I'm missing? The "database name" part of the database.yml file. This is supposed to be a database already created somewhere, or does this file create the database when I run the rake db:create:all command? I'm assuming the latter, so the name of the database doesn't matter?
Lazy option: Add host: localhost to your database.yml.
Only slightly less lazy option: Uninstall and reinstall the pg gem.
What's going on here? There are a number of ways for Postgres to already exist on your system, and the pg gem will use their pg_config output and build for their needs if you install the gem before installing your own copy of Postgres.
In your case, it was built for the version included with some releases of Mac OS X, which uses a socket file at /var/pgsql_socket.
when you are installing Postgres via Homebrew it will add your username to postgres with an empty password.
Just open a command prompt and type
whoami
Then change your database.yml to your mac user name (whatever is returned from whoami) with empty password.
Maybe add host: localhost
to you database.yml
I'm trying to move my database to a PostgreSQL because I'm putting it up on Heroku.
Followed Railscast #342. Installed PostgreSLQ with its dependencies on my Ubuntu machine. When I installed it I think a user was created. I used this user in my database.yml. It looks like this:
production:
adapter: postgresql
encoding: unicode
database: dlrvbtApp1_production
pool: 5
username: jdartland
password:
development:
adapter: postgresql
encoding: unicode
database: dlrvbtApp1_development
pool: 5
username: jdartland
password:
test:
adapter: postgresql
encoding: unicode
database: dlrvbtApp1_test
pool: 5
username: jdartland
password:
Installed pg gem and the taps gem.
Ran a Bundle install, created the databases with rake db:create:all
Started the taps senatra server with taps server sqlite://db/development.sqlite3 jdartland secure
The server started. And tried to pull the SQL to my new development db through this command.
taps pull postgres://jdartland#localhost/dlrvbtApp1_development http://jdartland:secret#localhost:5000
I then get this error:
Failed to connect to database:
Sequel::DatabaseConnectionError -> PG::ConnectionBad: fe_sendauth: no password supplied
I have tried and tried, created new databases, canhing the .yml, pg_config and so on but I can't get it to work.
This is my first time working with PostgreSQL and Heroku, please give me a hand! :)
Change the user on production to localhost and leave the password blank.
production:
adapter: postgresql
encoding: unicode
database: dlrvbtApp1_production
pool: 5
username: localhost
password:
If you're moving your database to Heroku, the whole thing is just a case of connecting your DB to Heroku's PG one, and migrating the data.
Did you receive database details from Heroku?
They basically use Amazon to serve their DB's, and you'll get some credentials to put into your yml file for it. Here is an example of one of our live Heroku apps:
production:
adapter: postgresql
database: ********
pool: 5
username: ****************
password: ****************
port: 5432
host: ec2-54-228-234-250.eu-west-1.compute.amazonaws.com
Ways To Migrate To PostgreSQL (Heroku)
If you're looking to migrate your data from SQLite3 to PostgreSQL, I found a really good tutorial on how to do this here. Only problem is that it's not for SQLite lol
If you're trying to pull down your database from Heroku into a local postgres database, use pg:pull or pgbackups:
https://devcenter.heroku.com/articles/heroku-postgresql#pg-push-and-pg-pull
https://devcenter.heroku.com/articles/heroku-postgres-import-export
You should also look into using foreman and a .env file to setup your DATABASE_URL similar to how it's ran on Heroku, for dev/prod parity:
https://devcenter.heroku.com/articles/procfile#developing-locally-with-foreman
Got It working by following another post here on stack. Simply went up one directory, installed taps Gem install Taps. Uninstalled Rack gem gem uninstall rack 4 then Reinstalled it gem install rack --version 1.0.1. Did not do this in my progect directory, just simply in RVM. Then Pulled the database from the same directory. (not from my project directory).
Here is the Whole tread: taps migration failing from sqlite to postgres rails4, ruby 1.9.3
Hope it helps someone with the same problem.
Now just one thing left, Push it to heroku..... We'll see how that goes...hehe
Thanks for all help!
I am new in ror developement..i was working on a LIVE server...I just uploaded a file through sftp...after 1 day server suddenly stopped working...You can see the error message from here
it shows
There appears to be a database problem.
Your config/database.yml may not be written correctly. Please check it and fix any errors.
Your database schema may be out of date or nonexistant. Please run rake db:migrate to ensure that the database schema is up-to-date.
The database server may not be running. Please check whether it's running, and start it if it isn't.
Looking at the error page you seem to be using Rails 2.3?
At a guess you have a MySQL database not an SQLite running. You should have the user name and password for the database around somewhere (replace the relevant fields in the 3 sections with them).
Change the database names to reflect your database names.
The server admins might have set a specific socket for MySQL in which case replace the '/tmp/mysql.sock' with the socket number.
Check your Gems to see if the MySQL adapter is installed (you appear to be using Rails 2.3 so try gem list on the terminal for your server - make sure that you are in the root directory for the app).
If the MySQL gem is missing use gem install to install it (this will depend on what your hosting provider allows).
The following links are pretty old - targetted towards Rails 2 which you appear to be using.
http://www.ruby-forum.com/topic/139710
http://forums.mysql.com/read.php?116,353922,359544
database.yml
development:
adapter: mysql
encoding: utf8
database: temp_development
username: root
password:
socket: /tmp/mysql.sock
# Warning: The database defined as 'test' will be erased and
# re-generated from your development database when you run 'rake'.
# Do not set this db to the same as development or production.
test:
adapter: mysql
encoding: utf8
database: temp_test
username: root
password:
socket: /tmp/mysql.sock
production:
adapter: mysql
encoding: utf8
database: temp_production
username: root
password:
socket: /tmp/mysql.sock
So I am developing locally using Rails 3.2 and mysql. My local machine is a Mac and my database.yml for development is:
development:
adapter: mysql2
database: dbname
encoding: utf8
host: localhost
port: 3306
timeout: 5000
socket: /tmp/mysql.sock
And for test it's
test:
adapter: mysql2
database: dbname
encoding: utf8
host: localhost
port: 3306
timeout: 5000
socket: /var/lib/mysql/mysql.sock
Test and production servers are on CentOS and the socket works correctly when deploying to them. However I just went to do a manual rake and got the
Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
My site works, but I'm curious if I'm should be handling database.yml separately for deployment since it's somehow looking at development when I run rake?
Looked for a suggestion and didn't see the same issue, apologize in advance if I missed it.
You can specify the Rails environment when you run the Rake task.
rake db:migrate RAILS_ENV=production
I can think of three alternatives:
Change your database.yml and just don't version in the changes
Use capistrano and its shared folder to handle different database.yml
Use an environment variable i.e. ENV['TEST_SOCKET']
Just setup a new rails 3.1.3 app using mysql (mysql2 gem) on CentOS 5 server / apache / passenger... I have correctly setup a database and a user for that database and I have added the login and info into my database.yml file... I can generate stuff, and rake db:migrate ok but the "We're sorry, but something went wrong." message is being rendered in the browser and this message is showing up in my production.log file!
Started GET "/" for xx.xxx.xx.xxx at 2011-12-29 19:52:35 -0600
Mysql2::Error (Access denied for user 'root'#'localhost' (using password: NO)):
weird, I am not using "root" as the login info in database.yml... Any suggestions?
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: the_db_I_made
pool: 5
username: the_user_I_made
password: the_password
socket: /var/lib/mysql/mysql.sock
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: the_db_I_made
pool: 5
username: the_user_I_made
password: the_password
socket: /var/lib/mysql/mysql.sock
Bunch of questions / suggestions:
Can you connect to the database using the terminal?
mysql -u root -p
Also, have you tried this on development mode? If so, please share the results.
Try removing
socket: /var/lib/mysql/mysql.sock
Is the gem installation correct?
gem check mysql2
EDIT:
There is a lot of difference in development and production mode ( including but not limited to, environment variables like the database connection string, asset pre-compilation, different level of logging, custom debug info on error pages )
** Embarrassing!!**
You have not included the "host" property in your config!
Try this:
production:
adapter: mysql2
encoding: utf8
reconnect: false
host: your_host #<----- normally localhost
database: the_db_I_made
pool: 5
username: the_user_I_made
password: the_password
socket: /var/lib/mysql/mysql.sock
Ok, I guess this is all part of my learning curve :)
What it ended up being was this: The gem for passenger that I installed originally was version 3.0.9, I did a gem update --system and that installed version 3.0.11. So the server thought it was using version 3.0.11 and I was still pointing to libraries for 3.0.9 in my rails_server.conf file. I found how to upgrade on http://blog.phusion.nl/
In Ubuntu 1)/usr/bin/mysql_secure_installation 2) Run in Terminal
follow the steps carefully change the mysql password
here.Everything done .then go to database.yml change the password
previously what u have created. Run rails server and check the
application .. it will works
Did you create the database "the_db_I_made"?
First create it, then only run it, else it will show this error continuously.
Now try to tun it.
For Me It was giving error because of no database. So i created one Using :
$ rake db:create
And the problem was solved :D