PG rails db:create InsufficientPrivilege: ERROR: permission denied to create db - ruby-on-rails

I executed:
$ GRANT ALL PRIVILEGES ON db1 to user1
$ ALTER USER user1 CREATEDB
$ ALTER USER user1 CREATEDB
$ ALTER USER user1 WITH 'pass'
But still get an error on
$ rails db:create
config/database.yml:
default: &default
adapter: postgresql
encoding: unicode
# For details on connection pooling, see Rails configuration guide
# https://guides.rubyonrails.org/configuring.html#database-pooling
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
development:
<<: *default
database: pg_app_development
Linux Manjaro.
Rails 6.0.2.2
Ruby 2.7.1
Pg 12.2
Also I do not want to put superuser info in database.yml

$ ALTER USER USER1 WITH CREATEDB

Related

Mysql Connection adapter error

I tried running db:migrate on my app and I'm getting this error.Not sure what is the cause.
My database is MySQL
using MySQL 64-bit connector
ruby version:ruby 2.2.6p396 (2016-11-15 revision 56800) [i386-mingw32]
I've done a google search and I'm not getting anything..Can anyone explain this error pls?
NotImplementedError: NotImplementedError
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/activerecord-5.0.1/lib/active_record/connection_adapters/abstract/database_statements.rb:85:in exec_query'
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/activerecord-5.0.1/lib/active_record/connection_adapters/abstract/database_statements.rb:377:in 'select_prepared'
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/activerecord-5.0.1/lib/active_record/connection_adapters/abstract/database_statements.rb:39:inselect_all'
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/activerecord-5.0.1/lib/active_record/connection_adapters/abstract/query_cache.rb:95:in select_all'
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/activerecord-5.0.1/lib/active_record/querying.rb:39:infind_by_sql'
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/activerecord-5.0.1/lib/active_record/relation.rb:702:in `exec_queries'
C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/rake-12.0.0/exe/rake:27:in <top (required)>'
C:/RailsInstaller/Ruby2.2.0/bin/rake:23:inload'
C:/RailsInstaller/Ruby2.2.0/bin/rake:23:in `'
Tasks: TOP => db:
migrate
You can try this..
Check your config/database.yml file.
your config/database.yml must look like and username, password should be change your mysql's username, password..
default: &default
adapter: mysql2
encoding: utf8
pool: 5
username: username
password: password
socket: /var/run/mysqld/mysqld.sock
development:
<<: *default
database: uBuild-rails_development
test:
<<: *default
database: uBuild-rails_test
production:
<<: *default
database: uBuild-rails_development
username: username
password: password
Also check you Gemfile
gem 'mysql2', '< 0.3' # as stated above
I had the same problem, what I did was to create the project again using this command:
rails new my_project -d=mysql
This way the configuration in database.yml and gemfile is created automatically avoiding problems. You only need to edit database.yml mysql password after this you can use
rails g scaffold Examples attrib1:string attrib2:string
to create views etc
rake db:create
to create the database and then
rake db:migrate
hope this helps...
Database file is in config/database.yml and configuration be
default: &default
adapter: mysql2 #if use postgres the add postgresql
pool: 5
timeout: 5000
username : username #mysql username
password : password #mysql password
development:
<<: *default
database: application_name
test:
<<: *default
database: application_name
production:
<<: *default
database: application_name
Run following command to setup database:
run rake db:create
run rake db:migrate

How do I setup username and password on postgresql database.yml for ruby on rails?

I'm trying to start an application on ruby on rails with postgresql but I'm fairly new and unfamiliar with the process. I'm running into a password error when I try to launch the rail server on localhost:3000. Here is the error I'm getting.
fe_sendauth: no password supplied
# connected server's characteristics.
def connect
#connection = PGconn.connect(#connection_parameters) <!-- This line says there's an issue -->
configure_connection
rescue ::PG::Error => error
if error.message.include?("does not exist")
Anyone know how I can set up the username and password on windows or what I need to do to get around this error?
config/database.yml
development:
adapter: postgresql
encoding: utf8
pool: 5
username: postgres
password: postgres_password
database: development_db
production:
adapter: postgresql
encoding: utf8
pool: 5
username: postgres
password: postgres_password
database: production_db

