fe_sendauth: no password supplied - postgresql

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

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.

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

psql -U postgres --password
Password:<Enter your password>
Then this will appear. postgres=#
This worked for me

This occurs if the password for the database is not given.
default="postgres://postgres:password#127.0.0.1:5432/DBname"

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

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

Related

Can't override forgettin password for Postgresql on Mac

I am having an issue where I forgot the password to the postgres shell when trying to login as postgres. I looked online and found several different things to do, but none of it worked. I have messed with the pg_hba.conf file but even with that change, it is not working. Here is what my pg_hba.conf file looks like.
# Put your actual configuration here
# ----------------------------------
#
# If you want to allow non-local connections, you need to add more
# "host" records. In that case you will also need to make PostgreSQL
# listen on a non-local interface via the listen_addresses
# configuration parameter, or via the -i or -h command line switches.
# CAUTION: Configuring the system for local "trust" authentication
# allows any local user to connect as any PostgreSQL user, including
# the database superuser. If you do not trust all your local users,
# use another authentication method.
# TYPE DATABASE USER ADDRESS METHOD
# 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.
host replication all 127.0.0.1/32 trust
host replication all ::1/128 trust
and then i ran the follwoing command:
brew services restart postgres
and I keep getting the following error:
omars-MacBook-Pro:postgres omarjandali$ psql -U postgres Password for user postgres: psql: error: could not connect to server: FATAL: password authentication failed for user "postgres"
Anyone know how to fix this issue.
It looks like your command psql -U postgres is attempting to make a socket connection, however you've only got trust authentication set up for TCP/IP connections on localhost.
Try psql -h localhost -U postgres.
Alternatively, add a line to pg_hba.conf setting up trust authentication for socket connections:
host all all trust
and restart PostgreSQL (though you don't actually need to restart it, pg_ctl -D /path/to/data-directory reload should work if you know the actual data directory path).

How to Control PostgreSQL Password authentication both Front end and Command line in Windows 10 and Redhat (Linux)?

Recently I'm using PostgreSQL9.2 both in Windows 10 and Redhat (Linux).
But now I'm little concern about PostgreSQL access authentication.
Late me explain...
When i first installed PostgreSQL in my system i used two different password for two log in role postgres (default) and adempiere (created). In Redhat i use to psql -h localhost -U postgres db_name and psql -h localhost -U adempiere db_name command. Sometime this command wants password sometime not.
Recently I have used ALTER USER postgres WITH PASSWORD 'new_password'; and ALTER USER adempiere WITH PASSWORD 'new_password'; command to change. But here is an another problem. After changed my password when i get database access with psql -h localhost -U adempiere db_name command, i can access with both old_passwod and new_password.
Now what can i do for Strong authentication in my Database both Windows 10 and Redhat (linux) ?
Here is part of my pg_hba.conf for reference:
# Put your actual configuration here
# ----------------------------------
#
# If you want to allow non-local connections, you need to add more
# "host" records. In that case you will also need to make PostgreSQL
# listen on a non-local interface via the listen_addresses
# configuration parameter, or via the -i or -h command line switches.
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 trust
host all all 192.168.2.151/32 trust
host all all 192.168.2.5/32 trust
host all all 192.168.2.6/32 trust
# IPv6 local connections:
host all all ::1/128 md5
# 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
To force password authentication for every connection, replace trust with md5 everywhere in pg_hba.conf and reload the server.
It is dangerously negligent to use PostgreSQL 9.2. Use a later version. For one, this will offer the more secure scram-sha-256 hashing method for password authentication.

Postgres Fatal role name is not permitted to log in

A couple of months ago I started with postgres for Heroku, this worked then. This week I had to use postgres again...
When trying to run a rails server I get:
PG::ConnectionBad
FATAL: role "codemonkey" is not permitted to log in
config/initializers/quiet_assets.rb:7:in `call_with_quiet_assets'
I am using postgres 9.4.4 and I am trying to use the Postgres.app to get in. (I also have pgAdmin3.)
In the terminal:
When I run su postgres psql I get: /usr/local/bin/psql: /usr/local/bin/psql: cannot execute binary file after entering my password.
When I do su postgres' I first get a 'bash-3.2$ environment. This environment (obviously) gives: bash: ALTER: command not found when I type: ALTER ROLE codemonkey WITH LOGIN;
small additional edit
Thanks to a_horse_with_no_name I know that in this bash-3.2$ environment I can start psql (as the superuser). I am not sure if it's working though, I get could not save history to file "/Library/PostgreSQL/9.4/.psql_history": No such file or directory after my SQL command. And am still left with the same FATAL error.
At some point I got:
shell-init: error retrieving current directory: getcwd: cannot access parent directories: Permission denied
When I use the postgres.app elephant symbol and click "open psql" and enter my password I get: psql: FATAL: role "codemonkey" is not permitted to log in after entering my password.
This is what my ~/.bash_profile looks like: Should I do something to add postgres commands? It never recognizes anything.
export PATH=/usr/local/bin:$PATH
# Setting PATH for Python 3.4
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.4/bin:${PATH}"
export PATH
### Added by the Heroku Toolbelt
export PATH="/usr/local/heroku/bin:$PATH"
export PATH="/usr/local/bin:/usr/local/sbin:~/bin:$PATH"
if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi
if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi
This is what my pg_hba.conf looks like:
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all postgres indent
# IPv4 local connections:
host all codemonkey 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 codemonkey trust
#host replication codemonkey 127.0.0.1/32 trust
#host replication codemonkey ::1/128 trust
I think at some point I should be able to give the command ALTER ROLE codemonkey WITH LOGIN;
So I can get through. I wish I knew how.
COMPLETE RE-EDIT
You should see your user's privileges by using this command:
SELECT * FROM pg_roles;
if the rolcanlogin corresponding to the user is set to false (f) then use this command:
ALTER USER username WITH LOGIN;
You don't need to reinstall everything to change password for Postgres user. To change the password run ALTER ROLE youruser PASSWORD 'yourpassword';.
For Heroku(as it's remote connection) you need temporary change ipv4/ipv6 section (depending what you are using) to whitelist your client ip address (x.x.x.x). Don't forget to change in to md5 again after password reset. To apply pg_hba.conf changes restart postgres service.
#IPv4 local connections:
host all youruser x.x.x.x/32 trust
SO has a lot of good answers as well.

Impossible to connect to Postgresql using RubyMine

I've been trying to connect to PostgreSQL using RubyMine but it's always asking for a password.
In a terminal I do connect using:
psql -U postgres
I don't have to input a password.
But, when I tried using RubyMine to connect to PostgreSQL is always asking for a password. I tried input some passwords but they don't work. Any idea?
My settings file:
default: &default
adapter: postgresql
encoding: unicode
# For details on connection pooling, see rails configuration guide
# http://guides.rubyonrails.org/configuring.html#database-pooling
pool: 5
development:
<<: *default
database: portafolio_development
username: postgres
password:
test:
<<: *default
database: portafolio_test
username: postgres
password:
production:
<<: *default
database: portafolio_production
username: portafolio
password: <%= ENV['PORTAFOLIO_DATABASE_PASSWORD'] %>
Edited
My pg_hba.conf:
local all postgres peer
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all peer
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication postgres peer
#host replication postgres 127.0.0.1/32 md5
#host replication postgres ::1/128 md5
Solved
Result that I have two pg_hba.conf files. One for version 9.3 and another for 9.4. I changed the first one to the following and everything is working now:
local all postgres trust
# The same using local loopback TCP/IP connections.
#
# TYPE DATABASE USER ADDRESS METHOD
host all all 127.0.0.1/32 trust
# The same as the previous line, but using a separate netmask column
#
# TYPE DATABASE USER IP-ADDRESS IP-MASK METHOD
host all all 127.0.0.1 255.255.255.255 trust
# The same over IPv6.
#
# TYPE DATABASE USER ADDRESS METHOD
host all all ::1/128 trust
# The same using a host name (would typically cover both IPv4 and IPv6).
#
# TYPE DATABASE USER ADDRESS METHOD
host all all localhost trust

Postgres asks for password, even though pg_hba.conf says trust

I have installed PostgreSQL 9.3 on my Mac. I am trying to do this command:
$ sudo -u postgres psql template1
Password:
Password:
psql: FATAL: password authentication failed for user "postgres"
As you can see, it asks for a password, which I give it. And it fails. I try the password for the postgres user, and the computer password. It always says it fails.
I read that you can change the pg_hba.conf file to not ask for a password. It is below:
> # 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 trust
> host replication postgres 127.0.0.1/32 trust
> host replication postgres ::1/128 trust
From my understanding this should not ask for a password. And yet it does.
Interesting note: it logs in fine in pgAdmin3. But not in terminal.
Update #1:
Tried to restart PostgreSQL after I change the pg_hba.conf file. This is the message I get.
$ pg_ctl -D postgres -l server.log restart
pg_ctl: PID file "postgres/postmaster.pid" does not exist
Is server running?
starting server anyway
pg_ctl: could not read file "postgres/postmaster.opts"
Turns out I had two versions of PostgreSQL installed on my system. 8.4 and 9.3. Whenever 8.4 was installed, all of the defaults were set to used it instead of 9.3. So even though 9.3 would never ask for permissions, or a password, 8.4 would.
Finally was able to kill the 8.4 version, which was running. And redirect traffic to 9.3. It works now!!!
I set 8.4's pg_hba.conf file to trust as well... just in case.