Re: Update "usename" in pg_user

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Bernd Lentes <bernd(dot)lentes(at)helmholtz-muenchen(dot)de>, Paul Smith* <paul(at)pscs(dot)co(dot)uk>, "pgsql-admin(at)lists(dot)postgresql(dot)org" <pgsql-admin(at)lists(dot)postgresql(dot)org>
Subject: Re: Update "usename" in pg_user
Date: 2023-11-14 16:42:00
Message-ID: ac2d7977b5f819a21eb7af93c9e954ab9fefbb5f.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

On Tue, 2023-11-14 at 13:20 +0000, Bernd Lentes wrote:
> >
> > ALTER USER <username> RENAME TO <new_username> is what you want
>
> thanks. Can I do this for all users in one turn ?

You can use the psql client and run

SELECT format('ALTER ROLE %I rename to %I',
usename,
usename || 'helmholtz-munich.de')
FROM pg_user
WHERE usename <> 'postgres' \gexec

\gexec will automatically execute each result line as an SQL statement.

Yours,
Laurenz Albe

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Alvaro Herrera 2023-11-14 17:20:06 Re: Update "usename" in pg_user
Previous Message Scott Ribe 2023-11-14 16:15:03 Re: Dupe Key Violations in Logical Replication with PKs in Place