bundle exec rake db:setup, Rake tasks not supported by 'username' adapter

When I try to run bundle exec rake db:setup ,It gives me this error
and when I change the adapter to my username I got the same error
PG::InsufficientPrivilege: ERROR: permission denied to create database
: CREATE DATABASE "freelance_camp_documents_development" ENCODING = 'unicode'
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "pool"=>5, "database"=>"freelance_camp_documents_development"}
rake aborted!
ActiveRecord::StatementInvalid: PG::InsufficientPrivilege: ERROR: permission denied to create database
: CREATE DATABASE "freelance_camp_documents_development" ENCODING = 'unicode'
/usr/local/share/gems/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:98:in `async_exec'
/usr/local/share/gems/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/postgresql/database_statements.rb:98:in `block in execute'
/usr/local/share/gems/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract_adapter.rb:566:in `block in log'
/usr/local/share/gems/gems/activesupport-
I can't put the whole error here
and here is the database.yml code
default: &default
adapter: postgresql
encoding: unicode
# For details on connection pooling, see rails configuration guide
# http://guides.rubyonrails.org/configuring.html#database-pooling
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
development:
<<: *default
database: freelance_camp_documents_development
test:
<<: *default
database: freelance_camp_documents_test
production:
<<: *default
database: freelance_camp_documents_production
username: freelance_camp_documents
password: <%= ENV['FREELANCE_CAMP_DOCUMENTS_DATABASE_PASSWORD'] %>
PG::InsufficientPrivilege: ERROR: permission denied to create database
The problem here is you don't have sufficient privileges to user freelance_camp_documents on Postgres.
I will suggest to change permissions for user freelance_camp_documents from postgres or just change username to postgres
production:
<<: *default
database: freelance_camp_documents_production
username: postgres
password: <%= ENV['FREELANCE_CAMP_DOCUMENTS_DATABASE_PASSWORD'] %>
postgres user has permissions by default so you don't need to change anything

Rails_admin dont work in production

I got some problems with my rails_admin gem in the production when I trying make first user admin in Rails console.
In the development all works fine. Look at the error and code.
Error terminal:
2.3.0 :001 > u = User.first
ActiveRecord::NoDatabaseError: FATAL: database "myApp_development" does not exist
database.production.yml
default: &default
adapter: postgresql
encoding: UTF-8
pool: 5
development:
<<: *default
database: myApp_development
username: deployer
password: password
test:
<<: *default
database: myApp_test
username: deployer
password: password
production:
<<: *default
database: myApp_production
username: deployer
password: password
To run rails console in the production environment you should use bundle exec rails console production or bundle exec rails console RAILS_ENV=production, the command bundle exec rails console run console in the development env by default.
Create the database table and do
rake db:migrate RAILS_ENV=production
rails console RAILS_ENV=production

ActiveRecord connection not established

I used this command to create an app rails new guestbook
then i used :-
rails generate scaffold Person name:string
and in routes.rb i unhashed the root :to => 'people#index'
then I wrote in the address bar localhost:3000/people and I got the following error :-
ActiveRecord::ConnectionNotEstablished
ActiveRecord::ConnectionNotEstablished
Rails.root: /home/rudraksha/rbtest/gbook
please answer ASAP
Anyways, the problem is that, connection is unable to establish with database.
Have you configured you database.yml as per you database? If not you have to configure it first.
If you are using mysql, you have to install mysql gem by adding it to your gemfile and running bundle install and configure database.yml accordingly.
Example of database.yml with mysql:
development:
adapter: mysql
encoding: utf8
reconnect: false
database: <db_name>
pool: 5
username: <your_mysql_username>
password: <your_mysql_password>
host: localhost
production:
adapter: mysql
encoding: utf8
reconnect: false
database: <db_name>
pool: 5
username: <your_mysql_username>
password: <your_mysql_password>
host: localhost

Resources