Thread: How to behive if I remove password from postgres role

How to behive if I remove password from postgres role

From
Raivo Rebane
Date:
HI

I wanted to install PostGIS Bundle so that it builds a sample spatial database, but got error - createdb: error: connection to server at "localhost" (::1), port 5432 failed: FATAL:  password authentication failed for user "postgres"
Then I altered role of postgres so, that password = NULL.
Now I am in situation that I can't run any postgres command.
What I must to do ?

Regards,
Raivo


Re: How to behive if I remove password from postgres role

From
Adrian Klaver
Date:
On 3/15/23 09:02, Raivo Rebane wrote:
> HI
> 
> I wanted to install PostGIS Bundle so that it builds a sample spatial 
> database, but got error - createdb: error: connection to server at 
> "localhost" (::1), port 5432 failed: FATAL:  password authentication 
> failed for user "postgres"
> Then I altered role of postgres so, that password = NULL.
> Now I am in situation that I can't run any postgres command.
> What I must to do ?

Edit the 
pg_hba.conf(https://www.postgresql.org/docs/15/auth-pg-hba-conf.html) so 
that the first local line is set to trust as in the 'Example 21.1. 
Example pg_hba.conf Entries' at the bottom of the file. It may already 
be set that way.

In either case when you connect do not use a host setting e.g. do not do 
host=localhost. This will ensure you are connecting to the local socket 
instead and will be using the trust authentication method and not a 
password. Once you are in you can alter the postgres user to have a 
proper password.

> 
> Regards,
> Raivo
> 
> 

-- 
Adrian Klaver
adrian.klaver@aklaver.com




Re: How to behive if I remove password from postgres role

From
Tom Lane
Date:
Raivo Rebane <raivore55@gmail.com> writes:
> Then I altered role of postgres so, that password = NULL.
> Now I am in situation that I can't run any postgres command.
> What I must to do ?

Stop the server, start it in single-user mode (postgres --single),
issue an ALTER USER command to undo the damage.

Or modify pg_hba.conf to let you in without a password.  Local
peer auth, for example, is perfectly secure.

            regards, tom lane