@@ -74,8 +74,13 @@ static int no_tablespaces = 0;
74
74
static int use_setsessauth = 0 ;
75
75
static int no_security_labels = 0 ;
76
76
static int no_unlogged_table_data = 0 ;
77
+ static int no_role_passwords = 0 ;
77
78
static int server_version ;
78
79
80
+ static char role_catalog [10 ];
81
+ #define PG_AUTHID "pg_authid"
82
+ #define PG_ROLES "pg_roles "
83
+
79
84
static FILE * OPF ;
80
85
static char * filename = NULL ;
81
86
@@ -123,6 +128,7 @@ main(int argc, char *argv[])
123
128
{"use-set-session-authorization" , no_argument , & use_setsessauth , 1 },
124
129
{"no-security-labels" , no_argument , & no_security_labels , 1 },
125
130
{"no-unlogged-table-data" , no_argument , & no_unlogged_table_data , 1 },
131
+ {"no-role-passwords" , no_argument , & no_role_passwords , 1 },
126
132
127
133
{NULL , 0 , NULL , 0 }
128
134
};
@@ -342,6 +348,25 @@ main(int argc, char *argv[])
342
348
exit_nicely (1 );
343
349
}
344
350
351
+ if (no_role_passwords && binary_upgrade )
352
+ {
353
+ fprintf (stderr , _ ("%s: options --no-role-passwords and --binary-upgrade cannot be used together\n" ),
354
+ progname );
355
+ fprintf (stderr , _ ("Try \"%s --help\" for more information.\n" ),
356
+ progname );
357
+ exit_nicely (1 );
358
+ }
359
+
360
+ /*
361
+ * If password values are not required in the dump, switch to
362
+ * using pg_roles which is equally useful, just more likely
363
+ * to have unrestricted access than pg_authid.
364
+ */
365
+ if (no_role_passwords )
366
+ sprintf (role_catalog , "%s" , PG_ROLES );
367
+ else
368
+ sprintf (role_catalog , "%s" , PG_AUTHID );
369
+
345
370
/* Add long options to the pg_dump argument list */
346
371
if (binary_upgrade )
347
372
appendPQExpBufferStr (pgdumpopts , " --binary-upgrade" );
@@ -563,6 +588,7 @@ help(void)
563
588
printf (_ (" --no-security-labels do not dump security label assignments\n" ));
564
589
printf (_ (" --no-tablespaces do not dump tablespace assignments\n" ));
565
590
printf (_ (" --no-unlogged-table-data do not dump unlogged table data\n" ));
591
+ printf (_ (" --no-role-passwords do not dump passwords for roles\n" ));
566
592
printf (_ (" --quote-all-identifiers quote all identifiers, even if not key words\n" ));
567
593
printf (_ (" --use-set-session-authorization\n"
568
594
" use SET SESSION AUTHORIZATION commands instead of\n"
@@ -590,30 +616,33 @@ help(void)
590
616
static void
591
617
dropRoles (PGconn * conn )
592
618
{
619
+ PQExpBuffer buf = createPQExpBuffer ();
593
620
PGresult * res ;
594
621
int i_rolname ;
595
622
int i ;
596
623
597
624
if (server_version >= 90600 )
598
- res = executeQuery ( conn ,
625
+ printfPQExpBuffer ( buf ,
599
626
"SELECT rolname "
600
- "FROM pg_authid "
627
+ "FROM %s "
601
628
"WHERE rolname !~ '^pg_' "
602
- "ORDER BY 1" );
629
+ "ORDER BY 1" , role_catalog );
603
630
else if (server_version >= 80100 )
604
- res = executeQuery ( conn ,
631
+ printfPQExpBuffer ( buf ,
605
632
"SELECT rolname "
606
- "FROM pg_authid "
607
- "ORDER BY 1" );
633
+ "FROM %s "
634
+ "ORDER BY 1" , role_catalog );
608
635
else
609
- res = executeQuery ( conn ,
636
+ printfPQExpBuffer ( buf ,
610
637
"SELECT usename as rolname "
611
638
"FROM pg_shadow "
612
639
"UNION "
613
640
"SELECT groname as rolname "
614
641
"FROM pg_group "
615
642
"ORDER BY 1" );
616
643
644
+ res = executeQuery (conn , buf -> data );
645
+
617
646
i_rolname = PQfnumber (res , "rolname" );
618
647
619
648
if (PQntuples (res ) > 0 )
@@ -631,6 +660,7 @@ dropRoles(PGconn *conn)
631
660
}
632
661
633
662
PQclear (res );
663
+ destroyPQExpBuffer (buf );
634
664
635
665
fprintf (OPF , "\n\n" );
636
666
}
@@ -666,43 +696,43 @@ dumpRoles(PGconn *conn)
666
696
"rolcreaterole, rolcreatedb, "
667
697
"rolcanlogin, rolconnlimit, rolpassword, "
668
698
"rolvaliduntil, rolreplication, rolbypassrls, "
669
- "pg_catalog.shobj_description(oid, 'pg_authid ') as rolcomment, "
699
+ "pg_catalog.shobj_description(oid, '%s ') as rolcomment, "
670
700
"rolname = current_user AS is_current_user "
671
- "FROM pg_authid "
701
+ "FROM %s "
672
702
"WHERE rolname !~ '^pg_' "
673
- "ORDER BY 2" );
703
+ "ORDER BY 2" , role_catalog , role_catalog );
674
704
else if (server_version >= 90500 )
675
705
printfPQExpBuffer (buf ,
676
706
"SELECT oid, rolname, rolsuper, rolinherit, "
677
707
"rolcreaterole, rolcreatedb, "
678
708
"rolcanlogin, rolconnlimit, rolpassword, "
679
709
"rolvaliduntil, rolreplication, rolbypassrls, "
680
- "pg_catalog.shobj_description(oid, 'pg_authid ') as rolcomment, "
710
+ "pg_catalog.shobj_description(oid, '%s ') as rolcomment, "
681
711
"rolname = current_user AS is_current_user "
682
- "FROM pg_authid "
683
- "ORDER BY 2" );
712
+ "FROM %s "
713
+ "ORDER BY 2" , role_catalog , role_catalog );
684
714
else if (server_version >= 90100 )
685
715
printfPQExpBuffer (buf ,
686
716
"SELECT oid, rolname, rolsuper, rolinherit, "
687
717
"rolcreaterole, rolcreatedb, "
688
718
"rolcanlogin, rolconnlimit, rolpassword, "
689
719
"rolvaliduntil, rolreplication, "
690
720
"false as rolbypassrls, "
691
- "pg_catalog.shobj_description(oid, 'pg_authid ') as rolcomment, "
721
+ "pg_catalog.shobj_description(oid, '%s ') as rolcomment, "
692
722
"rolname = current_user AS is_current_user "
693
- "FROM pg_authid "
694
- "ORDER BY 2" );
723
+ "FROM %s "
724
+ "ORDER BY 2" , role_catalog , role_catalog );
695
725
else if (server_version >= 80200 )
696
726
printfPQExpBuffer (buf ,
697
727
"SELECT oid, rolname, rolsuper, rolinherit, "
698
728
"rolcreaterole, rolcreatedb, "
699
729
"rolcanlogin, rolconnlimit, rolpassword, "
700
730
"rolvaliduntil, false as rolreplication, "
701
731
"false as rolbypassrls, "
702
- "pg_catalog.shobj_description(oid, 'pg_authid ') as rolcomment, "
732
+ "pg_catalog.shobj_description(oid, '%s ') as rolcomment, "
703
733
"rolname = current_user AS is_current_user "
704
- "FROM pg_authid "
705
- "ORDER BY 2" );
734
+ "FROM %s "
735
+ "ORDER BY 2" , role_catalog , role_catalog );
706
736
else if (server_version >= 80100 )
707
737
printfPQExpBuffer (buf ,
708
738
"SELECT oid, rolname, rolsuper, rolinherit, "
@@ -712,8 +742,8 @@ dumpRoles(PGconn *conn)
712
742
"false as rolbypassrls, "
713
743
"null as rolcomment, "
714
744
"rolname = current_user AS is_current_user "
715
- "FROM pg_authid "
716
- "ORDER BY 2" );
745
+ "FROM %s "
746
+ "ORDER BY 2" , role_catalog );
717
747
else
718
748
printfPQExpBuffer (buf ,
719
749
"SELECT 0 as oid, usename as rolname, "
@@ -846,7 +876,8 @@ dumpRoles(PGconn *conn)
846
876
appendPQExpBuffer (buf , " CONNECTION LIMIT %s" ,
847
877
PQgetvalue (res , i , i_rolconnlimit ));
848
878
849
- if (!PQgetisnull (res , i , i_rolpassword ))
879
+
880
+ if (!PQgetisnull (res , i , i_rolpassword ) && !no_role_passwords )
850
881
{
851
882
appendPQExpBufferStr (buf , " PASSWORD " );
852
883
appendStringLiteralConn (buf , PQgetvalue (res , i , i_rolpassword ), conn );
@@ -897,19 +928,21 @@ dumpRoles(PGconn *conn)
897
928
static void
898
929
dumpRoleMembership (PGconn * conn )
899
930
{
931
+ PQExpBuffer buf = createPQExpBuffer ();
900
932
PGresult * res ;
901
933
int i ;
902
934
903
- res = executeQuery ( conn , "SELECT ur.rolname AS roleid, "
935
+ printfPQExpBuffer ( buf , "SELECT ur.rolname AS roleid, "
904
936
"um.rolname AS member, "
905
937
"a.admin_option, "
906
938
"ug.rolname AS grantor "
907
939
"FROM pg_auth_members a "
908
- "LEFT JOIN pg_authid ur on ur.oid = a.roleid "
909
- "LEFT JOIN pg_authid um on um.oid = a.member "
910
- "LEFT JOIN pg_authid ug on ug.oid = a.grantor "
940
+ "LEFT JOIN %s ur on ur.oid = a.roleid "
941
+ "LEFT JOIN %s um on um.oid = a.member "
942
+ "LEFT JOIN %s ug on ug.oid = a.grantor "
911
943
"WHERE NOT (ur.rolname ~ '^pg_' AND um.rolname ~ '^pg_')"
912
- "ORDER BY 1,2,3" );
944
+ "ORDER BY 1,2,3" , role_catalog , role_catalog , role_catalog );
945
+ res = executeQuery (conn , buf -> data );
913
946
914
947
if (PQntuples (res ) > 0 )
915
948
fprintf (OPF , "--\n-- Role memberships\n--\n\n" );
@@ -939,6 +972,7 @@ dumpRoleMembership(PGconn *conn)
939
972
}
940
973
941
974
PQclear (res );
975
+ destroyPQExpBuffer (buf );
942
976
943
977
fprintf (OPF , "\n\n" );
944
978
}
@@ -1298,9 +1332,9 @@ dumpCreateDB(PGconn *conn)
1298
1332
* databases.
1299
1333
*/
1300
1334
if (server_version >= 90600 )
1301
- res = executeQuery ( conn ,
1335
+ printfPQExpBuffer ( buf ,
1302
1336
"SELECT datname, "
1303
- "coalesce(rolname, (select rolname from pg_authid where oid=(select datdba from pg_database where datname='template0'))), "
1337
+ "coalesce(rolname, (select rolname from %s where oid=(select datdba from pg_database where datname='template0'))), "
1304
1338
"pg_encoding_to_char(d.encoding), "
1305
1339
"datcollate, datctype, datfrozenxid, datminmxid, "
1306
1340
"datistemplate, "
@@ -1314,43 +1348,43 @@ dumpCreateDB(PGconn *conn)
1314
1348
"AS rdatacl, "
1315
1349
"datconnlimit, "
1316
1350
"(SELECT spcname FROM pg_tablespace t WHERE t.oid = d.dattablespace) AS dattablespace "
1317
- "FROM pg_database d LEFT JOIN pg_authid u ON (datdba = u.oid) "
1318
- "WHERE datallowconn ORDER BY 1" );
1351
+ "FROM pg_database d LEFT JOIN %s u ON (datdba = u.oid) "
1352
+ "WHERE datallowconn ORDER BY 1" , role_catalog , role_catalog );
1319
1353
else if (server_version >= 90300 )
1320
- res = executeQuery ( conn ,
1354
+ printfPQExpBuffer ( buf ,
1321
1355
"SELECT datname, "
1322
- "coalesce(rolname, (select rolname from pg_authid where oid=(select datdba from pg_database where datname='template0'))), "
1356
+ "coalesce(rolname, (select rolname from %s where oid=(select datdba from pg_database where datname='template0'))), "
1323
1357
"pg_encoding_to_char(d.encoding), "
1324
1358
"datcollate, datctype, datfrozenxid, datminmxid, "
1325
1359
"datistemplate, datacl, '' as rdatacl, "
1326
1360
"datconnlimit, "
1327
1361
"(SELECT spcname FROM pg_tablespace t WHERE t.oid = d.dattablespace) AS dattablespace "
1328
- "FROM pg_database d LEFT JOIN pg_authid u ON (datdba = u.oid) "
1329
- "WHERE datallowconn ORDER BY 1" );
1362
+ "FROM pg_database d LEFT JOIN %s u ON (datdba = u.oid) "
1363
+ "WHERE datallowconn ORDER BY 1" , role_catalog , role_catalog );
1330
1364
else if (server_version >= 80400 )
1331
- res = executeQuery ( conn ,
1365
+ printfPQExpBuffer ( buf ,
1332
1366
"SELECT datname, "
1333
- "coalesce(rolname, (select rolname from pg_authid where oid=(select datdba from pg_database where datname='template0'))), "
1367
+ "coalesce(rolname, (select rolname from %s where oid=(select datdba from pg_database where datname='template0'))), "
1334
1368
"pg_encoding_to_char(d.encoding), "
1335
1369
"datcollate, datctype, datfrozenxid, 0 AS datminmxid, "
1336
1370
"datistemplate, datacl, '' as rdatacl, "
1337
1371
"datconnlimit, "
1338
1372
"(SELECT spcname FROM pg_tablespace t WHERE t.oid = d.dattablespace) AS dattablespace "
1339
- "FROM pg_database d LEFT JOIN pg_authid u ON (datdba = u.oid) "
1340
- "WHERE datallowconn ORDER BY 1" );
1373
+ "FROM pg_database d LEFT JOIN %s u ON (datdba = u.oid) "
1374
+ "WHERE datallowconn ORDER BY 1" , role_catalog , role_catalog );
1341
1375
else if (server_version >= 80100 )
1342
- res = executeQuery ( conn ,
1376
+ printfPQExpBuffer ( buf ,
1343
1377
"SELECT datname, "
1344
- "coalesce(rolname, (select rolname from pg_authid where oid=(select datdba from pg_database where datname='template0'))), "
1378
+ "coalesce(rolname, (select rolname from %s where oid=(select datdba from pg_database where datname='template0'))), "
1345
1379
"pg_encoding_to_char(d.encoding), "
1346
1380
"null::text AS datcollate, null::text AS datctype, datfrozenxid, 0 AS datminmxid, "
1347
1381
"datistemplate, datacl, '' as rdatacl, "
1348
1382
"datconnlimit, "
1349
1383
"(SELECT spcname FROM pg_tablespace t WHERE t.oid = d.dattablespace) AS dattablespace "
1350
- "FROM pg_database d LEFT JOIN pg_authid u ON (datdba = u.oid) "
1351
- "WHERE datallowconn ORDER BY 1" );
1384
+ "FROM pg_database d LEFT JOIN %s u ON (datdba = u.oid) "
1385
+ "WHERE datallowconn ORDER BY 1" , role_catalog , role_catalog );
1352
1386
else
1353
- res = executeQuery ( conn ,
1387
+ printfPQExpBuffer ( buf ,
1354
1388
"SELECT datname, "
1355
1389
"coalesce(usename, (select usename from pg_shadow where usesysid=(select datdba from pg_database where datname='template0'))), "
1356
1390
"pg_encoding_to_char(d.encoding), "
@@ -1361,6 +1395,8 @@ dumpCreateDB(PGconn *conn)
1361
1395
"FROM pg_database d LEFT JOIN pg_shadow u ON (datdba = usesysid) "
1362
1396
"WHERE datallowconn ORDER BY 1" );
1363
1397
1398
+ res = executeQuery (conn , buf -> data );
1399
+
1364
1400
for (i = 0 ; i < PQntuples (res ); i ++ )
1365
1401
{
1366
1402
char * dbname = PQgetvalue (res , i , 0 );
@@ -1557,9 +1593,9 @@ dumpUserConfig(PGconn *conn, const char *username)
1557
1593
if (server_version >= 90000 )
1558
1594
printfPQExpBuffer (buf , "SELECT setconfig[%d] FROM pg_db_role_setting WHERE "
1559
1595
"setdatabase = 0 AND setrole = "
1560
- "(SELECT oid FROM pg_authid WHERE rolname = " , count );
1596
+ "(SELECT oid FROM %s WHERE rolname = " , count , role_catalog );
1561
1597
else if (server_version >= 80100 )
1562
- printfPQExpBuffer (buf , "SELECT rolconfig[%d] FROM pg_authid WHERE rolname = " , count );
1598
+ printfPQExpBuffer (buf , "SELECT rolconfig[%d] FROM %s WHERE rolname = " , count , role_catalog );
1563
1599
else
1564
1600
printfPQExpBuffer (buf , "SELECT useconfig[%d] FROM pg_shadow WHERE usename = " , count );
1565
1601
appendStringLiteralConn (buf , username , conn );
@@ -1597,8 +1633,8 @@ dumpDbRoleConfig(PGconn *conn)
1597
1633
int i ;
1598
1634
1599
1635
printfPQExpBuffer (buf , "SELECT rolname, datname, unnest(setconfig) "
1600
- "FROM pg_db_role_setting, pg_authid , pg_database "
1601
- "WHERE setrole = pg_authid .oid AND setdatabase = pg_database.oid" );
1636
+ "FROM pg_db_role_setting, %s u , pg_database "
1637
+ "WHERE setrole = u .oid AND setdatabase = pg_database.oid" , role_catalog );
1602
1638
res = executeQuery (conn , buf -> data );
1603
1639
1604
1640
if (PQntuples (res ) > 0 )
0 commit comments