2929#include <unistd.h>
3030#include <sys/stat.h>
3131
32+ #if PG_VERSION_NUM < 120000
33+ #include "access/htup_details.h"
34+ #endif
3235#include "catalog/pg_tablespace.h"
3336#include "catalog/pg_type.h"
3437#include "funcapi.h"
3538#include "miscadmin.h"
3639#include "nodes/pg_list.h"
3740#include "storage/copydir.h"
3841#include "storage/lmgr.h"
42+ #if PG_VERSION_NUM >=120000
3943#include "storage/md.h"
44+ #endif
4045#include "storage/reinit.h"
4146#include "utils/builtins.h"
4247#include "utils/guc.h"
@@ -55,7 +60,9 @@ intptrack_map_size_tmp;
5560static copydir_hook_type prev_copydir_hook = NULL ;
5661static mdwrite_hook_type prev_mdwrite_hook = NULL ;
5762static mdextend_hook_type prev_mdextend_hook = NULL ;
63+ #if PG_VERSION_NUM >=120000
5864static ProcessSyncRequests_hook_type prev_ProcessSyncRequests_hook = NULL ;
65+ #endif
5966
6067void _PG_init (void );
6168void _PG_fini (void );
@@ -65,8 +72,9 @@ static void ptrack_mdwrite_hook(RelFileNodeBackend smgr_rnode,
6572ForkNumber forkno ,BlockNumber blkno );
6673static void ptrack_mdextend_hook (RelFileNodeBackend smgr_rnode ,
6774ForkNumber forkno ,BlockNumber blkno );
75+ #if PG_VERSION_NUM >=120000
6876static void ptrack_ProcessSyncRequests_hook (void );
69-
77+ #endif
7078static void ptrack_gather_filelist (List * * filelist ,char * path ,Oid spcOid ,Oid dbOid );
7179static int ptrack_filelist_getnext (PtScanCtx * ctx );
7280
@@ -108,8 +116,10 @@ _PG_init(void)
108116mdwrite_hook = ptrack_mdwrite_hook ;
109117prev_mdextend_hook = mdextend_hook ;
110118mdextend_hook = ptrack_mdextend_hook ;
119+ #if PG_VERSION_NUM >=120000
111120prev_ProcessSyncRequests_hook = ProcessSyncRequests_hook ;
112121ProcessSyncRequests_hook = ptrack_ProcessSyncRequests_hook ;
122+ #endif
113123}
114124
115125/*
@@ -122,7 +132,9 @@ _PG_fini(void)
122132copydir_hook = prev_copydir_hook ;
123133mdwrite_hook = prev_mdwrite_hook ;
124134mdextend_hook = prev_mdextend_hook ;
135+ #if PG_VERSION_NUM >=120000
125136ProcessSyncRequests_hook = prev_ProcessSyncRequests_hook ;
137+ #endif
126138}
127139
128140/*
@@ -194,6 +206,7 @@ ptrack_mdextend_hook(RelFileNodeBackend smgr_rnode,
194206prev_mdextend_hook (smgr_rnode ,forknum ,blocknum );
195207}
196208
209+ #if PG_VERSION_NUM >=120000
197210static void
198211ptrack_ProcessSyncRequests_hook ()
199212{
@@ -202,6 +215,7 @@ ptrack_ProcessSyncRequests_hook()
202215if (prev_ProcessSyncRequests_hook )
203216prev_ProcessSyncRequests_hook ();
204217}
218+ #endif
205219
206220/*
207221 * Recursively walk through the path and add all data files to filelist.
@@ -426,7 +440,11 @@ ptrack_get_pagemapset(PG_FUNCTION_ARGS)
426440ctx -> filelist = NIL ;
427441
428442/* Make tuple descriptor */
443+ #if PG_VERSION_NUM >=120000
429444tupdesc = CreateTemplateTupleDesc (2 );
445+ #else
446+ tupdesc = CreateTemplateTupleDesc (2 , false);
447+ #endif
430448TupleDescInitEntry (tupdesc , (AttrNumber )1 ,"path" ,TEXTOID ,-1 ,0 );
431449TupleDescInitEntry (tupdesc , (AttrNumber )2 ,"pagemap" ,BYTEAOID ,-1 ,0 );
432450funcctx -> tuple_desc = BlessTupleDesc (tupdesc );
@@ -475,6 +493,7 @@ ptrack_get_pagemapset(PG_FUNCTION_ARGS)
475493char pathname [MAXPGPATH ];
476494bytea * result = NULL ;
477495Size result_sz = pagemap .bitmapsize + VARHDRSZ ;
496+ HeapTuple htup = NULL ;
478497
479498/* Create a bytea copy of our bitmap */
480499result = (bytea * )palloc (result_sz );
@@ -490,7 +509,9 @@ ptrack_get_pagemapset(PG_FUNCTION_ARGS)
490509pagemap .bitmap = NULL ;
491510pagemap .bitmapsize = 0 ;
492511
493- SRF_RETURN_NEXT (funcctx ,HeapTupleGetDatum (heap_form_tuple (funcctx -> tuple_desc ,values ,nulls )));
512+ htup = heap_form_tuple (funcctx -> tuple_desc ,values ,nulls );
513+ if (htup )
514+ SRF_RETURN_NEXT (funcctx ,HeapTupleGetDatum (htup ));
494515}
495516else
496517{