114

database.yml:

# SQLite version 3.x
#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem 'sqlite3'
development:
  adapter: postgresql
  encoding: utf8
  database: sampleapp_dev  #can be anything unique
  #host: localhost
  #username: 7stud
  #password: 

  #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: postgresql
  encoding: utf8
  database: sampleapp_test  #can be anything unique
  #host: localhost
  #username: 7stud
  #password: 
  #adapter: sqlite3
  #database: db/test.sqlite3
  pool: 5
  timeout: 5000

production:
  adapter: postgresql
  database: sampleapp_prod   #can be anything unique
  #host: localhost
  #username: 7stud
  #password: 
  #adapter: sqlite3
  #database: db/production.sqlite3
  pool: 5
  timeout: 5000

pg_hba.conf:

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     trust
# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
# IPv6 local connections:
host    all             all             ::1/128                 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local   replication     postgres                                md5
#host    replication     postgres        127.0.0.1/32            md5
#host    replication     postgres        ::1/128                 md5

I changed the METHOD in the first three lines from md5 to trust, but I still get the error.

And no matter what combinations of things I try in database.yml, when I do:

~/rails_projects/sample_app4_0$ bundle exec rake db:create:all

I always get the error:

fe_sendauth: no password supplied

I followed this tutorial to get things setup:

https://pragtob.wordpress.com/2012/09/12/setting-up-postgresql-for-ruby-on-rails-on-linux

Mac OSX 10.6.8
PostgreSQL 9.2.4 installed via enterpriseDB installer
Install dir: /Library/PostgreSQL/9.2
7stud
  • 46,922
  • 14
  • 101
  • 127
  • 1
    And you reloaded your pg_hba.conf file after making changes? – bma Aug 01 '13 at 14:38
  • @bma, How do you reload it? The only way I have been able to connect to the server is using pgAdmin3(in the 9.2 dir). I choose the server, right click, then choose Connnect. So in an attempt to reload the conf file, I disconnected from the server in pgAdmin3, then reconnected. – 7stud Aug 01 '13 at 14:41
  • 3
    You can issue a query: `select pg_reload_conf()` as the superuser, or in pgadmin you can right-click the db name, then click "Reload Configuration" (I think that's what that does, I don't use pgadmin) – bma Aug 01 '13 at 14:45
  • @bma, !$#@%!$^%! That worked. Can you put your comments in an answer? – 7stud Aug 01 '13 at 14:48
  • 1
    I had the same issue. I solved putting username: postgres and password: into my database.yml – Danilo Cândido Nov 19 '18 at 18:19

6 Answers6

91

After making changes to the pg_hba.conf or postgresql.conf files, the cluster needs to be reloaded to pick up the changes.

From the command line: pg_ctl reload

From within a db (as superuser): select pg_reload_conf();

From PGAdmin: right-click db name, select "Reload Configuration"

Note: the reload is not sufficient for changes like enabling archiving, changing shared_buffers, etc -- those require a cluster restart.

simeg
  • 1,889
  • 2
  • 26
  • 34
bma
  • 9,424
  • 2
  • 33
  • 22
  • 2
    I have a follow up question: As far as I know, I never started any server. The only thing I did was install postgress with a Mac OSX installer. Then I spent hours trying to figure out how to use postgres with no luck. I just happened to spot pgAdmin3 in the /Library/PostgreSQL/9.2 dir, so I clicked on it. So how did the server start? And do I need to stop it? – 7stud Aug 01 '13 at 15:02
  • 3
    It likely started after installation completed by the installer (most installers/packages that I've seen do that) – bma Aug 01 '13 at 15:03
  • 1
    Do I need to stop it? How can I do that? I don't like the installer because I'm used to using the command line. – 7stud Aug 01 '13 at 15:05
  • 1
    Stop what? The database cluster, or the installer? If the latter, I have no idea why an installer would still be running. – bma Aug 01 '13 at 16:48
  • 4
    The server...but I figured it out. I did a write up of all the steps I went through to get postgres to work with rails here: http://stackoverflow.com/questions/17971101/how-do-i-start-enterpisedb-postgresql-on-mac-osx-10-6-8/18007600#18007600 – 7stud Aug 02 '13 at 12:14
  • From PGAdmin: right-click db name, select "refresh" – Ahmed Aboud Jan 21 '20 at 14:07
  • I don't seem to have `pg_ctl`. Another option: `sudo systemctl retart postgresql` – nealmcb May 06 '20 at 14:44
9

I just put --password flag into my command and after hitting Enter it asked me for password, which I supplied.

parsecer
  • 4,758
  • 13
  • 71
  • 140
6
psql -U postgres --password

Password:<Enter your password>

Then this will appear. postgres=#

This worked for me

User
  • 1,460
  • 14
  • 11
4

This occurs if the password for the database is not given.

default="postgres://postgres:password@127.0.0.1:5432/DBname"

1

What worked for me was making sure that I had these four lines after development, test, and production in the database.yml file. I leave username and password blank here for security purposes, but fill these out in the actual application

  username: 
  password: 
  host: localhost
  port: 5432
Jeffrey Kozik
  • 201
  • 4
  • 8
0

I also had same issue. But my application was running on docker daemon. I changed those environment in docker-compose.yml file. And also changed in database.yml file. These changes resolved my issue.

 DATABASE_HOST= db
 POSTGRES_PASSWORD= password
Gokce Demir
  • 459
  • 4
  • 5