@@ -1350,7 +1350,9 @@ CopyXLogRecordToWAL(int write_len, bool isLogSwitch, XLogRecData *rdata,
13501350 }
13511351
13521352 if (CurrPos != EndPos )
1353- elog (PANIC , "space reserved for WAL record does not match what was written" );
1353+ ereport (PANIC ,
1354+ errcode (ERRCODE_DATA_CORRUPTED ),
1355+ errmsg_internal ("space reserved for WAL record does not match what was written" ));
13541356}
13551357
13561358/*
@@ -4036,7 +4038,8 @@ ValidateXLOGDirectoryStructure(void)
40364038 if (stat (XLOGDIR , & stat_buf ) != 0 ||
40374039 !S_ISDIR (stat_buf .st_mode ))
40384040 ereport (FATAL ,
4039- (errmsg ("required WAL directory \"%s\" does not exist" ,
4041+ (errcode_for_file_access (),
4042+ errmsg ("required WAL directory \"%s\" does not exist" ,
40404043 XLOGDIR )));
40414044
40424045 /* Check for archive_status */
@@ -4046,7 +4049,8 @@ ValidateXLOGDirectoryStructure(void)
40464049 /* Check for weird cases where it exists but isn't a directory */
40474050 if (!S_ISDIR (stat_buf .st_mode ))
40484051 ereport (FATAL ,
4049- (errmsg ("required WAL directory \"%s\" does not exist" ,
4052+ (errcode_for_file_access (),
4053+ errmsg ("required WAL directory \"%s\" does not exist" ,
40504054 path )));
40514055 }
40524056 else
@@ -4055,7 +4059,8 @@ ValidateXLOGDirectoryStructure(void)
40554059 (errmsg ("creating missing WAL directory \"%s\"" , path )));
40564060 if (MakePGDirectory (path ) < 0 )
40574061 ereport (FATAL ,
4058- (errmsg ("could not create missing directory \"%s\": %m" ,
4062+ (errcode_for_file_access (),
4063+ errmsg ("could not create missing directory \"%s\": %m" ,
40594064 path )));
40604065 }
40614066
@@ -4292,7 +4297,8 @@ ReadControlFile(void)
42924297
42934298 if (ControlFile -> pg_control_version != PG_CONTROL_VERSION && ControlFile -> pg_control_version % 65536 == 0 && ControlFile -> pg_control_version / 65536 != 0 )
42944299 ereport (FATAL ,
4295- (errmsg ("database files are incompatible with server" ),
4300+ (errcode (ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE ),
4301+ errmsg ("database files are incompatible with server" ),
42964302 errdetail ("The database cluster was initialized with PG_CONTROL_VERSION %d (0x%08x),"
42974303 " but the server was compiled with PG_CONTROL_VERSION %d (0x%08x)." ,
42984304 ControlFile -> pg_control_version , ControlFile -> pg_control_version ,
@@ -4301,7 +4307,8 @@ ReadControlFile(void)
43014307
43024308 if (ControlFile -> pg_control_version != PG_CONTROL_VERSION )
43034309 ereport (FATAL ,
4304- (errmsg ("database files are incompatible with server" ),
4310+ (errcode (ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE ),
4311+ errmsg ("database files are incompatible with server" ),
43054312 errdetail ("The database cluster was initialized with PG_CONTROL_VERSION %d,"
43064313 " but the server was compiled with PG_CONTROL_VERSION %d." ,
43074314 ControlFile -> pg_control_version , PG_CONTROL_VERSION ),
@@ -4316,7 +4323,8 @@ ReadControlFile(void)
43164323
43174324 if (!EQ_CRC32C (crc , ControlFile -> crc ))
43184325 ereport (FATAL ,
4319- (errmsg ("incorrect checksum in control file" )));
4326+ (errcode (ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE ),
4327+ errmsg ("incorrect checksum in control file" )));
43204328
43214329 /*
43224330 * Do compatibility checking immediately. If the database isn't
@@ -4325,68 +4333,78 @@ ReadControlFile(void)
43254333 */
43264334 if (ControlFile -> catalog_version_no != CATALOG_VERSION_NO )
43274335 ereport (FATAL ,
4328- (errmsg ("database files are incompatible with server" ),
4336+ (errcode (ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE ),
4337+ errmsg ("database files are incompatible with server" ),
43294338 errdetail ("The database cluster was initialized with CATALOG_VERSION_NO %d,"
43304339 " but the server was compiled with CATALOG_VERSION_NO %d." ,
43314340 ControlFile -> catalog_version_no , CATALOG_VERSION_NO ),
43324341 errhint ("It looks like you need to initdb." )));
43334342 if (ControlFile -> maxAlign != MAXIMUM_ALIGNOF )
43344343 ereport (FATAL ,
4335- (errmsg ("database files are incompatible with server" ),
4344+ (errcode (ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE ),
4345+ errmsg ("database files are incompatible with server" ),
43364346 errdetail ("The database cluster was initialized with MAXALIGN %d,"
43374347 " but the server was compiled with MAXALIGN %d." ,
43384348 ControlFile -> maxAlign , MAXIMUM_ALIGNOF ),
43394349 errhint ("It looks like you need to initdb." )));
43404350 if (ControlFile -> floatFormat != FLOATFORMAT_VALUE )
43414351 ereport (FATAL ,
4342- (errmsg ("database files are incompatible with server" ),
4352+ (errcode (ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE ),
4353+ errmsg ("database files are incompatible with server" ),
43434354 errdetail ("The database cluster appears to use a different floating-point number format than the server executable." ),
43444355 errhint ("It looks like you need to initdb." )));
43454356 if (ControlFile -> blcksz != BLCKSZ )
43464357 ereport (FATAL ,
4347- (errmsg ("database files are incompatible with server" ),
4358+ (errcode (ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE ),
4359+ errmsg ("database files are incompatible with server" ),
43484360 errdetail ("The database cluster was initialized with BLCKSZ %d,"
43494361 " but the server was compiled with BLCKSZ %d." ,
43504362 ControlFile -> blcksz , BLCKSZ ),
43514363 errhint ("It looks like you need to recompile or initdb." )));
43524364 if (ControlFile -> relseg_size != RELSEG_SIZE )
43534365 ereport (FATAL ,
4354- (errmsg ("database files are incompatible with server" ),
4366+ (errcode (ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE ),
4367+ errmsg ("database files are incompatible with server" ),
43554368 errdetail ("The database cluster was initialized with RELSEG_SIZE %d,"
43564369 " but the server was compiled with RELSEG_SIZE %d." ,
43574370 ControlFile -> relseg_size , RELSEG_SIZE ),
43584371 errhint ("It looks like you need to recompile or initdb." )));
43594372 if (ControlFile -> xlog_blcksz != XLOG_BLCKSZ )
43604373 ereport (FATAL ,
4361- (errmsg ("database files are incompatible with server" ),
4374+ (errcode (ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE ),
4375+ errmsg ("database files are incompatible with server" ),
43624376 errdetail ("The database cluster was initialized with XLOG_BLCKSZ %d,"
43634377 " but the server was compiled with XLOG_BLCKSZ %d." ,
43644378 ControlFile -> xlog_blcksz , XLOG_BLCKSZ ),
43654379 errhint ("It looks like you need to recompile or initdb." )));
43664380 if (ControlFile -> nameDataLen != NAMEDATALEN )
43674381 ereport (FATAL ,
4368- (errmsg ("database files are incompatible with server" ),
4382+ (errcode (ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE ),
4383+ errmsg ("database files are incompatible with server" ),
43694384 errdetail ("The database cluster was initialized with NAMEDATALEN %d,"
43704385 " but the server was compiled with NAMEDATALEN %d." ,
43714386 ControlFile -> nameDataLen , NAMEDATALEN ),
43724387 errhint ("It looks like you need to recompile or initdb." )));
43734388 if (ControlFile -> indexMaxKeys != INDEX_MAX_KEYS )
43744389 ereport (FATAL ,
4375- (errmsg ("database files are incompatible with server" ),
4390+ (errcode (ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE ),
4391+ errmsg ("database files are incompatible with server" ),
43764392 errdetail ("The database cluster was initialized with INDEX_MAX_KEYS %d,"
43774393 " but the server was compiled with INDEX_MAX_KEYS %d." ,
43784394 ControlFile -> indexMaxKeys , INDEX_MAX_KEYS ),
43794395 errhint ("It looks like you need to recompile or initdb." )));
43804396 if (ControlFile -> toast_max_chunk_size != TOAST_MAX_CHUNK_SIZE )
43814397 ereport (FATAL ,
4382- (errmsg ("database files are incompatible with server" ),
4398+ (errcode (ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE ),
4399+ errmsg ("database files are incompatible with server" ),
43834400 errdetail ("The database cluster was initialized with TOAST_MAX_CHUNK_SIZE %d,"
43844401 " but the server was compiled with TOAST_MAX_CHUNK_SIZE %d." ,
43854402 ControlFile -> toast_max_chunk_size , (int ) TOAST_MAX_CHUNK_SIZE ),
43864403 errhint ("It looks like you need to recompile or initdb." )));
43874404 if (ControlFile -> loblksize != LOBLKSIZE )
43884405 ereport (FATAL ,
4389- (errmsg ("database files are incompatible with server" ),
4406+ (errcode (ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE ),
4407+ errmsg ("database files are incompatible with server" ),
43904408 errdetail ("The database cluster was initialized with LOBLKSIZE %d,"
43914409 " but the server was compiled with LOBLKSIZE %d." ,
43924410 ControlFile -> loblksize , (int ) LOBLKSIZE ),
@@ -4395,14 +4413,16 @@ ReadControlFile(void)
43954413#ifdef USE_FLOAT8_BYVAL
43964414 if (ControlFile -> float8ByVal != true)
43974415 ereport (FATAL ,
4398- (errmsg ("database files are incompatible with server" ),
4416+ (errcode (ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE ),
4417+ errmsg ("database files are incompatible with server" ),
43994418 errdetail ("The database cluster was initialized without USE_FLOAT8_BYVAL"
44004419 " but the server was compiled with USE_FLOAT8_BYVAL." ),
44014420 errhint ("It looks like you need to recompile or initdb." )));
44024421#else
44034422 if (ControlFile -> float8ByVal != false)
44044423 ereport (FATAL ,
4405- (errmsg ("database files are incompatible with server" ),
4424+ (errcode (ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE ),
4425+ errmsg ("database files are incompatible with server" ),
44064426 errdetail ("The database cluster was initialized with USE_FLOAT8_BYVAL"
44074427 " but the server was compiled without USE_FLOAT8_BYVAL." ),
44084428 errhint ("It looks like you need to recompile or initdb." )));
@@ -5271,7 +5291,8 @@ CheckRequiredParameterValues(void)
52715291 if (ArchiveRecoveryRequested && ControlFile -> wal_level == WAL_LEVEL_MINIMAL )
52725292 {
52735293 ereport (FATAL ,
5274- (errmsg ("WAL was generated with wal_level=minimal, cannot continue recovering" ),
5294+ (errcode (ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE ),
5295+ errmsg ("WAL was generated with wal_level=minimal, cannot continue recovering" ),
52755296 errdetail ("This happens if you temporarily set wal_level=minimal on the server." ),
52765297 errhint ("Use a backup taken after setting wal_level to higher than minimal." )));
52775298 }
@@ -5337,7 +5358,8 @@ StartupXLOG(void)
53375358 */
53385359 if (!XRecOffIsValid (ControlFile -> checkPoint ))
53395360 ereport (FATAL ,
5340- (errmsg ("control file contains invalid checkpoint location" )));
5361+ (errcode (ERRCODE_DATA_CORRUPTED ),
5362+ errmsg ("control file contains invalid checkpoint location" )));
53415363
53425364 switch (ControlFile -> state )
53435365 {
@@ -5388,7 +5410,8 @@ StartupXLOG(void)
53885410
53895411 default :
53905412 ereport (FATAL ,
5391- (errmsg ("control file contains invalid database cluster state" )));
5413+ (errcode (ERRCODE_DATA_CORRUPTED ),
5414+ errmsg ("control file contains invalid database cluster state" )));
53925415 }
53935416
53945417 /* This is just to allow attaching to startup process with a debugger */
@@ -5774,11 +5797,13 @@ StartupXLOG(void)
57745797 {
57755798 if (!XLogRecPtrIsInvalid (ControlFile -> backupStartPoint ) || ControlFile -> backupEndRequired )
57765799 ereport (FATAL ,
5777- (errmsg ("WAL ends before end of online backup" ),
5800+ (errcode (ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE ),
5801+ errmsg ("WAL ends before end of online backup" ),
57785802 errhint ("All WAL generated while online backup was taken must be available at recovery." )));
57795803 else
57805804 ereport (FATAL ,
5781- (errmsg ("WAL ends before consistent recovery point" )));
5805+ (errcode (ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE ),
5806+ errmsg ("WAL ends before consistent recovery point" )));
57825807 }
57835808 }
57845809
@@ -8565,7 +8590,9 @@ issue_xlog_fsync(int fd, XLogSegNo segno, TimeLineID tli)
85658590 Assert (false);
85668591 break ;
85678592 default :
8568- elog (PANIC , "unrecognized wal_sync_method: %d" , wal_sync_method );
8593+ ereport (PANIC ,
8594+ errcode (ERRCODE_INVALID_PARAMETER_VALUE ),
8595+ errmsg_internal ("unrecognized wal_sync_method: %d" , wal_sync_method ));
85698596 break ;
85708597 }
85718598
0 commit comments