@@ -1350,7 +1350,9 @@ CopyXLogRecordToWAL(int write_len, bool isLogSwitch, XLogRecData *rdata,
1350
1350
}
1351
1351
1352
1352
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" ));
1354
1356
}
1355
1357
1356
1358
/*
@@ -4036,7 +4038,8 @@ ValidateXLOGDirectoryStructure(void)
4036
4038
if (stat (XLOGDIR , & stat_buf ) != 0 ||
4037
4039
!S_ISDIR (stat_buf .st_mode ))
4038
4040
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" ,
4040
4043
XLOGDIR )));
4041
4044
4042
4045
/* Check for archive_status */
@@ -4046,7 +4049,8 @@ ValidateXLOGDirectoryStructure(void)
4046
4049
/* Check for weird cases where it exists but isn't a directory */
4047
4050
if (!S_ISDIR (stat_buf .st_mode ))
4048
4051
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" ,
4050
4054
path )));
4051
4055
}
4052
4056
else
@@ -4055,7 +4059,8 @@ ValidateXLOGDirectoryStructure(void)
4055
4059
(errmsg ("creating missing WAL directory \"%s\"" , path )));
4056
4060
if (MakePGDirectory (path ) < 0 )
4057
4061
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" ,
4059
4064
path )));
4060
4065
}
4061
4066
@@ -4292,7 +4297,8 @@ ReadControlFile(void)
4292
4297
4293
4298
if (ControlFile -> pg_control_version != PG_CONTROL_VERSION && ControlFile -> pg_control_version % 65536 == 0 && ControlFile -> pg_control_version / 65536 != 0 )
4294
4299
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" ),
4296
4302
errdetail ("The database cluster was initialized with PG_CONTROL_VERSION %d (0x%08x),"
4297
4303
" but the server was compiled with PG_CONTROL_VERSION %d (0x%08x)." ,
4298
4304
ControlFile -> pg_control_version , ControlFile -> pg_control_version ,
@@ -4301,7 +4307,8 @@ ReadControlFile(void)
4301
4307
4302
4308
if (ControlFile -> pg_control_version != PG_CONTROL_VERSION )
4303
4309
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" ),
4305
4312
errdetail ("The database cluster was initialized with PG_CONTROL_VERSION %d,"
4306
4313
" but the server was compiled with PG_CONTROL_VERSION %d." ,
4307
4314
ControlFile -> pg_control_version , PG_CONTROL_VERSION ),
@@ -4316,7 +4323,8 @@ ReadControlFile(void)
4316
4323
4317
4324
if (!EQ_CRC32C (crc , ControlFile -> crc ))
4318
4325
ereport (FATAL ,
4319
- (errmsg ("incorrect checksum in control file" )));
4326
+ (errcode (ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE ),
4327
+ errmsg ("incorrect checksum in control file" )));
4320
4328
4321
4329
/*
4322
4330
* Do compatibility checking immediately. If the database isn't
@@ -4325,68 +4333,78 @@ ReadControlFile(void)
4325
4333
*/
4326
4334
if (ControlFile -> catalog_version_no != CATALOG_VERSION_NO )
4327
4335
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" ),
4329
4338
errdetail ("The database cluster was initialized with CATALOG_VERSION_NO %d,"
4330
4339
" but the server was compiled with CATALOG_VERSION_NO %d." ,
4331
4340
ControlFile -> catalog_version_no , CATALOG_VERSION_NO ),
4332
4341
errhint ("It looks like you need to initdb." )));
4333
4342
if (ControlFile -> maxAlign != MAXIMUM_ALIGNOF )
4334
4343
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" ),
4336
4346
errdetail ("The database cluster was initialized with MAXALIGN %d,"
4337
4347
" but the server was compiled with MAXALIGN %d." ,
4338
4348
ControlFile -> maxAlign , MAXIMUM_ALIGNOF ),
4339
4349
errhint ("It looks like you need to initdb." )));
4340
4350
if (ControlFile -> floatFormat != FLOATFORMAT_VALUE )
4341
4351
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" ),
4343
4354
errdetail ("The database cluster appears to use a different floating-point number format than the server executable." ),
4344
4355
errhint ("It looks like you need to initdb." )));
4345
4356
if (ControlFile -> blcksz != BLCKSZ )
4346
4357
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" ),
4348
4360
errdetail ("The database cluster was initialized with BLCKSZ %d,"
4349
4361
" but the server was compiled with BLCKSZ %d." ,
4350
4362
ControlFile -> blcksz , BLCKSZ ),
4351
4363
errhint ("It looks like you need to recompile or initdb." )));
4352
4364
if (ControlFile -> relseg_size != RELSEG_SIZE )
4353
4365
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" ),
4355
4368
errdetail ("The database cluster was initialized with RELSEG_SIZE %d,"
4356
4369
" but the server was compiled with RELSEG_SIZE %d." ,
4357
4370
ControlFile -> relseg_size , RELSEG_SIZE ),
4358
4371
errhint ("It looks like you need to recompile or initdb." )));
4359
4372
if (ControlFile -> xlog_blcksz != XLOG_BLCKSZ )
4360
4373
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" ),
4362
4376
errdetail ("The database cluster was initialized with XLOG_BLCKSZ %d,"
4363
4377
" but the server was compiled with XLOG_BLCKSZ %d." ,
4364
4378
ControlFile -> xlog_blcksz , XLOG_BLCKSZ ),
4365
4379
errhint ("It looks like you need to recompile or initdb." )));
4366
4380
if (ControlFile -> nameDataLen != NAMEDATALEN )
4367
4381
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" ),
4369
4384
errdetail ("The database cluster was initialized with NAMEDATALEN %d,"
4370
4385
" but the server was compiled with NAMEDATALEN %d." ,
4371
4386
ControlFile -> nameDataLen , NAMEDATALEN ),
4372
4387
errhint ("It looks like you need to recompile or initdb." )));
4373
4388
if (ControlFile -> indexMaxKeys != INDEX_MAX_KEYS )
4374
4389
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" ),
4376
4392
errdetail ("The database cluster was initialized with INDEX_MAX_KEYS %d,"
4377
4393
" but the server was compiled with INDEX_MAX_KEYS %d." ,
4378
4394
ControlFile -> indexMaxKeys , INDEX_MAX_KEYS ),
4379
4395
errhint ("It looks like you need to recompile or initdb." )));
4380
4396
if (ControlFile -> toast_max_chunk_size != TOAST_MAX_CHUNK_SIZE )
4381
4397
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" ),
4383
4400
errdetail ("The database cluster was initialized with TOAST_MAX_CHUNK_SIZE %d,"
4384
4401
" but the server was compiled with TOAST_MAX_CHUNK_SIZE %d." ,
4385
4402
ControlFile -> toast_max_chunk_size , (int ) TOAST_MAX_CHUNK_SIZE ),
4386
4403
errhint ("It looks like you need to recompile or initdb." )));
4387
4404
if (ControlFile -> loblksize != LOBLKSIZE )
4388
4405
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" ),
4390
4408
errdetail ("The database cluster was initialized with LOBLKSIZE %d,"
4391
4409
" but the server was compiled with LOBLKSIZE %d." ,
4392
4410
ControlFile -> loblksize , (int ) LOBLKSIZE ),
@@ -4395,14 +4413,16 @@ ReadControlFile(void)
4395
4413
#ifdef USE_FLOAT8_BYVAL
4396
4414
if (ControlFile -> float8ByVal != true)
4397
4415
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" ),
4399
4418
errdetail ("The database cluster was initialized without USE_FLOAT8_BYVAL"
4400
4419
" but the server was compiled with USE_FLOAT8_BYVAL." ),
4401
4420
errhint ("It looks like you need to recompile or initdb." )));
4402
4421
#else
4403
4422
if (ControlFile -> float8ByVal != false)
4404
4423
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" ),
4406
4426
errdetail ("The database cluster was initialized with USE_FLOAT8_BYVAL"
4407
4427
" but the server was compiled without USE_FLOAT8_BYVAL." ),
4408
4428
errhint ("It looks like you need to recompile or initdb." )));
@@ -5271,7 +5291,8 @@ CheckRequiredParameterValues(void)
5271
5291
if (ArchiveRecoveryRequested && ControlFile -> wal_level == WAL_LEVEL_MINIMAL )
5272
5292
{
5273
5293
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" ),
5275
5296
errdetail ("This happens if you temporarily set wal_level=minimal on the server." ),
5276
5297
errhint ("Use a backup taken after setting wal_level to higher than minimal." )));
5277
5298
}
@@ -5337,7 +5358,8 @@ StartupXLOG(void)
5337
5358
*/
5338
5359
if (!XRecOffIsValid (ControlFile -> checkPoint ))
5339
5360
ereport (FATAL ,
5340
- (errmsg ("control file contains invalid checkpoint location" )));
5361
+ (errcode (ERRCODE_DATA_CORRUPTED ),
5362
+ errmsg ("control file contains invalid checkpoint location" )));
5341
5363
5342
5364
switch (ControlFile -> state )
5343
5365
{
@@ -5388,7 +5410,8 @@ StartupXLOG(void)
5388
5410
5389
5411
default :
5390
5412
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" )));
5392
5415
}
5393
5416
5394
5417
/* This is just to allow attaching to startup process with a debugger */
@@ -5774,11 +5797,13 @@ StartupXLOG(void)
5774
5797
{
5775
5798
if (!XLogRecPtrIsInvalid (ControlFile -> backupStartPoint ) || ControlFile -> backupEndRequired )
5776
5799
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" ),
5778
5802
errhint ("All WAL generated while online backup was taken must be available at recovery." )));
5779
5803
else
5780
5804
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" )));
5782
5807
}
5783
5808
}
5784
5809
@@ -8565,7 +8590,9 @@ issue_xlog_fsync(int fd, XLogSegNo segno, TimeLineID tli)
8565
8590
Assert (false);
8566
8591
break ;
8567
8592
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 ));
8569
8596
break ;
8570
8597
}
8571
8598
0 commit comments