Travis CI: FATAL: role does not exist - ruby-on-rails

I'm trying to get my application working w/ Travis CI but I keep getting: FATAL: role "skateparks" does not exist. Any ideas on what I could be doing wrong? I've followed their documentation.

For the record, put something like this in your .travis.yml:
before_script:
- psql -c "CREATE USER skateparks WITH PASSWORD 'skateparks';" -U postgres

Your database.yml has this:
development:
adapter: postgresql
encoding: utf8
database: skateparks_development
username: skateparks
password:
template: template0 # Required for UTF8 encoding
Note the username: skateparks part. Either drop that or create the role with something like:
create role skateparks login
from the psql shell.

This worked for me
from bash...
createuser blog
from psql prompt
ALTER USER blog CREATEDB;
my database.yml
development:
adapter: postgresql
encoding: unicode
database: blog_development
pool: 5
username: blog
password:

Related

ActiveRecord::NoDatabaseError: FATAL: role "postgres" does not exist when I try to migrate bd in rails

I cloned a friend's git repo and I'm trying to migrate the db. I started postgres, but when I run rails db:migrate, I keep getting the errors:
Rails Error: Unable to access log file.
and
ActiveRecord::NoDatabaseError: FATAL: role "postgres" does not exist
I've tried all available solutions online but keep getting the same error. Does anyone know what I'm doing wrong?
Try the following
Setting Up Postgres
Create a Postgres user for the Rails app we'll create in the next step. To do this, switch into the Postgres user:
su - postgres
Then create a user (or a "role", as Postgres calls it):
create role myapp with createdb login password 'password1';
and make sure you have config/database.yml
development:
adapter: postgresql
encoding: unicode
database: myapp_development
pool: 5
username: myapp
password: password1
test:
adapter: postgresql
encoding: unicode
database: myapp_test
pool: 5
username: myapp
password: password1
The solution for me was:
createuser -s postgres
After I ran that on the command line my rake task to create the DB worked

FATAL: Peer authentication failed for user "shop"

What I did:
sudo -u postgres psql
CREATE ROLE shop CREATEDB LOGIN PASSWORD 'kurt1245';
Then I cloned a repository from GitHub (a rails application which uses pg), bundle install, edit database.yml to write my password and now after rake db:create (also setup and migrate) doesn't work.
database.yml:
development:
adapter: postgresql
encoding: unicode
database: shop_development
pool: 5
username: shop
password: kurt1245
test:
adapter: postgresql
encoding: unicode
database: shop_test
pool: 5
username: shop
password: kurt1245
Please Add host to your database.yml file. Hope it will help you.
development:
adapter: postgresql
encoding: unicode
host: localhost
database: shop_development
pool: 5
username: shop
password: kurt1245
test:
adapter: postgresql
encoding: unicode
host: localhost
database: shop_test
pool: 5
username: shop
password: kurt1245
I've had the same error a few days back.
Edit the /etc/postgresql/$version/main/pg_hba.conf
You can check what version you're using in the psql console as select VERSION();
Inside pg_hba.conf change
local all postgres peer
to:
local all postgres md5
Peer Authentication explained
19.3.7. Peer Authentication
The peer authentication method works by obtaining the client's
operating system user name from the kernel and using it as the allowed
database user name (with optional user name mapping). This method is
only supported on local connections.

Cannot seem to use development database

I updated my database.yml file to look like so:
test:
adapter: postgresql
encoding: unicode
database: startpoint_test
hostname: localhost
pool: 5
username: postgres
password: password
development:
adapter: postgresql
encoding: unicode
database: startpoint_dev
pool: 5
username: postgres
password: password
And now it seems when I run my application, and sign up a new user the development database does not get a new user inserted into it ...
The tests all pass for signing up a new user
Have you tried using
rake db:create:all
and then
rake db:test:prepare

Rails: How do I change my database from SQLite to PG while in Development?

