Re: Reset Postgresql users password

From: Gurjeet Singh <gurjeet(at)singh(dot)im>
To: Mateusz Henicz <mateuszhenicz(at)gmail(dot)com>
Cc: Gianni Ceccarelli <dakkar(at)thenautilus(dot)net>, pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Reset Postgresql users password
Date: 2023-07-12 20:16:53
Message-ID: CABwTF4VhikBm1wEDDebJ_Lds-oeFW9EFrMgisjAwGYJnOFpGmg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Jul 12, 2023 at 12:42 PM Mateusz Henicz <mateuszhenicz(at)gmail(dot)com> wrote:
>
> You can also just write an sql and execute it, like:
>
> select 'alter user '|| usename ||' with password ''newpassword'';' from pg_user;
> \gexec

Note that the above assumes you're using psql.

For tools other than psql, you'd have to use dynamic SQL something
like the DO block below. It will work on psql, just as well.

DO $$
declare
rec record;
begin
for rec in select
'alter user '|| quote_ident(usename)
||' with password '|| quote_literal('newpassword')
as c from pg_user
loop
raise notice 'Executing command: %', rec.c;
execute rec.c;
end loop;
end;
$$;

Best regards,
Gurjeet
http://Gurje.et

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Johnathan Tiamoh 2023-07-12 20:25:11 Re: Reset Postgresql users password
Previous Message Mateusz Henicz 2023-07-12 19:42:02 Re: Reset Postgresql users password