PostgreSQL settings on Mac - postgresql

After attempt of all bases and uses deleting, I try to set postgresql again.
For this purpose I try to change the superuser password.
I enter in console
MacBook-Pro-Andrej:~ andrej$ sudo su - postgres
And system requests password.
But what the password may be, when I changed pb_hba.cfg as follows
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
local replication all trust
host replication all 127.0.0.1/32 trust
host replication all ::1/128 trust
in Log
FATAL: database "andrej" does not exist
But what is database "andrej", when I deleted all bases?
I try to delete this base ones more:
sudo -u postgres dropdb andrej
But system requests password...

You start your command with sudo so you are prompted for your OS password. Try to provide that password and the command should execute without any problem.

Related

psql: error: could not connect to server: FATAL: Peer authentication failed for user "postgres"

i installed and setup postgresql-12 with the commands from here [https://www.postgresql.org/download/linux/redhat/]
yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
yum install postgresql12
yum install postgresql12-server
/usr/pgsql-12/bin/postgresql-12-setup initdb
systemctl enable postgresql-12
systemctl start postgresql-12
i then tried to log into the database
psql postgres postgres
i got the error
psql: error: could not connect to server: FATAL: Peer authentication failed for user "postgres"
there are two pg_hba.conf files on my system. i checked the authentication settings, shown below, as recommended here [psql: FATAL: Ident authentication failed for user "postgres"
/data/pg_data_dir/pg_hba.conf
# TYPE DATABASE USER ADDRESS METHOD
host all all 0.0.0.0/0 md5
# "local" is for Unix domain socket connections only
local all all md5
# 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 all trust
host replication all 127.0.0.1/32 trust
host replication all ::1/128 trust
/var/lib/pgsql/12/data/pg_hba.conf
# 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 md5
# IPv6 local connections:
host all all ::1/128 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all trust
host replication all 127.0.0.1/32 trust
host replication all ::1/128 trust
the authentication settings look OK, so i'm not sure what to do from here.
EDIT - To make this more structured and usable.
First, you need to understand what each of those authentification methods mean, there is a ton on infromation in here about this. Long story short, at this stage, the one you'll likely be interested in is md5 which is a hashed password, or trust which is no password.
After installing the postgres on your machine, you'll need to become the postgres user and then attempt psql
~# su -l postgres --assume you're postgres
~$ psql --connect
psql (xx.x ))
Type "help" for help.
postgres=#
Once you're in, you can set a new password for that user:
postgres=# \password postgres
To prevent this from happening, you'll need to ask postgres where the hba file is:
postgres=# SHOW hba_file;
Use your favourite text editor and modify it to fulfill your needs.
Also you need to make sure you reload the postgresql service, the command is:
sudo systemctl reload postgresql-12.service

psql: FATAL: password authentication failed

When ever I am trying to run psql in the command line, it is asking for a Password: .
I'm not too sure what the username and password is.
I installed postgresql by brew install postgres
pg_hba.conf
# the database superuser. If you do not trust all your local users,
# use another authentication method.
# 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 AustinTruong trust
#host replication AustinTruong 127.0.0.1/32 trust
#host replication AustinTruong ::1/128 trust
Let me know if there is any confusion in my question.
Edit
In other posts, it mentions if I change pg_hba.conf file to local all all trust, I shouldn't require a password. But it is still requesting for a password.
When I run brew info postgres
I've followed the steps from Postgresql: password authentication failed for user "postgres", but i'm still having the same issue. I added the line
local all postgres ident
If you want to create a new database account from you own OS account use:
/usr/local/bin/createdb someusername
See if this works.
Also this other SO Question might help.
Edit:
Use brew info postgres for more information about your version.

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.

psql: FATAL: Ident authentication failed for user "postgres"

I have setup a Ubuntu VPS as per the railcast episode #335. I've worked through a few issues but can't get past the error above when starting Unicorn. I have been testing with this command to connect to the db since.
psql -U postgres -W
I have edited /etc/postgresql/8.4/main/pg_hba.conf as follows
# Database administrative login by Unix domain socket
local all postgres trust
# TYPE DATABASE USER CIDR-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
It doesn't seem to matter what METHOD I use (trust, md5, password) the error is the same.
Any ideas would be appreciated.
Try using psql -U postgres -h localhost
As Per my setting plz use below setting can help this setting dear...
host all all 0.0.0.0/0 md5
host all all 127.0.0.1/32 md5
host all all ::1/128 md5
You usually connect as the postgres user with sudo -u postgres psql. Note that sudo prompts for the current users password (unless you are root), not a user from the database.

Postgresql does not prompt for password

I have a postgresql 8.3 db set up on linux box, together with a user postgres
The pg_hba.conf reads
local all postgres ident sameuser
local all all md5
so no trusted connections from local machine.
Yet when connecting via commandline with psql, no password is asked and all users get all access to all databases.
I'm completely lost here..
Are you sure you did restart or reload of PostgreSQL after pg_hba.conf change?
If yes, type this command from postgres system account (shell):
psql -qAt -c "show hba_file" | xargs grep -v -E '^[[:space:]]*#'
If this will not help - show us output of the command.
You have to change both lines for IPv4 and IPv6 in pg_hba.conf
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
Server restart is needed.
Try
host all all 127.0.0.1/32 md5
instead.