|
16 | 16 | #include "access/clog.h"
|
17 | 17 | #include "access/subtrans.h"
|
18 | 18 | #include "access/transam.h"
|
| 19 | +#include "access/xact.h" |
19 | 20 | #include "commands/dbcommands.h"
|
20 | 21 | #include "miscadmin.h"
|
21 | 22 | #include "postmaster/autovacuum.h"
|
@@ -346,13 +347,22 @@ SetTransactionIdLimit(TransactionId oldest_datfrozenxid, Oid oldest_datoid)
|
346 | 347 | /* Give an immediate warning if past the wrap warn point */
|
347 | 348 | if (TransactionIdFollowsOrEquals(curXid, xidWarnLimit) && !InRecovery)
|
348 | 349 | {
|
349 |
| - char *oldest_datname = get_database_name(oldest_datoid); |
| 350 | + char *oldest_datname; |
350 | 351 |
|
351 | 352 | /*
|
352 |
| - * Note: it's possible that get_database_name fails and returns NULL, |
353 |
| - * for example because the database just got dropped. We'll still |
354 |
| - * warn, even though the warning might now be unnecessary. |
| 353 | + * We can be called when not inside a transaction, for example |
| 354 | + * during StartupXLOG(). In such a case we cannot do database |
| 355 | + * access, so we must just report the oldest DB's OID. |
| 356 | + * |
| 357 | + * Note: it's also possible that get_database_name fails and returns |
| 358 | + * NULL, for example because the database just got dropped. We'll |
| 359 | + * still warn, even though the warning might now be unnecessary. |
355 | 360 | */
|
| 361 | + if (IsTransactionState()) |
| 362 | + oldest_datname = get_database_name(oldest_datoid); |
| 363 | + else |
| 364 | + oldest_datname = NULL; |
| 365 | + |
356 | 366 | if (oldest_datname)
|
357 | 367 | ereport(WARNING,
|
358 | 368 | (errmsg("database \"%s\" must be vacuumed within %u transactions",
|
|
0 commit comments