I generated my rails app with the default SQLite database, but after creating a few models and migrating a few times, I want to change it to Postgresql.
I added the postgres gem to my Gemfile, bundle install, then I replaced all my database.yml code from
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000
to
default: &default
adapter: postgresql
encoding: unicode
pool: 5
username: postgres
password: mypass
development:
<<: *default
database: sample_app_development
test:
<<: *default
database: sample_app_test
production:
<<: *default
database: sample_app_production
I get a FATAL: password authentication failed for user "postgres" error even though the password is correct. Is it because I am missing a step? Am I supposed to tell PG using pg Admin III that I want to add this app to my server? Am I supposed to create a new role/connection?
I have run into this problem a few times and don't seem to be able to find an answer for this specific problem.
it gives me this when I try to run rake db:drop :
Couldn't drop sample_app_development : #<PGError: FATAL: role "postgres" does not exist
>
Couldn't drop sample_app_test : #<PGError: FATAL: role "postgres" does not exist
>
=========
Edmunds-MacBook-Pro:sample_app edmundmai$ createuser foo
Shall the new role be a superuser? (y/n) n
Shall the new role be allowed to create databases? (y/n) y
Shall the new role be allowed to create more new roles? (y/n) y
Password:
createuser: could not connect to database postgres: FATAL: password authentication failed for user "edmundmai"
Postgres user authentication is a bit weird. The default is to use the same authentication as the OS (at least in Linux). So to get to the Postgres prompt from the command line, you have to do something like this:
sudo -u postgres psql
Note that there's no password - and because the OS takes care of the authentication, there's no need for one (the OS'll ask for your sudo password, though, if required).
So option one is to just strip the password option out of your Rails config file and hope everything works out. Failing that, set up Postgres to accept password-based authentication by editing the pg_hba.conf file (mine's at /etc/postgresql/9.2/main/pg_hba.conf). Here's an example from my local server; the user "postgres" uses the OS's authentication ("peer"), but the user "opengeo" uses a password ("md5"):
# TYPE DATABASE USER ADDRESS METHOD
local all postgres peer
local all opengeo md5
Hope that helps!
To convert your database to postgresql first create a user as below:
$ createuser foo
Shall the new role be a superuser? (y/n) n
Shall the new role be allowed to create databases? (y/n) y
Shall the new role be allowed to create more new roles? (y/n) y
To create a db:
CREATE DATABASE foo_db ENCODING 'UTF8' OWNER foo;
make sure your database.yml looks as below:
development:
adapter: postgresql
encoding: unicode
database: foo_db
pool: 5
username: foo
password:
test:
adapter: postgresql
encoding: unicode
database: foo_test
pool: 5
username: foo
password:
development:
adapter: postgresql
database: postgres
username: postgres
password: ;ernakulam
pool: 5
timeout: 5000
test:
adapter: postgresql
database: postgres
pool: 5
timeout: 5000
production:
adapter: postgresql
database: postgres
pool: 5
timeout: 5000`

Postgresql or psql 'rails db' password error

I am trying to prompt the psql interface to try to create a database, actually following from Dr. Hartl's tutorials http://ruby.railstutorial.org/book/ruby-on-rails-tutorial?version=3.2.
I created the project with:
rails new postgr_ --database=postgresql
I added passwords to the database.yml file:
development:
adapter: postgresql
encoding: unicode
database: postgr__development
pool: 5
username: postgr_
password: 12345
test:
adapter: postgresql
encoding: unicode
database: postgr__test
pool: 5
username: postgr_
password: 12345
production:
adapter: postgresql
encoding: unicode
database: postgr__production
pool: 5
username: postgr_
password: 12345
I then enter into terminal:
$ rails db
And I get the following error after entering my password:
psql: FATAL: password authentication failed for user "postgr_"
I've been going at this a good part of yesterday and all day today and was unable to work around this. I may very well be missing something fundamental, if you spot it please let me know. Thank you!
You're missing the steps to setup the postgresql role and database creation.
This procedure depends on the system you are using. I will assume that you are using a mainstream linux distribution.
First login to the postgresql account. You may use one of the following commands:
$ su - postgres
or
$ sudo -i -u postgres
Once logged in, start the psql program:
$ psql template1
At the psql prompt, create a new user role and a database for your project:
=> create role postgr_ with createdb login password '12345';
Then simply quit the program
=> \q
And logout from the postgresql user account
$ exit
Then you should be able to run the rail db command successfully

Resources