@@ -163,6 +163,11 @@ bool data_sync_retry = false;
163163/* How SyncDataDirectory() should do its job. */
164164int recovery_init_sync_method = RECOVERY_INIT_SYNC_METHOD_FSYNC ;
165165
166+ /* Which kinds of files should be opened with PG_O_DIRECT. */
167+ int io_direct_flags ;
168+
169+ CheckTempFileSize_hook_type CheckTempFileSize_hook = NULL ;
170+
166171/* Debugging.... */
167172
168173#ifdef FDDEBUG
@@ -1907,6 +1912,10 @@ FileClose(File file)
19071912 {
19081913 /* Subtract its size from current usage (do first in case of error) */
19091914 temporary_files_size -= vfdP -> fileSize ;
1915+ if (CheckTempFileSize_hook != NULL )
1916+ {
1917+ CheckTempFileSize_hook (vfdP -> fileSize , PG_TEMP_FILES_SIZE_DEC );
1918+ }
19101919 vfdP -> fileSize = 0 ;
19111920 }
19121921
@@ -2120,6 +2129,10 @@ FileWrite(File file, char *buffer, int amount, off_t offset,
21202129 (errcode (ERRCODE_CONFIGURATION_LIMIT_EXCEEDED ),
21212130 errmsg ("temporary file size exceeds temp_file_limit (%dkB)" ,
21222131 temp_file_limit )));
2132+ if (CheckTempFileSize_hook != NULL )
2133+ {
2134+ CheckTempFileSize_hook (past_write - vfdP -> fileSize , PG_TEMP_FILES_SIZE_CHECK );
2135+ }
21232136 }
21242137 }
21252138
@@ -2145,6 +2158,10 @@ FileWrite(File file, char *buffer, int amount, off_t offset,
21452158 if (past_write > vfdP -> fileSize )
21462159 {
21472160 temporary_files_size += past_write - vfdP -> fileSize ;
2161+ if (CheckTempFileSize_hook != NULL )
2162+ {
2163+ CheckTempFileSize_hook (past_write - vfdP -> fileSize , PG_TEMP_FILES_SIZE_INC );
2164+ }
21482165 vfdP -> fileSize = past_write ;
21492166 }
21502167 }
@@ -2237,6 +2254,10 @@ FileTruncate(File file, off_t offset, uint32 wait_event_info)
22372254 /* adjust our state for truncation of a temp file */
22382255 Assert (VfdCache [file ].fdstate & FD_TEMP_FILE_LIMIT );
22392256 temporary_files_size -= VfdCache [file ].fileSize - offset ;
2257+ if (CheckTempFileSize_hook != NULL )
2258+ {
2259+ CheckTempFileSize_hook (VfdCache [file ].fileSize - offset , PG_TEMP_FILES_SIZE_DEC );
2260+ }
22402261 VfdCache [file ].fileSize = offset ;
22412262 }
22422263
@@ -2971,6 +2992,11 @@ static void
29712992AtProcExit_Files (int code , Datum arg )
29722993{
29732994 CleanupTempFiles (false, true);
2995+
2996+ if (CheckTempFileSize_hook != NULL )
2997+ {
2998+ CheckTempFileSize_hook (temporary_files_size , PG_TEMP_FILES_SIZE_DEC );
2999+ }
29743000}
29753001
29763002/*
0 commit comments