Skip to content

Commit 7697c12

Browse files
author
hackorum
committed
Apply page_inspect_owner_can_query.diff
1 parent 4255812 commit 7697c12

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

‎contrib/pageinspect/rawpage.c‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "access/xlog.h"
2121
#include "catalog/namespace.h"
2222
#include "catalog/pg_type.h"
23+
#include "commands/tablecmds.h"
2324
#include "funcapi.h"
2425
#include "miscadmin.h"
2526
#include "pageinspect.h"
@@ -146,18 +147,21 @@ static bytea *
146147
get_raw_page_internal(text *relname, ForkNumber forknum, BlockNumber blkno)
147148
{
148149
bytea *raw_page;
150+
Oid relid;
149151
RangeVar *relrv;
150152
Relation rel;
151153
char *raw_page_data;
152154
Buffer buf;
153155

154-
if (!superuser())
155-
ereport(ERROR,
156-
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
157-
errmsg("must be superuser to use raw page functions")));
158-
159156
relrv = makeRangeVarFromNameList(textToQualifiedNameList(relname));
160-
rel = relation_openrv(relrv, AccessShareLock);
157+
158+
/* Open and lock sequence, and check for ownership along the way. */
159+
relid = RangeVarGetRelidExtended(relrv,
160+
AccessShareLock,
161+
0,
162+
RangeVarCallbackOwnsRelation,
163+
NULL);
164+
rel = relation_open(relid, NoLock);
161165

162166
if (!RELKIND_HAS_STORAGE(rel->rd_rel->relkind))
163167
ereport(ERROR,
@@ -188,7 +192,7 @@ get_raw_page_internal(text *relname, ForkNumber forknum, BlockNumber blkno)
188192

189193
UnlockReleaseBuffer(buf);
190194

191-
relation_close(rel, AccessShareLock);
195+
relation_close(rel, NoLock);
192196

193197
return raw_page;
194198
}

0 commit comments

Comments
 (0)