JRuby JDBC Without Username or Password in database.yml - ruby-on-rails

It it possible to use the JDBC Postgres (jRuby) driver without specifying a username and password in the database.yml file? My project database file currently is:
test: &test
adapter: postgresql
encoding: unicode
database: app_test
pool: 5
development: &development
adapter: postgresql
encoding: unicode
database: app_development
pool: 5
production: &production
adapter: postgresql
encoding: unicode
database: app_production
pool: 5
cucumber:
<<: *test
However, this causes the following error on starting the server / console:
ActiveRecord::JDBCError: The driver encountered an unknown error: FATAL: no PostgreSQL user name specified in startup packet
If possible, it would be nice to not include the username and password out of the database.yml configuration file (this works with MRI and the pg gem). Each team members uses a different username for their local installs.

Related

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.

Postgres code in config.database.yml for Rails Angular app

I am following this tutorial http://asanderson.org/posts/2013/06/03/bootstrapping-angular-rails-part-1.html to create an app using rails an angular js and having issues in making postgres code work
When i run rake db :create i get this error
YAML syntax error occurred while parsing database.yml. Please note that YAML must be consistently indented using spaces. Tabs are not allowed. Error: (<unknown>): mapping values are not allowed in this context at line 71 column 11
What username and password should i use in the postgres code in the database.yml file .How do i find out my postgres uername and password .posgres is already installed in the system
Here is the code in database.yml file
default: &default
adapter: postgresql
encoding: unicode
development:
<<: *default
database: blog1_development
development:
adapter: postgresql
encoding: unicode
database: blog_development
pool: 5
username: pguser
password:
test:
<<: *default
database: blog1_test
adapter: postgresql
encoding: unicode
database: blog_test
pool: 5
username: pguser
password:
I recommend you to use password create a password by
opening cmd prompt
enter this to create password
mysqladmin -u pguser password [newpassword]
after creating the password
change your database.yml file
development:
<<: *default
database: blog1_development
development:
adapter: postgresql
encoding: unicode
database: blog_development
pool: 5
username: pguser
password: [new password]
Enter the password correctly give a space after colon<:> in database.yml in password section when entering password

Rails Change Default Projects Database 'sqllite' to PostgreSql

I'm learning ruby. I've created some application and played with it.
i wanted to change the database to postgres. I modified gemfile with
gem 'pg'
[pg already installed in usr/bin/pg]
then update database.yml with
postgresql where sqllite is used.
pg connection bad:
FATAL: role "user" does not exist
i've created some postgres user already. what should i have to change to work with postgres?
development:
adapter: postgresql
database: db/development.postgresql
pool: 5
timeout: 5000
user:
adapter: postgresql
database: db/test.postgresql
pool: 5
timeout: 5000
production:
adapter: postgresql
database: db/production.postgresql
pool: 5
timeout: 5000
If you don't specify a username to connect to PostgreSQL as, libpq will connect using the login username of the current running user.
libpq is what the Pg gem used by Rails uses to connect to PostgreSQL.
So, in your database.yml, specify the PostgreSQL user to connect to the database as with a user: entry. Make sure this corresponds to a user that exists in PostgreSQL, and that pg_hba.conf permits this user to connect.
To learn more, see the client authentication chapter of the PostgreSQL docs.
I know its a two year old question, but I just ran into the same problem, and i fixed it by changing the syntax of config.yml, then I rake db:migrate
default: &default
adapter: postgresql
encoding: unicode
pool: 5
development:
<<: *default
database: yourappnamehere_development
test:
<<: *default
database: yourappnamehere_testdevelopment:
production:
<<: *default
database: YOURAPPNAME_production
username: YOURUSERNAME
password: <%= ENV['YOURAPPNAME_DATABASE_PASSWORD'] %>

no records showing after migration to postgres

Just followed the "Migrating to PostgreSQL" Railscast, migrating my local sqlite3 database to postgres:
here is my database.yml file:
development:
adapter: postgresql
encoding: unicode
database: app_development
pool: 5
host: localhost
username: martinbraun
password:
test:
adapter: postgresql
encoding: unicode
database: app_test
pool: 5
username: mbraun
password:
production:
adapter: postgresql
encoding: utf8
database: app_production
pool: 5
username: mbraun
password:
My postgres server is running on postgressapp on port 5432. It tells me that it's running and I get connection to my database app_development.
However, "which psql" tells me:
/usr/bin/psql
and when I start my app, all the records are not loading, I simply see my application layout and all html stuff which is not related to any records. No error is showing up.
I have verified that my database contains data via rails console, so the migration from sqlite3 to postgres was def successful. I am just wondering why my records are not showing and what I do wrong here?

setting up postgresql development in rails with multiple users in database.yml?

I am in the process of migrating my SQL to Postgresql because I want to develop in the same environment as my production.
I installed Postgres and was able to set my database yml file such that rake db:create:all worked with no problems.
However before I pushed, I realized that the username and password of the postgresql database is only available on my computer. I.e. I created the login role on my computer. When my friend who is also developing on the application, pulls the code, he won't have the username and password created by me on my computer.
Is he supposed to also create the same login role? Or is there a way to leave username / password blank so that everyone who develops can access the application? More importantly, what is the best practice for a situation like this?
I am developing on windows and he is on mac.
My database.yml: username and password left out.
development:
adapter: postgresql
encoding: unicode
database: volatility_development
pool: 5
timeout: 5000
host: localhost
test:
adapter: postgresql
encoding: unicode
database: volatility_test
pool: 5
timeout: 5000
host: localhost
production:
adapter: postgresql
encoding: unicode
database: volatility_production
pool: 5
timeout: 5000
one possibility would be to use a combination of erb and environment variables, for example:
development:
username: <%= ENV['USERNAME'] %>
password: <%= ENV['PASSWORD'] %>
adapter: postgresql
encoding: unicode
database: volatility_development
pool: 5
timeout: 5000
host: localhost
then you could do either of the following:
start your server like so: USERNAME=bob PASSWORD=secret rails s
add the following to your .bashrc
export USERNAME=bob
export PASSWORD=secret

Resources