@@ -72,7 +72,7 @@ typedef struct _parallelReadyList
72
72
static ArchiveHandle * _allocAH (const char * FileSpec , const ArchiveFormat fmt ,
73
73
const int compression , bool dosync , ArchiveMode mode ,
74
74
SetupWorkerPtrType setupWorkerPtr );
75
- static void _getObjectDescription (PQExpBuffer buf , TocEntry * te );
75
+ static void _getObjectDescription (PQExpBuffer buf , const TocEntry * te );
76
76
static void _printTocEntry (ArchiveHandle * AH , TocEntry * te , bool isData );
77
77
static char * sanitize_line (const char * str , bool want_hyphen );
78
78
static void _doSetFixedOutputState (ArchiveHandle * AH );
@@ -3398,27 +3398,27 @@ _selectTableAccessMethod(ArchiveHandle *AH, const char *tableam)
3398
3398
* Extract an object description for a TOC entry, and append it to buf.
3399
3399
*
3400
3400
* This is used for ALTER ... OWNER TO.
3401
+ *
3402
+ * If the object type has no owner, do nothing.
3401
3403
*/
3402
3404
static void
3403
- _getObjectDescription (PQExpBuffer buf , TocEntry * te )
3405
+ _getObjectDescription (PQExpBuffer buf , const TocEntry * te )
3404
3406
{
3405
3407
const char * type = te -> desc ;
3406
3408
3407
- /* Use ALTER TABLE for views and sequences */
3408
- if (strcmp (type , "VIEW" ) == 0 || strcmp (type , "SEQUENCE" ) == 0 ||
3409
- strcmp (type , "MATERIALIZED VIEW" ) == 0 )
3410
- type = "TABLE" ;
3411
-
3412
3409
/* objects that don't require special decoration */
3413
3410
if (strcmp (type , "COLLATION" ) == 0 ||
3414
3411
strcmp (type , "CONVERSION" ) == 0 ||
3415
3412
strcmp (type , "DOMAIN" ) == 0 ||
3416
- strcmp (type , "TABLE" ) == 0 ||
3417
- strcmp (type , "TYPE" ) == 0 ||
3418
3413
strcmp (type , "FOREIGN TABLE" ) == 0 ||
3414
+ strcmp (type , "MATERIALIZED VIEW" ) == 0 ||
3415
+ strcmp (type , "SEQUENCE" ) == 0 ||
3416
+ strcmp (type , "STATISTICS" ) == 0 ||
3417
+ strcmp (type , "TABLE" ) == 0 ||
3419
3418
strcmp (type , "TEXT SEARCH DICTIONARY" ) == 0 ||
3420
3419
strcmp (type , "TEXT SEARCH CONFIGURATION" ) == 0 ||
3421
- strcmp (type , "STATISTICS" ) == 0 ||
3420
+ strcmp (type , "TYPE" ) == 0 ||
3421
+ strcmp (type , "VIEW" ) == 0 ||
3422
3422
/* non-schema-specified objects */
3423
3423
strcmp (type , "DATABASE" ) == 0 ||
3424
3424
strcmp (type , "PROCEDURAL LANGUAGE" ) == 0 ||
@@ -3427,33 +3427,28 @@ _getObjectDescription(PQExpBuffer buf, TocEntry *te)
3427
3427
strcmp (type , "FOREIGN DATA WRAPPER" ) == 0 ||
3428
3428
strcmp (type , "SERVER" ) == 0 ||
3429
3429
strcmp (type , "PUBLICATION" ) == 0 ||
3430
- strcmp (type , "SUBSCRIPTION" ) == 0 ||
3431
- strcmp (type , "USER MAPPING" ) == 0 )
3430
+ strcmp (type , "SUBSCRIPTION" ) == 0 )
3432
3431
{
3433
3432
appendPQExpBuffer (buf , "%s " , type );
3434
3433
if (te -> namespace && * te -> namespace )
3435
3434
appendPQExpBuffer (buf , "%s." , fmtId (te -> namespace ));
3436
3435
appendPQExpBufferStr (buf , fmtId (te -> tag ));
3437
- return ;
3438
3436
}
3439
-
3440
3437
/* BLOBs just have a name, but it's numeric so must not use fmtId */
3441
- if (strcmp (type , "BLOB" ) == 0 )
3438
+ else if (strcmp (type , "BLOB" ) == 0 )
3442
3439
{
3443
3440
appendPQExpBuffer (buf , "LARGE OBJECT %s" , te -> tag );
3444
- return ;
3445
3441
}
3446
-
3447
3442
/*
3448
3443
* These object types require additional decoration. Fortunately, the
3449
3444
* information needed is exactly what's in the DROP command.
3450
3445
*/
3451
- if (strcmp (type , "AGGREGATE" ) == 0 ||
3452
- strcmp (type , "FUNCTION" ) == 0 ||
3453
- strcmp (type , "OPERATOR" ) == 0 ||
3454
- strcmp (type , "OPERATOR CLASS" ) == 0 ||
3455
- strcmp (type , "OPERATOR FAMILY" ) == 0 ||
3456
- strcmp (type , "PROCEDURE" ) == 0 )
3446
+ else if (strcmp (type , "AGGREGATE" ) == 0 ||
3447
+ strcmp (type , "FUNCTION" ) == 0 ||
3448
+ strcmp (type , "OPERATOR" ) == 0 ||
3449
+ strcmp (type , "OPERATOR CLASS" ) == 0 ||
3450
+ strcmp (type , "OPERATOR FAMILY" ) == 0 ||
3451
+ strcmp (type , "PROCEDURE" ) == 0 )
3457
3452
{
3458
3453
/* Chop "DROP " off the front and make a modifiable copy */
3459
3454
char * first = pg_strdup (te -> dropStmt + 5 );
@@ -3472,9 +3467,24 @@ _getObjectDescription(PQExpBuffer buf, TocEntry *te)
3472
3467
free (first );
3473
3468
return ;
3474
3469
}
3475
-
3476
- pg_log_warning ("don't know how to set owner for object type \"%s\"" ,
3477
- type );
3470
+ /* these object types don't have separate owners */
3471
+ else if (strcmp (type , "CAST" ) == 0 ||
3472
+ strcmp (type , "CHECK CONSTRAINT" ) == 0 ||
3473
+ strcmp (type , "CONSTRAINT" ) == 0 ||
3474
+ strcmp (type , "DATABASE PROPERTIES" ) == 0 ||
3475
+ strcmp (type , "DEFAULT" ) == 0 ||
3476
+ strcmp (type , "FK CONSTRAINT" ) == 0 ||
3477
+ strcmp (type , "INDEX" ) == 0 ||
3478
+ strcmp (type , "RULE" ) == 0 ||
3479
+ strcmp (type , "TRIGGER" ) == 0 ||
3480
+ strcmp (type , "ROW SECURITY" ) == 0 ||
3481
+ strcmp (type , "POLICY" ) == 0 ||
3482
+ strcmp (type , "USER MAPPING" ) == 0 )
3483
+ {
3484
+ /* do nothing */
3485
+ }
3486
+ else
3487
+ pg_fatal ("don't know how to set owner for object type \"%s\"" , type );
3478
3488
}
3479
3489
3480
3490
/*
@@ -3575,8 +3585,7 @@ _printTocEntry(ArchiveHandle *AH, TocEntry *te, bool isData)
3575
3585
* instead issue an ALTER OWNER command. Schema "public" is special; when
3576
3586
* a dump emits a comment in lieu of creating it, we use ALTER OWNER even
3577
3587
* when using SET SESSION for all other objects. We assume that anything
3578
- * without a DROP command is not a separately ownable object. All the
3579
- * categories with DROP commands must appear in one list or the other.
3588
+ * without a DROP command is not a separately ownable object.
3580
3589
*/
3581
3590
if (!ropt -> noOwner &&
3582
3591
(!ropt -> use_setsessauth ||
@@ -3585,62 +3594,17 @@ _printTocEntry(ArchiveHandle *AH, TocEntry *te, bool isData)
3585
3594
te -> owner && strlen (te -> owner ) > 0 &&
3586
3595
te -> dropStmt && strlen (te -> dropStmt ) > 0 )
3587
3596
{
3588
- if (strcmp (te -> desc , "AGGREGATE" ) == 0 ||
3589
- strcmp (te -> desc , "BLOB" ) == 0 ||
3590
- strcmp (te -> desc , "COLLATION" ) == 0 ||
3591
- strcmp (te -> desc , "CONVERSION" ) == 0 ||
3592
- strcmp (te -> desc , "DATABASE" ) == 0 ||
3593
- strcmp (te -> desc , "DOMAIN" ) == 0 ||
3594
- strcmp (te -> desc , "FUNCTION" ) == 0 ||
3595
- strcmp (te -> desc , "OPERATOR" ) == 0 ||
3596
- strcmp (te -> desc , "OPERATOR CLASS" ) == 0 ||
3597
- strcmp (te -> desc , "OPERATOR FAMILY" ) == 0 ||
3598
- strcmp (te -> desc , "PROCEDURE" ) == 0 ||
3599
- strcmp (te -> desc , "PROCEDURAL LANGUAGE" ) == 0 ||
3600
- strcmp (te -> desc , "SCHEMA" ) == 0 ||
3601
- strcmp (te -> desc , "EVENT TRIGGER" ) == 0 ||
3602
- strcmp (te -> desc , "TABLE" ) == 0 ||
3603
- strcmp (te -> desc , "TYPE" ) == 0 ||
3604
- strcmp (te -> desc , "VIEW" ) == 0 ||
3605
- strcmp (te -> desc , "MATERIALIZED VIEW" ) == 0 ||
3606
- strcmp (te -> desc , "SEQUENCE" ) == 0 ||
3607
- strcmp (te -> desc , "FOREIGN TABLE" ) == 0 ||
3608
- strcmp (te -> desc , "TEXT SEARCH DICTIONARY" ) == 0 ||
3609
- strcmp (te -> desc , "TEXT SEARCH CONFIGURATION" ) == 0 ||
3610
- strcmp (te -> desc , "FOREIGN DATA WRAPPER" ) == 0 ||
3611
- strcmp (te -> desc , "SERVER" ) == 0 ||
3612
- strcmp (te -> desc , "STATISTICS" ) == 0 ||
3613
- strcmp (te -> desc , "PUBLICATION" ) == 0 ||
3614
- strcmp (te -> desc , "SUBSCRIPTION" ) == 0 )
3615
- {
3616
- PQExpBuffer temp = createPQExpBuffer ();
3597
+ PQExpBufferData temp ;
3617
3598
3618
- appendPQExpBufferStr (temp , "ALTER " );
3619
- _getObjectDescription (temp , te );
3620
- appendPQExpBuffer (temp , " OWNER TO %s;" , fmtId (te -> owner ));
3621
- ahprintf (AH , "%s\n\n" , temp -> data );
3622
- destroyPQExpBuffer (temp );
3623
- }
3624
- else if (strcmp (te -> desc , "CAST" ) == 0 ||
3625
- strcmp (te -> desc , "CHECK CONSTRAINT" ) == 0 ||
3626
- strcmp (te -> desc , "CONSTRAINT" ) == 0 ||
3627
- strcmp (te -> desc , "DATABASE PROPERTIES" ) == 0 ||
3628
- strcmp (te -> desc , "DEFAULT" ) == 0 ||
3629
- strcmp (te -> desc , "FK CONSTRAINT" ) == 0 ||
3630
- strcmp (te -> desc , "INDEX" ) == 0 ||
3631
- strcmp (te -> desc , "RULE" ) == 0 ||
3632
- strcmp (te -> desc , "TRIGGER" ) == 0 ||
3633
- strcmp (te -> desc , "ROW SECURITY" ) == 0 ||
3634
- strcmp (te -> desc , "POLICY" ) == 0 ||
3635
- strcmp (te -> desc , "USER MAPPING" ) == 0 )
3636
- {
3637
- /* these object types don't have separate owners */
3638
- }
3639
- else
3640
- {
3641
- pg_log_warning ("don't know how to set owner for object type \"%s\"" ,
3642
- te -> desc );
3643
- }
3599
+ initPQExpBuffer (& temp );
3600
+ _getObjectDescription (& temp , te );
3601
+ /*
3602
+ * If _getObjectDescription() didn't fill the buffer, then there is no
3603
+ * owner.
3604
+ */
3605
+ if (temp .data [0 ])
3606
+ ahprintf (AH , "ALTER %s OWNER TO %s;\n\n" , temp .data , fmtId (te -> owner ));
3607
+ termPQExpBuffer (& temp );
3644
3608
}
3645
3609
3646
3610
/*
0 commit comments