R
R
railshello2014-07-22 10:15:03
PostgreSQL
railshello, 2014-07-22 10:15:03

How to set up postgresql in Ruby on Rails?

Every time I create a new project, I have to sudo -u postgres psql and create new databases.
How can this be avoided?
I tried editing pg_hba.conf , restarting the server did not help.
pg_hba.conf :
local all all trust

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
sim3x, 2014-07-22
@railshello

This has nothing to do with rubies.
The file associates the postgres user with the database
/etc/postgresql/9.X/main/pg_hba.conf

# TYPE  DATABASE        USER            ADDRESS                 METHOD
local   railshelloDB         railshelloPG                                 ident map=railshelloMAP
#local   all                      railshelloPG                                 ident map=railshelloMAP

Database user map file with OS user
/etc/postgresql/9.X/main/pg_ident.conf
# MAPNAME       SYSTEM-USERNAME         PG-USERNAME
railshelloMAP       railshello       railshelloPG

tet from your user
psql

D
deep_orange, 2016-03-15
@deep_orange

Fair for Linux.
+ To connect (so as not to delve into pg_hba.conf ) It is
enough to specify host: localhost. For example:

default: &default
  adapter: postgresql
  encoding: unicode
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  username: tester
  password: tester
  host: localhost # <- здесь или по месту в development, test

development:
  <<: *default
  database: awesome_development

The thing is that the default is to connect via unix-socket, and this, in turn, does not allow "anyone" to connect to the database.
+ User rights
Well, when creating a user, he must have the right to do so:
CREATE ROLE username WITH LOGIN CREATEDB PASSWORD 'secret';
--- или
CREATE USER username WITH CREATEDB PASSWORD 'secret';

The default user is the system user.

E
Eugene Burmakin, 2014-07-22
@Freika

Enter your database settings (login-password-address-port) in database.yml, and then execute rake db:create in the project folder

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question