Re: Reset Postgresql users password

Поиск
Список
Период
Сортировка
Искать
От
Gurjeet Singh
Тема
Re: Reset Postgresql users password
Дата
Msg-id
CABwTF4VhikBm1wEDDebJ_Lds-oeFW9EFrMgisjAwGYJnOFpGmg@mail.gmail.com
Ответ на
Список
Дерево обсуждения
Reset Postgresql users password Johnathan Tiamoh <johnathantiamoh@gmail.com>
Re: Reset Postgresql users password Ron <ronljohnsonjr@gmail.com>
Re: Reset Postgresql users password Chris Travers <chris.travers@gmail.com>
Re: Reset Postgresql users password "Wen Yi" <wen-yi@qq.com>
Re: Reset Postgresql users password Gianni Ceccarelli <dakkar@thenautilus.net>
Re: Reset Postgresql users password Mateusz Henicz <mateuszhenicz@gmail.com>
Re: Reset Postgresql users password Gurjeet Singh <gurjeet@singh.im>
Re: Reset Postgresql users password Johnathan Tiamoh <johnathantiamoh@gmail.com>
Re: Reset Postgresql users password "David G. Johnston" <david.g.johnston@gmail.com>
On Wed, Jul 12, 2023 at 12:42 PM Mateusz Henicz  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 по дате отправления
От: Mateusz Henicz
Дата:
От: Johnathan Tiamoh
Дата:
FAQ