Re: Reset Postgresql users password

Поиск
Список
Период
Сортировка
От Johnathan Tiamoh
Тема Re: Reset Postgresql users password
Дата
Msg-id CACoPQdasnttEJ_amDnj02qu=e9i_bP80OWKG-+ihro+e2AucaQ@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Reset Postgresql users password  (Gurjeet Singh <gurjeet@singh.im>)
Список pgsql-general
Thank you all very much. 

I really appreciate !!

On Wed, Jul 12, 2023 at 4:17 PM Gurjeet Singh <gurjeet@singh.im> wrote:
On Wed, Jul 12, 2023 at 12:42 PM Mateusz Henicz <mateuszhenicz@gmail.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


В списке pgsql-general по дате отправления:

Предыдущее
От: Gurjeet Singh
Дата:
Сообщение: Re: Reset Postgresql users password
Следующее
От: "David G. Johnston"
Дата:
Сообщение: Re: Reset Postgresql users password