Re: Update "usename" in pg_user - Mailing list pgsql-admin

From Laurenz Albe
Subject Re: Update "usename" in pg_user
Date
Msg-id ac2d7977b5f819a21eb7af93c9e954ab9fefbb5f.camel@cybertec.at
Whole thread Raw
In response to RE: Update "usename" in pg_user  (Bernd Lentes <bernd.lentes@helmholtz-muenchen.de>)
List 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



pgsql-admin by date:

Previous
From: Scott Ribe
Date:
Subject: Re: Dupe Key Violations in Logical Replication with PKs in Place
Next
From: Alvaro Herrera
Date:
Subject: Re: Update "usename" in pg_user