@@ -44,6 +44,7 @@ static void create_recovery_conf(time_t backup_id,
44
44
pgRestoreParams * params );
45
45
static void * restore_files (void * arg );
46
46
static void set_orphan_status (parray * backups , pgBackup * parent_backup );
47
+ static void create_pg12_recovery_config (pgBackup * backup , bool add_include );
47
48
48
49
/*
49
50
* Iterate over backup list to find all ancestors of the broken parent_backup
@@ -866,24 +867,43 @@ create_recovery_conf(time_t backup_id,
866
867
867
868
/* No need to generate recovery.conf at all. */
868
869
if (!(need_restore_conf || params -> restore_as_replica ))
870
+ {
871
+ #if PG_VERSION_NUM >= 120000
872
+ /*
873
+ * Restoring STREAM backup without PITR and not as replica,
874
+ * recovery.signal and standby.signal are not needed
875
+ */
876
+ create_pg12_recovery_config (backup , false);
877
+ #endif
869
878
return ;
879
+ }
870
880
871
881
elog (LOG , "----------------------------------------" );
882
+ #if PG_VERSION_NUM >= 120000
883
+ elog (LOG , "creating probackup_recovery.conf" );
884
+ create_pg12_recovery_config (backup , true);
885
+ snprintf (path , lengthof (path ), "%s/probackup_recovery.conf" , instance_config .pgdata );
886
+ #else
872
887
elog (LOG , "creating recovery.conf" );
873
-
874
888
snprintf (path , lengthof (path ), "%s/recovery.conf" , instance_config .pgdata );
889
+ #endif
890
+
875
891
fp = fio_fopen (path , "w" , FIO_DB_HOST );
876
892
if (fp == NULL )
877
- elog (ERROR , "cannot open recovery.conf \"%s\": %s" , path ,
893
+ elog (ERROR , "cannot open file \"%s\": %s" , path ,
878
894
strerror (errno ));
879
895
896
+ #if PG_VERSION_NUM >= 120000
897
+ fio_fprintf (fp , "# probackup_recovery.conf generated by pg_probackup %s\n" ,
898
+ PROGRAM_VERSION );
899
+ #else
880
900
fio_fprintf (fp , "# recovery.conf generated by pg_probackup %s\n" ,
881
901
PROGRAM_VERSION );
902
+ #endif
882
903
883
904
/* construct restore_command */
884
905
if (need_restore_conf )
885
906
{
886
-
887
907
char restore_command_guc [16384 ];
888
908
889
909
/* If restore_command is provided, use it */
@@ -957,15 +977,111 @@ create_recovery_conf(time_t backup_id,
957
977
958
978
if (params -> restore_as_replica )
959
979
{
980
+ /* standby_mode was removed in PG12 */
981
+ #if PG_VERSION_NUM < 120000
960
982
fio_fprintf (fp , "standby_mode = 'on'\n" );
983
+ #endif
961
984
962
985
if (backup -> primary_conninfo )
963
986
fio_fprintf (fp , "primary_conninfo = '%s'\n" , backup -> primary_conninfo );
964
987
}
965
988
966
989
if (fio_fflush (fp ) != 0 ||
967
990
fio_fclose (fp ))
968
- elog (ERROR , "cannot write recovery.conf \"%s\": %s" , path ,
991
+ elog (ERROR , "cannot write file \"%s\": %s" , path ,
992
+ strerror (errno ));
993
+
994
+ #if PG_VERSION_NUM >= 120000
995
+ if (need_restore_conf )
996
+ {
997
+ elog (LOG , "creating recovery.signal file" );
998
+ snprintf (path , lengthof (path ), "%s/recovery.signal" , instance_config .pgdata );
999
+
1000
+ fp = fio_fopen (path , "w" , FIO_DB_HOST );
1001
+ if (fp == NULL )
1002
+ elog (ERROR , "cannot open file \"%s\": %s" , path ,
1003
+ strerror (errno ));
1004
+
1005
+ if (fio_fflush (fp ) != 0 ||
1006
+ fio_fclose (fp ))
1007
+ elog (ERROR , "cannot write file \"%s\": %s" , path ,
1008
+ strerror (errno ));
1009
+ }
1010
+
1011
+ if (params -> restore_as_replica )
1012
+ {
1013
+ elog (LOG , "creating standby.signal file" );
1014
+ snprintf (path , lengthof (path ), "%s/standby.signal" , instance_config .pgdata );
1015
+
1016
+ fp = fio_fopen (path , "w" , FIO_DB_HOST );
1017
+ if (fp == NULL )
1018
+ elog (ERROR , "cannot open file \"%s\": %s" , path ,
1019
+ strerror (errno ));
1020
+
1021
+ if (fio_fflush (fp ) != 0 ||
1022
+ fio_fclose (fp ))
1023
+ elog (ERROR , "cannot write file \"%s\": %s" , path ,
1024
+ strerror (errno ));
1025
+ }
1026
+ #endif
1027
+ }
1028
+
1029
+ /*
1030
+ * Create empty probackup_recovery.conf in PGDATA and
1031
+ * add include directive to postgresql.auto.conf
1032
+
1033
+ * When restoring PG12 we always(!) must do this, even
1034
+ * when restoring STREAM backup without PITR options
1035
+ * because restored instance may have been backed up
1036
+ * and restored again and user didn`t cleaned up postgresql.auto.conf.
1037
+
1038
+ * So for recovery to work regardless of all this factors
1039
+ * we must always create empty probackup_recovery.conf file.
1040
+ */
1041
+ static void
1042
+ create_pg12_recovery_config (pgBackup * backup , bool add_include )
1043
+ {
1044
+ char probackup_recovery_path [MAXPGPATH ];
1045
+ char postgres_auto_path [MAXPGPATH ];
1046
+ FILE * fp ;
1047
+
1048
+ if (add_include )
1049
+ {
1050
+ time_t current_time ;
1051
+ char current_time_str [100 ];
1052
+
1053
+ current_time = time (NULL );
1054
+ time2iso (current_time_str , lengthof (current_time_str ), current_time );
1055
+
1056
+ snprintf (postgres_auto_path , lengthof (postgres_auto_path ),
1057
+ "%s/postgresql.auto.conf" , instance_config .pgdata );
1058
+
1059
+ fp = fio_fopen (postgres_auto_path , "a" , FIO_DB_HOST );
1060
+ if (fp == NULL )
1061
+ elog (ERROR , "cannot write to file \"%s\": %s" , postgres_auto_path ,
1062
+ strerror (errno ));
1063
+
1064
+ fio_fprintf (fp , "\n# created by pg_probackup restore of backup %s at '%s'\n" ,
1065
+ base36enc (backup -> start_time ), current_time_str );
1066
+ fio_fprintf (fp , "include '%s'\n" , "probackup_recovery.conf" );
1067
+
1068
+ if (fio_fflush (fp ) != 0 ||
1069
+ fio_fclose (fp ))
1070
+ elog (ERROR , "cannot write to file \"%s\": %s" , postgres_auto_path ,
1071
+ strerror (errno ));
1072
+ }
1073
+
1074
+ /* Create empty probackup_recovery.conf */
1075
+ snprintf (probackup_recovery_path , lengthof (probackup_recovery_path ),
1076
+ "%s/probackup_recovery.conf" , instance_config .pgdata );
1077
+ fp = fio_fopen (probackup_recovery_path , "w" , FIO_DB_HOST );
1078
+ if (fp == NULL )
1079
+ elog (ERROR , "cannot open file \"%s\": %s" , probackup_recovery_path ,
1080
+ strerror (errno ));
1081
+
1082
+ if (fio_fflush (fp ) != 0 ||
1083
+ fio_fclose (fp ))
1084
+ elog (ERROR , "cannot write to file \"%s\": %s" , probackup_recovery_path ,
969
1085
strerror (errno ));
970
1086
}
971
1087
0 commit comments