I Cannot get the welcome screen not matter what I do, all I get is the connection issue with the postgres db error.
I ran this command to start the app.
rails new -T appName --database=postgresql
Here is my database.yml file:
default: &default
adapter: postgresql
encoding: unicode
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
development:
adapter: postgresql
encoding: unicode
database: dbname
pool: 5
username: toolshiring
password: toolshiring
host: localhost
port: 5432
production:
<<: *default
database: toolshiring
username: toolshiring
password: <%= ENV['toolshiring'] %>
I used pgAdmin to add a user with full permissions named toolshiring and has the same password. Then created the database with owner toolshiring.
I decided to try something and it seems to have worked for the time being.
I decided to reset the password for the default db 'postgres' to the password 'postgres' as well, and delete the new db that I created....because the wasn't working for some reason.
in my database.yml file i commented everything but this
development:
adapter: postgresql
encoding: unicode
database: postgres
pool: 5
username: postgres
password: postgres
host: localhost
Related
I have created a Rails 5.0.2 app with postgres as the database, it all works fine in the development environment.
But when I try to test the app in the production environment (Still on my local machine) I just can't figure out what the password for the database is.
I see this error in the log:
PG::ConnectionBad (FATAL: Peer authentication failed for user "myapp"
My database.yml file:
default: &default
adapter: postgresql
encoding: unicode
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
development:
<<: *default
database: myapp_development
production:
<<: *default
database: myapp_production
username: myapp
password: <%= ENV['MYAPP_DATABASE_PASSWORD'] %>
Can I access the ENV['MYAPP_DATABASE_PASSWORD'] somehow? Was I supposed to set it up when I created the app?
I realize this may be very trivial. Thanks.
I have tried everything I have read on the internet but cannot seem to get it to work. I am trying to set it up on a new project. Here is my database.yml file:
development:
adapter: postgresql
encoding: unicode
database: timetracker_development
pool: 5
username: postgres
password:
host: localhost
test:
adapter: postgresql
encoding: unicode
database: timetracker_test
pool: 5
username: postgres
password:
host: localhost
production:
adapter: postgresql
encoding: unicode
database: timetracker_production
pool: 5
username: timetracker
password:
And the error i get on my web page:
'postgresql' database is not configured. Available: ["development", "adapter", "encoding", "database", "pool", "username", "password", "host", "test", "production"]
I installed postgress via brew and then did the init command and when I type the start command all it says is "server starting". Does this mean it did or didn't start? Anyone know how I can get this to work?
Indenting is significant in YAML.
blah:
blah2: 1
means a different thing to:
blah:
blah2: 1
Here is how your database.yml should look like:
development:
adapter: postgresql
encoding: unicode
database: timetracker_development
pool: 5
username: postgres
password:
host: localhost
test:
adapter: postgresql
encoding: unicode
database: timetracker_test
pool: 5
username: postgres
password:
host: localhost
production:
adapter: postgresql
encoding: unicode
database: timetracker_production
pool: 5
username: timetracker
password:
I created a simple rails application:
1
$ rails new myapp1 -d postrgresql
2. Removed /public/index.html
3. Created the Homecontroller and the actions
4. Wrote the routes
myapp1::Application.routes.draw do
root :to => "home#index"
match 'about' => 'home#about'
match 'contacts' => 'home#contacts'
match 'projects' => 'home#projects'
end
5. Created the views and the default layout
6. The bottom line. Here is the database.yml
development:
adapter: postgresql
encoding: unicode
database: myapp1_db
host: localhost
pool: 5
username: myapp1_user
password: 1234
test:
adapter: postgresql
encoding: unicode
database: myapp1_db
host: localhost
pool: 5
username: myapp1_user
password: 1234
production:
adapter: postgresql
encoding: unicode
database: myapp1_db
host: localhost
pool: 5
username: myapp1_user
password: 1234
and of course I created user and database
sudo -u postgres psql
postgres=# \password
postgres=# create user myapp1_user with password '1234';
postgres=# create database myapp1_db owner myapp1_user;
But there are some worries:
1. Now I don't use any database, but in spite of this the application gives an error
PG::Error FATAL: Peer authentication failed for user "myapp1"
2. It seems like rails turns a blind eye to database.yml. Why does it use the user myapp1 instead of myapp1_user?
Whitespace is significant in YAML.
production:
adapter: postgresql
encoding: unicode
...
password: 1234
Should be:
production:
adapter: postgresql
encoding: unicode
...
password: 1234
Provide host and port in the database.yml file, like this:
development:
adapter: postgresql
encoding: unicode
database: myapp1_db
host: localhost
pool: 5
username: myapp1_user
password: 1234
host: localhost
port: 5432
Works like a charm on Ubuntu 12.04 LTS with Rails 3.2.x and PostgreSQL 9.1.x
In my rails application I have two databases, I was able to get this up and running with following settings
database.yml
development: &defaults
adapter: mysql
encoding: utf8
database: <Database1>
username: <user_name>
password: <password>
host: localhost
second_development: &defaults
adapter: mysql
encoding: utf8
database: <Database2>
username: <user_name>
password: <password>
host: localhost
test: &defaults
adapter: mysql
encoding: utf8
database: <Database1_test>
username: <user_name>
password: <password>
host: localhost
second_test: &defaults
adapter: mysql
encoding: utf8
database: <Database2_test>
username: <user_name>
password: <password>
host: localhost
But the problem is when running the test cases, I'm using 'mocha', 'guard' and 'notahat-machinist', and when I try to run the test cases, it first runs the schema.rb file. But the problem is it creates the schema from the first test database only
test: &defaults
adapter: mysql
encoding: utf8
database: <Database1_test>
username: <user_name>
password: <password>
host: localhost
this will makes the test related to the second test database 'Database2_test' fail. What would be the workaround for this.
to generate a schema.rb file which has both the database schema.
thanks in advance
The schema.rb generate is define by the connection. So you need use the good connection in your test to have the good schema.
Rails new app.
The current database.yml is like that:
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
# 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: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000
I need to edit this for postgresql database.
How can I do this?
Simply:
development:
adapter: postgresql
encoding: unicode
database: blog_development
pool: 5
username: blog
password:
host: localhost
Source: Configuring Rails Applications
development:
adapter: postgresql
encoding: utf8
database: name
username: hading
password: my_db_password
pool: 5 # not mandatory
timeout: 5000 # not mandatory
host: localhost
port: your postgresql port number (5432 or 5433)
As Zabba said it's
development:
adapter: postgresql
encoding: unicode
database: blog_development
pool: 5
username: blog
password:
As mentioned in the Configuring Rails Applications. But you might want an additional min_messages: WARNING, to get rid of the nasty NOTICE messages postgresql gives you during a migration. So my database.yml entry looks like this
development:
adapter: postgresql
encoding: unicode
database: blog_development
pool: 5
username: blog
password:
min_messages: WARNING
You might be interested in generating new app with postgres default:
rails new myapp --database=postgresql
as mentioned here: https://devcenter.heroku.com/articles/getting-started-with-rails4
development:
adapter: postgresql
encoding: utf8
database: name
username: hading
password: my_db_password
host: localhost # not mandatory
pool: 5 # not mandatory
timeout: 5000 # not mandatory
Simply use
rails new app_name --database=postgresql
or if existing application try
development:
adapter: postgresql
encoding: unicode
database: app_dev
pool: 5
username: username
password: password
host: localhost
Another way is to have the common values in &default and then have individual values for the other environments, which can be based on environment variables:
default: &default
adapter: postgresql
encoding: unicode
port: <%= ENV.fetch("POSTGRESQL_PORT", "5432") %>
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
username: <%= ENV['POSTGRESQL_USER_NAME'] %>
password: <%= ENV.fetch("POSTGRESQL_PASSWORD", "myS3cr3tP4ssw0rd") %>
host: <%= ENV['POSTGRESQL_HOST'] %>
development:
<<: *default
database: <%= ENV['POSTGRESQL_DB'] %>-development
host: db
test:
<<: *default
database: <%= ENV['POSTGRESQL_DB'] %>-test
host: db
production:
<<: *default
database: <%= ENV['POSTGRESQL_DB'] %>
Here all the values can come from environment variables (if you use Docker or Bitbucket Pipelines) or you can have them in your .env files.