Redmine postgresql FATAL: Ident authentication failed for user "redmine" - postgresql

Following the these instructions (using postgresql instead of mysql):
http://www.redmine.org/projects/redmine/wiki/Redmine_on_CentOS_installation_HOWTO
when run this command :
RAILS_ENV=production bundle exec rake db:migrate
rake show an error message:
FATAL: Ident authentication failed for user "redmine"
??

It should not be necessary to modify pg_hba.conf for redmine. First check that your database role is configured correctly:
su - postgres
psql -d redmine -U redmine -h localhost
<password challenge>
If the password is accepted, then the next step is to confirm that you have libopenssl-ruby installed.

You should have the postgres user name the same as your linux username
It's easier than modifying "pg_hba.conf" file

This works for me:
psql redmine redmine -h localhost
The -h localhost part makes the difference.

Related

createdb: could not connect to database template1: fatal: password authentication failed for user "user1"

I just installed postgres. and then wrote the following commands in my terminal then
postgres#user /home/user $ createuser -dP CinemaHole
Enter password for new role:
Enter it again:
postgres#user /home/user $ createdb -E utf8 -U Movie CinemaHole
createdb: could not connect to database template1: FATAL: Peer authentication failed for user "Movie"
Here is my pg_hba.conf
pg_hba.conf
Please help me with the issue.
First do not image links for file contents. Instead post the actual text. It makes it easier to include your information in the answer.
Second try:
createdb -E utf8 -U CinemaHole -h localhost Movie
Assuming CinemaHole is the user you really want to use.
The connection that is not working:
createdb -E utf8 -U Movie CinemaHole
is failing because you do not have a -h (host) name so it trying the local socket and your pg_hba.conf has peer authentication for local(socket) connections. Also you are doing -U Movie which is specifying the user Movie which is not what you created. Also user Movie is not the system user you are logged in as, so peer authentication is failing. The connection I suggested you try is using -h localhost and for that your pg_hba.conf use md5(password) authentication.
For more information on pg_hba.conf see here
FYI, you can also do the CREATE ROLE(USER) and CREATE DATABASE using the psql client. Fewer programs to remember.

How to successfully restore a backup using pg_dump in postgresql?

I am new to Postrgresql. I want to create a backup of a production database and restore it in my development instance. Before I touch production, however, I want to make and restore a backup in development. I figured this would be a trivial effort, but that has not been the case.
I connected to psql using the command below.
sudo -u postgres psql
I ran the following command to create my backup inside psql.
\ pg_dump -U postgres -d dbname > /tmp/kp.bak
I included the "!" with the ""of the command above, but Stackoverflow is having trouble rendering that combination of characters
After that it prompted for a password. When I give it the correct password I get the following error. I reset the password for the PostgreSQL user using the ALTER PASSWORD command, so I know I have the correct password.
FATAL: password authentication failed for user "postgresql"
Since that doesn't work, I configured the pg_hba.conf to not require one and restarted the service. This has had no effect, as I am still prompted for a password when I try to restore. This is the first uncommented line in pg_hba.conf.
local all all trust
Here is the command I am using to do the restore.
\ pg_dump -U postgresql -h localhost -f \tmp\kp.bak dbname;
I am at a loss at how to move forward with this. Can anyone tell me what I am missing?
Thanks
Starting psql just to shell out to pg_dump doesn't make any sense. Just do it directly:
sudo -u postgres pg_dump ....
But once you have moved away from "peer" as your authentication method, there is no point in using the sudo at all, so just do it even more directly:
pg_dump ....
FATAL: password authentication failed for user "postgresql"
I don't find it believable that you specified -U postgres, yet the error message says user "postgresql". Please double check your post for spelling and typing errors.
I eventually got it to work with the following commands
sudo -U postgres psql
Then
\! pg_dump -U postgres -d dbname > /tmp/dbname.bak
Doing this outside of psql did not work. I received the following error despite running with sudo.
bash: /tmp/dbname.bak: Permission denied

How to connect to an alternative local postgresql cluster for the fist time?

