File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 173173DATABASE_EXPECTED_COUNT = os .environ .get ('DATABASE_EXPECTED_COUNT' , '' )
174174# A specific database?
175175DATABASE = os .environ .get ('DATABASE' , '' )
176+ RECOVERY_DATABASE_ROOT_USER = os .environ .get ('RECOVERY_DATABASE_ROOT_USER' , 'postgres' )
176177# Extract configuration from the environment.
177178# Postgres material...
178179PGHOST = os .environ .get ('PGHOST' , '' )
@@ -544,6 +545,18 @@ def error(error_no):
544545 write_termination_message ('Unpack failed' )
545546 sys .exit (0 )
546547
548+ # Filter - Remove actions on the root (postgres) user, which will otherwise
549+ # cause the recovery to fail with "current user cannot be dropped".
550+ # We only need to do this if the recovery is from a dumpall.
551+ if DATABASE :
552+ TARGET_FILE = "%s/%s.sql" % (RECOVERY_ROOT_DIR , DECOMPRESSED_RECOVERY_NAME )
553+ FILTER_PG_CMD = "egrep -v '^(CREATE|DROP) ROLE %s;' %s > filtered.sql ; mv filtered.sql %s" % (RECOVERY_DATABASE_ROOT_USER , TARGET_FILE , TARGET_FILE )
554+ print (" $" , FILTER_PG_CMD )
555+ COMPLETED_PROCESS = subprocess .run (FILTER_PG_CMD ,
556+ shell = True ,
557+ stderr = subprocess .PIPE ,
558+ check = False )
559+
547560print (" $" , RECOVERY_CMD )
548561COMPLETED_PROCESS = subprocess .run (RECOVERY_CMD ,
549562 shell = True ,
You can’t perform that action at this time.
0 commit comments