Re: pg_restore but for full user and roles, etc

From: Keith Fiske <keith(dot)fiske(at)crunchydata(dot)com>
To: Wells Oliver <wells(dot)oliver(at)gmail(dot)com>
Cc: pgsql-admin <pgsql-admin(at)postgresql(dot)org>
Subject: Re: pg_restore but for full user and roles, etc
Date: 2024-07-26 17:03:53
Message-ID: CAODZiv6GL6iasg91-uYzfh699NgGBOwTbWWQXeZG9=EwvGy3Gw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

On Fri, Jul 26, 2024 at 12:43 PM Wells Oliver <wells(dot)oliver(at)gmail(dot)com>
wrote:

> I am doing a pg_restore of a database, which is nothing difficult, but I
> also am creating a new server first, and rather than painstakingly making
> sure I create all users and roles etc prior to pg_restore (so we can have
> the same perms), is there some obvious way of doing this I'm unawares of?
>
> --
> Wells Oliver
> wells(dot)oliver(at)gmail(dot)com <wellsoliver(at)gmail(dot)com>
>

pg_restore is only used for custom/directory format dumps done by pg_dump.
Roles are global objects, not per database. So you have to use "pg_dumpall
-g" to grab the global objects. That creates a standard sql file that you
then use "psql -f" to restore.

And to clarify, while the roles themselves are global, the GRANTS are per
database and would be contained in the pg_dump files along with the objects
those grants are for.
--
Keith Fiske
Senior Database Engineer
Crunchy Data - http://crunchydata.com

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Ron Johnson 2024-07-26 17:06:11 Re: pg_restore but for full user and roles, etc
Previous Message Fernando Hevia 2024-07-26 16:56:42 Re: Queries are failing on standby server