In Ubuntu 16.04 I created second postgres database cluster, called cmg, with a local user as the admin user:
pg_create -u "local_username" -g "local_usergroup" -d /path/to/data/dir 9.5 cmg
The cluster was started with:
pg_ctrlcluster 9.5 cmg start
which ran successfully (pg_lsclusters show both are online)
The problem is I cannot connect to the cluster using psql as is normally done.
I tried using:
psql -h 127.0.0.1 -w -p5433 -U local_username
which fails with:
psql: fe_sendauth: no password supplied"
Is there any way to connect to the specific cluster?
use psql -h your_socket_dir -p5433 -U postgres to connect locally (uses peer auth by default - thus high chahce to login wothout password)
once logged in - set up password (create user if needed) and use it connecting remotely
psql -h 127.0.0.1 -p5433 -U local_username
in your connect string you had -w which is never ask for a password https://www.postgresql.org/docs/current/static/app-psql.html which would by default work only for local connections
I think the default pg_hba.conf when you start up a new cluster expects you to authenticate with peer connections, so you need to change user to your local user before connecting
[root#server~]# su - local_username
>> Enter password:
> password
[local_username#server~]# psql -h 127.0.0.1 -p 5433
You can check your pg_hba.conf file in /path/to/data/dir/pg_hba.conf to see how it expects you to authenticate.
Alternatively, if you cannot get access as your 'local_username' then instead su to postgres user in the instructions above and it should work

Heroku pg:push psql: FATAL: password authentication failed for user

I know similar questions have been asked but none of the solutions have worked. I am trying to push my local db to my Heroku db, and I keep getting psql: FATAL: password authentication failed for user "windows username".
I am on windows, so I tried SET PGUSER=postgres SET PGPASSWORD=password
Then ran heroku pg:push localdb DATABASE_URL --app herokuapp
But am still getting this stupid password error. The thing is it still looks like it is using my windows user name and not postgres username.... how do I resolve this?
Thanks to Heroku support I was finally able to get this to work. So for Windows users, these are the steps:
First you want to dump your local database out to a dump file:
pg_dump --verbose -F c -Z 0 -U postgres -h localhost -p 5432 yourdbname > local.dump
Then you want to grab the connection string from your heroku application config vars:
heroku config:get DATABASE_URL
Then you want to pick out the username / hostname / databasename parts from the connection string, ie: postgres:// username : password # hostname : port / databasename
One warning, running this against a production database with real data is something you want to avoid so be careful with pg_restore. When running this manually you run the risk of mangling your data without the CLI check, so you may want to manually verify that the target database is empty first.
pg_restore --verbose --no-acl --no-owner -U username -h hostname -p 5432 -d databasename < local.dump
Then when prompted for a password, just paste in the password from the connection string
Run SET PGUSER=postgres. This is important as otherwise heroku will use a different user and your password will not work.
Run heroku pg:push localdb DATABASE_URL --app herokuapp
Enter your password for postgres when it prompts.
I just faced the exact same problem and was successful in resolving this.
Rather than use the single line 'heroku pg:push' command with / without username/password, I relied instead on 2-steps:
Step-1: pg_dump
Step-2: pg_restore
This as pointed out by https://stackoverflow.com/users/4051445/na-peters above
as well as briefly hinted by Heroku at:
https://devcenter.heroku.com/articles/heroku-postgresql#pg-psql
Key thing is the password to enter is NOT the password you'd use when accessing your local Postgresql database. Instead, the password is a 64-character string you will obtain from:
heroku config:get DATABASE_URL -a
To extract it follow instructions by NA Peters above (it is the y string between : and # in the postgres://xxxxxxx:yyyyyyyyyyyyyyyyyyyyyyyy#hhhhhh:5432/dddddd
Expect it to work
For you Windows PowerShell folks out there struggling with the restore, try:
Get-Content -raw local.dump | pg_restore -F c --verbose --no-acl --no-owner -U <username> -h <hostname> -p 5432 -d <databasename>
Then paste the password in when prompted.

Ecto Postgres install error password authentication failed

I created a phoenix project from the hello example using digital ocean. I entered the username and password from the etc/motd.tail file. I keep getting the error message below. I am a beginner and for some reason I just cannot get ecto to install correctly.
** (Mix) The database for Hello.Repo couldn't be created, reason given: psql: FATAL: password authentication failed for user "elixir"
FATAL: password authentication failed for user "elixir"
You can use the following Postgress database credentials:
* User: elixir
* Pass: ***
install. Any help would be appreciated.
I get the same error using Ubuntu 14.04 and I corrected resetting the 'postgres' password:
$ sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'postgres';"
and restart postgres service:
sudo service postgresql restart
I assume this error is happening on the mix ecto.create task?
This happens because Ecto uses psql to create the database, however this is no longer the case in the upcoming Ecto 2.0.
The following GitHub issue shows the same issue https://github.com/elixir-lang/ecto/issues/1207
The relevant comment with the fix is https://github.com/elixir-lang/ecto/issues/1207#issuecomment-172570064:
My database config (pg_hba.conf) was apparently wrong.
For anyone else encountering this:
host all my_user 127.0.0.1/32 trust will not work
host all my_user localhost trust will work
Please check your pg_hba.conf (likely in /etc/postsgresql/9.x/pg_hba.conf).
We just need to create a new postgresql username and password according to the files inside config folder using this db method
$ sudo -u postgres createuser <username>
$ sudo -u postgres createdb <dbname>
$ sudo -u postgres psql
psql=# alter user <username> with encrypted password '<password>';
psql=# grant all privileges on database <dbname> to <username> ;
I needed to update the pg_hba.conf to make this work.
I am using Fedora, so get to /var/lib/pgsql/data
# "local" is for Unix domain socket connections only
local all postgres peer
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 ident
Then I created an elixir user in postgres with databse creation capabilities and configured it in dev.exs (user/password/database)