Skip to content

Commit fdaa40d

Browse files
committed
Refuse to return the "dead" pseudo column during recovery
GetOldestXmin() asserts !RecoveryInProgress(). Spotted by Andreas Seltenreich, thanks! Close #2.
1 parent efe0db2 commit fdaa40d

File tree

6 files changed

+23
-3
lines changed

6 files changed

+23
-3
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ System Columns
6767
System columns such as `xmax` and `ctid` can be retrieved by including them in
6868
the table alias attached to the `pg_dirtyread()` call. A special column `dead` of
6969
type boolean is available to report dead rows (as by `HeapTupleIsSurelyDead`).
70+
The `dead` column is not usable during recovery, i.e. most notably not on
71+
standby servers.
7072

7173
```sql
7274
SELECT * FROM pg_dirtyread('foo'::regclass)

debian/changelog

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
pg-dirtyread (1.2) unstable; urgency=medium
2+
3+
* Refuse to return the "dead" pseudo column during recovery,
4+
because GetOldestXmin() asserts !RecoveryInProgress().
5+
Spotted by Andreas Seltenreich, thanks!
6+
7+
-- Christoph Berg <myon@debian.org> Sun, 06 Aug 2017 16:57:41 +0200
8+
19
pg-dirtyread (1.1) unstable; urgency=medium
210

311
* Initial release.

debian/control

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Priority: optional
44
Maintainer: Debian PostgreSQL Maintainers <pkg-postgresql-public@lists.alioth.debian.org>
55
Uploaders: Christoph Berg <myon@debian.org>
66
Build-Depends: debhelper (>= 9), postgresql-server-dev-all (>= 153~)
7-
Standards-Version: 3.9.8
7+
Standards-Version: 4.0.1
88
Vcs-Browser: https://github.com/ChristophBerg/pg_dirtyread
99
Vcs-Git: https://github.com/ChristophBerg/pg_dirtyread.git
1010

debian/control.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Priority: optional
44
Maintainer: Debian PostgreSQL Maintainers <pkg-postgresql-public@lists.alioth.debian.org>
55
Uploaders: Christoph Berg <myon@debian.org>
66
Build-Depends: debhelper (>= 9), postgresql-server-dev-all (>= 153~)
7-
Standards-Version: 3.9.8
7+
Standards-Version: 4.0.1
88
Vcs-Browser: https://github.com/ChristophBerg/pg_dirtyread
99
Vcs-Git: https://github.com/ChristophBerg/pg_dirtyread.git
1010

dirtyread_tupconvert.c

+7
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#endif
2626
#include "access/tupconvert.h"
2727
#include "access/sysattr.h"
28+
#include "access/xlog.h" /* RecoveryInProgress */
2829
#include "catalog/pg_type.h" /* *OID */
2930
#include "utils/builtins.h"
3031
#include "utils/tqual.h" /* HeapTupleIsSurelyDead */
@@ -221,6 +222,12 @@ dirtyread_convert_tuples_by_name_map(TupleDesc indesc,
221222
attname,
222223
format_type_be(system_columns[j].atttypid),
223224
format_type_be(indesc->tdtypeid))));
225+
/* GetOldestXmin() is not available during recovery */
226+
if (system_columns[j].attnum == DeadFakeAttributeNumber &&
227+
RecoveryInProgress())
228+
ereport(ERROR,
229+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
230+
errmsg("Cannot use \"dead\" column during recovery")));
224231
attrMap[i] = system_columns[j].attnum;
225232
break;
226233
}

pg_dirtyread.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#if PG_VERSION_NUM >= 90300
4343
#include "access/htup_details.h"
4444
#endif
45+
#include "access/xlog.h" /* RecoveryInProgress */
4546
#include "miscadmin.h" /* superuser */
4647
#include "storage/procarray.h" /* GetOldestXmin */
4748

@@ -97,7 +98,9 @@ pg_dirtyread(PG_FUNCTION_ARGS)
9798
usr_ctx->map = dirtyread_convert_tuples_by_name(usr_ctx->reltupdesc,
9899
funcctx->tuple_desc, "Error converting tuple descriptors!");
99100
usr_ctx->scan = heap_beginscan(usr_ctx->rel, SnapshotAny, 0, NULL);
100-
usr_ctx->oldest_xmin = GetOldestXmin(
101+
/* only call GetOldestXmin while not in recovery */
102+
if (!RecoveryInProgress())
103+
usr_ctx->oldest_xmin = GetOldestXmin(
101104
#if PG_VERSION_NUM >= 90400
102105
usr_ctx->rel
103106
#else

0 commit comments

Comments
 (0)