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
Related
I'm having problems assessing a postgres database from straight ruby.
I've created a Postgres database using Rails
>rails new www --database=postgresql
using Rails 4.2.5 and Postgres is 9.4
It produces the following config/database.yml file.
default: &default
adapter: postgresql
encoding: unicode
pool: 5
development:
<<: *default
database: www_development
test:
<<: *default
database: www_test
production:
<<: *default
database: www_production
username: www
password: <%= ENV['WWW_DATABASE_PASSWORD'] %>
I can run rails server, db:drop, db:create and db:migrate fine.
I can also access the database fine with psql
>psql www_development
But when I run the following app.rb from a non Rails project directory, I get a fe_sendauth: no password supplied (PG::ConnectionBad) error message.
It's clearly not a Rails issue. I've either missed something in my ruby or Postgres need a tweek to handle some difference between Rails and pure Ruby [that I'm not aware off]. I've also included Postgres' pg_hba.conf file.
At wits end trying to figure this one out. Any help would be much appreciated.
app.rb
require 'yaml'
require 'active_record'
require 'pg'
ActiveRecord::Base.establish_connection(
adapter: 'postgresql',
host: 'localhost',
database: 'www_development',
)
/etc/postgresql/9.4/main/pg_hba.conf
# TYPE DATABASE USER ADDRESS METHOD
local all postgres peer
local all all peer
host all all 127.0.0.1/32 md5
host all all ::1/128 md5
You don't specify neither username, no password in your ActiveRecord::Base.establish_connection(. I assume you want to use some SUPERUSER without password for www_development database - right?
as per documentation peer auth does
Obtain the client's operating system user name from the operating
system and check if it matches the requested database user name.
That is why if you can psql without password, you should be able run app.rb with same OS user and environment without password. If you can't, then app.rb tries to connect with different username or so...
Options:
put username: postgres to ActiveRecord::Base.establish_connection(
change local all all peer to local all all trust
With ENV variable as password it's very likely that the variable itself is not present. Confirm the presence with printenv. You need to relogin/reboot for the variable to be accessible after you've included it in /etc/environment file for example. If this works, it's probably better than changing pg_hba.conf.
development:
<<: *default
database: postgres
username: postgres
password: postgres
# must specify the right DB, superuser and superuser Password as per postgreSQL setup
This worked for me, the only changes I needed to make. (ok fine i re-installed pgsql with 12.1)
I had this same issue when setting up a Rails 6 application.
The issue was that when start the rails server using rails server, and try to view the application from a browser, I get the error below:
ActiveRecord::ConnectionNotEstablished
fe_sendauth: no password supplied
Here's how I solved it:
The issue was caused by me not specifying/supplying the database password to be used by the application, so when the application tries to connect to the database specified in the config/database.yml it runs into that error.
I solved it by specifying the database password for the application in the config/database.yml:
# The password associated with the postgres role (username).
password: my-password
Also, ensure that you've created the database for the application if you've not created it already using:
rails db:create
Afterwhich I restarted the rails server:
rails server
This time when I tried viewing the application from the browser, it worked fine.
That's all.
I hope this helps
I was trying to use peer authentication which shouldn't ask for the password.
For me the issue was that I was specifying localhost in the database.yml so that was forcing the database driver to try to make a different type of connection (e.g., tcp, named pipe, etc)
Removing the "host: 'localhost'" line from my config solved the problem for me per this other answer: ActiveRecord connection to a localhost postgresql database in trust mode
Note that in my case I'm using the 'peer' method and not the 'trust' method but the solution is the same
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 have configured database.yml to include "logging_development" as a label for signifying another database. One of the models is using "establish_connection" to connect to the database using this "label".
My model looks like this:
class AdHistory < ActiveRecord::Base
establish_connection "logging_#{RAILS_ENV}"
The Rails server works fine when it starts and establishes connection of the model with the concerned database. But when I start ruby console and try to use the model, it uses "development" label in database.yml to establish connections. I have looked into the issue but unable to find a solution. Here is a sample of the database.yml file:
development:
adapter: mysql
encoding: utf8
reconnect: true
database: ad_production
pool: 5
username: root
password: ********
socket: /tmp/mysql.sock
logging_development:
adapter: mysql
encoding: utf8
reconnect: true
database: ad_logging
pool: 5
username: root
password: ********
socket: /tmp/mysql.sock
I am using Ruby 1.8.7 and Rails 2.3.8
Have you used the RAILS_ENV=logging_development when running the rails console? If not you should, because the default Rails environment is development. So, try to load the console using this to set the RAILS_ENV variable:
RAILS_ENV=logging_development scripts/rails console
I found the answer to my question. The problem was that I was using Multi_DB gem which was intercepting all the SQL Queries that were being executed and re-directing those queries to the slave database. That was why those queries were not being executed against the database I had chosen in the "database.yml". Once the multi_db connection is nullified, the console behaves as expected. One of the problems of using "multi_db" gem is that it only accepts names of connections as "_slave_database_". So, any deviation from the expected name for multi_db gem in database.yml file will lead to errors, and the queries will not get executed against the selected database.
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.