Skip to content

Commit 13db3aa

Browse files
committed
Register a relcache callback to invalidate cached Oids when necessary.
1 parent aaf4da2 commit 13db3aa

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

expected/lolor.out

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,17 @@ REINDEX INDEX CONCURRENTLY lolor.pg_largeobject_pkey;
5454
REINDEX INDEX CONCURRENTLY lolor.pg_largeobject_metadata_pkey;
5555
BEGIN;
5656
SELECT lo_open(:loid, 262144) AS fd \gset
57-
ERROR: could not open relation with OID 16399
5857
SELECT convert_from(loread(:fd, 1024), 'UTF8');
59-
ERROR: current transaction is aborted, commands ignored until end of transaction block
58+
convert_from
59+
----------------------
60+
Example large object
61+
(1 row)
62+
6063
SELECT lo_close(:fd);
61-
ERROR: current transaction is aborted, commands ignored until end of transaction block
64+
lo_close
65+
----------
66+
0
67+
(1 row)
68+
6269
END;
6370
DROP EXTENSION lolor;

src/lolor.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "nodes/value.h"
2525
#include "nodes/print.h"
2626
#include "utils/builtins.h"
27+
#include "utils/inval.h"
2728
#include "utils/guc.h"
2829
#include "utils/rel.h"
2930
#include "utils/lsyscache.h"
@@ -131,6 +132,18 @@ lolor_subxact_callback(SubXactEvent event, SubTransactionId mySubid,
131132
}
132133
}
133134

135+
/*
136+
* For the sake of performance, make it simple
137+
*/
138+
static void
139+
relcache_invalidate_callback(Datum arg, Oid reloid)
140+
{
141+
LOLOR_LargeObjectRelationId = InvalidOid;
142+
LOLOR_LargeObjectLOidPNIndexId = InvalidOid;
143+
LOLOR_LargeObjectMetadataRelationId = InvalidOid;
144+
LOLOR_LargeObjectMetadataOidIndexId = InvalidOid;
145+
}
146+
134147
/*
135148
* Entry point for this module.
136149
*/
@@ -151,6 +164,12 @@ _PG_init(void)
151164
/* register transaction callbacks for cleanup. */
152165
RegisterXactCallback(lolor_xact_callback, NULL);
153166
RegisterSubXactCallback(lolor_subxact_callback, NULL);
167+
168+
/*
169+
* Something may change object ID accidentially (REINDEX is a good example).
170+
* So, it is necessary to invalidate cache of Oids.
171+
*/
172+
CacheRegisterRelcacheCallback(relcache_invalidate_callback, (Datum) 0);
154173
}
155174

156175
/*

0 commit comments

Comments
 (0)