Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get pg_dump to include create user command

Tags:

postgresql

I need to create a dump of all the commands below.

   test=> create user rdstest login password 'rdstest';
   CREATE ROLE
   test=> grant connect on database test to rdstest;
   GRANT
   test=> create user devadmin login password 'devtest';
   CREATE ROLE
   test=> grant connect on database test to devadmin;
   GRANT
   test=> grant rdstest to devadmin with admin option;
   GRANT ROLE
   test=> grant rdstest to devadmin;
   GRANT ROLE
   test=> create schema authorization rdstest;
   CREATE SCHEMA

when i tried to create it using pg_dump as pg_dump -U devadmin -h ****xxx.rds.amazonaws.com test > Outfile.sql

I can only see the schema related commands

CREATE SCHEMA rdstest;
ALTER SCHEMA rdstest OWNER TO rdstest;

How to get pg_dump to include all the commands:create user command,grant connect on database test to rdstest etc.

like image 807
nad87563 Avatar asked Apr 11 '18 21:04

nad87563


People also ask

Does pg_dump include users?

pg_dump is a utility for backing up a PostgreSQL database. It makes consistent backups even if the database is being used concurrently. pg_dump does not block other users accessing the database (readers or writers). pg_dump only dumps a single database.

Can not find pg_dump in a system?

Go to Edit the system environment variables. Then Environement variables. Then Path then add the location of bin of postgres in my case C:\Program Files\PostgreSQL\14\bin\

What is pg_dump and Pg_restore?

Description. pg_restore is a utility for restoring a PostgreSQL database from an archive created by pg_dump in one of the non-plain-text formats. It will issue the commands necessary to reconstruct the database to the state it was in at the time it was saved.

How long does PG dump take?

It took ~60 minutes.


1 Answers

pg_dump can not do that, because pg_dump only dumps a single database and that information is not part of one database, but stored globally in the Postgres "cluster".

You need to use pg_dumpall for that, using the --globals-only option:

pg_dumpall --globals-only  --file=globals.sql
like image 124
a_horse_with_no_name Avatar answered Nov 26 '22 07:11

a_horse_with_no_name