pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Laurenz Albe <laurenz.albe@cybertec.at>
To: Bernd Lentes <bernd.lentes@helmholtz-muenchen.de>
To: Paul Smith* <paul@pscs.co.uk>
To: pgsql-admin@lists.postgresql.org <pgsql-admin@lists.postgresql.org>
Subject: Re: Update "usename" in pg_user
Date: Tue, 14 Nov 2023 17:42:00 +0100
Message-ID: <ac2d7977b5f819a21eb7af93c9e954ab9fefbb5f.camel@cybertec.at> (raw)
In-Reply-To: <PR3PR04MB7340875E4F0EE41F263D58D4D6B2A@PR3PR04MB7340.eurprd04.prod.outlook.com>
References: <PR3PR04MB73409EB3F2695DA61418F784D6B2A@PR3PR04MB7340.eurprd04.prod.outlook.com>
	<79d4ec67-40b2-427f-aa40-2588bacb4556@pscs.co.uk>
	<PR3PR04MB7340875E4F0EE41F263D58D4D6B2A@PR3PR04MB7340.eurprd04.prod.outlook.com>

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





view thread (10+ messages)  latest in thread

Message-ID: <ac2d7977b5f819a21eb7af93c9e954ab9fefbb5f.camel@cybertec.at>
Permalink:  ../ac2d7977b5f819a21eb7af93c9e954ab9fefbb5f.camel@cybertec.at/
Also on:    postgresql.org/message-id/ac2d7977b5f819a21eb7af93c9e954ab9fefbb5f.camel@cybertec.at

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-admin@postgresql.org
  Cc: laurenz.albe@cybertec.at, bernd.lentes@helmholtz-muenchen.de, paul@pscs.co.uk, pgsql-admin@lists.postgresql.org
  Subject: Re: Update "usename" in pg_user
  In-Reply-To: <ac2d7977b5f819a21eb7af93c9e954ab9fefbb5f.camel@cybertec.at>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox