@@ -8957,6 +8957,11 @@ pg_start_backup(PG_FUNCTION_ARGS)
8957
8957
8958
8958
backupidstr = text_to_cstring (backupid );
8959
8959
8960
+ if (!superuser ()&& !has_rolreplication (GetUserId ()))
8961
+ ereport (ERROR ,
8962
+ (errcode (ERRCODE_INSUFFICIENT_PRIVILEGE ),
8963
+ errmsg ("must be superuser or replication role to run a backup" )));
8964
+
8960
8965
startpoint = do_pg_start_backup (backupidstr ,fast ,NULL );
8961
8966
8962
8967
snprintf (startxlogstr ,sizeof (startxlogstr ),"%X/%X" ,
@@ -8984,6 +8989,9 @@ pg_start_backup(PG_FUNCTION_ARGS)
8984
8989
*
8985
8990
* Every successfully started non-exclusive backup must be stopped by calling
8986
8991
* do_pg_stop_backup() or do_pg_abort_backup().
8992
+ *
8993
+ * It is the responsibility of the caller of this function to verify the
8994
+ * permissions of the calling user!
8987
8995
*/
8988
8996
XLogRecPtr
8989
8997
do_pg_start_backup (const char * backupidstr ,bool fast ,char * * labelfile )
@@ -9000,11 +9008,6 @@ do_pg_start_backup(const char *backupidstr, bool fast, char **labelfile)
9000
9008
FILE * fp ;
9001
9009
StringInfoData labelfbuf ;
9002
9010
9003
- if (!superuser ()&& !has_rolreplication (GetUserId ()))
9004
- ereport (ERROR ,
9005
- (errcode (ERRCODE_INSUFFICIENT_PRIVILEGE ),
9006
- errmsg ("must be superuser or replication role to run a backup" )));
9007
-
9008
9011
if (RecoveryInProgress ())
9009
9012
ereport (ERROR ,
9010
9013
(errcode (ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE ),
@@ -9241,6 +9244,11 @@ pg_stop_backup(PG_FUNCTION_ARGS)
9241
9244
XLogRecPtr stoppoint ;
9242
9245
char stopxlogstr [MAXFNAMELEN ];
9243
9246
9247
+ if (!superuser ()&& !has_rolreplication (GetUserId ()))
9248
+ ereport (ERROR ,
9249
+ (errcode (ERRCODE_INSUFFICIENT_PRIVILEGE ),
9250
+ errmsg ("must be superuser or replication role to run a backup" )));
9251
+
9244
9252
stoppoint = do_pg_stop_backup (NULL , true);
9245
9253
9246
9254
snprintf (stopxlogstr ,sizeof (stopxlogstr ),"%X/%X" ,
@@ -9254,6 +9262,9 @@ pg_stop_backup(PG_FUNCTION_ARGS)
9254
9262
9255
9263
* If labelfile is NULL, this stops an exclusive backup. Otherwise this stops
9256
9264
* the non-exclusive backup specified by 'labelfile'.
9265
+ *
9266
+ * It is the responsibility of the caller of this function to verify the
9267
+ * permissions of the calling user!
9257
9268
*/
9258
9269
XLogRecPtr
9259
9270
do_pg_stop_backup (char * labelfile ,bool waitforarchive )
@@ -9279,11 +9290,6 @@ do_pg_stop_backup(char *labelfile, bool waitforarchive)
9279
9290
bool reported_waiting = false;
9280
9291
char * remaining ;
9281
9292
9282
- if (!superuser ()&& !has_rolreplication (GetUserId ()))
9283
- ereport (ERROR ,
9284
- (errcode (ERRCODE_INSUFFICIENT_PRIVILEGE ),
9285
- (errmsg ("must be superuser or replication role to run a backup" ))));
9286
-
9287
9293
if (RecoveryInProgress ())
9288
9294
ereport (ERROR ,
9289
9295
(errcode (ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE ),