@@ -162,6 +162,10 @@ int do_one_job(schd_executor_share_t *shared, schd_executor_status_t *status)
162162int i ;
163163job_t * job ;
164164spi_response_t * r ;
165+ MemoryContext old ;
166+ MemoryContext mem = init_mem_ctx ("executor" );
167+
168+ old = MemoryContextSwitchTo (mem );
165169
166170EE .n = 0 ;
167171EE .errors = NULL ;
@@ -230,11 +234,11 @@ int do_one_job(schd_executor_share_t *shared, schd_executor_status_t *status)
230234}
231235if (job -> type == AtJob && i == 0 && job -> sql_params_n > 0 )
232236{
233- r = execute_spi_params_prepared (job -> dosql [i ],job -> sql_params_n ,job -> sql_params );
237+ r = execute_spi_params_prepared (mem , job -> dosql [i ],job -> sql_params_n ,job -> sql_params );
234238}
235239else
236240{
237- r = execute_spi (job -> dosql [i ]);
241+ r = execute_spi (mem , job -> dosql [i ]);
238242}
239243if (r -> retval < 0 )
240244{
@@ -321,6 +325,8 @@ int do_one_job(schd_executor_share_t *shared, schd_executor_status_t *status)
321325
322326SetSessionAuthorization (BOOTSTRAP_SUPERUSERID , true);
323327ResetAllOptions ();
328+ MemoryContextSwitchTo (old );
329+ MemoryContextDelete (mem );
324330
325331return 1 ;
326332}
@@ -336,23 +342,24 @@ int set_session_authorization(char *username, char **error)
336342int rv ;
337343char * sql = "select oid, rolsuper from pg_catalog.pg_roles where rolname = $1" ;
338344char buff [1024 ];
345+ MemoryContext mem = CurrentMemoryContext ;
339346
340347values [0 ]= CStringGetTextDatum (username );
341348START_SPI_SNAP ();
342- r = execute_spi_sql_with_args (sql ,1 ,types ,values ,NULL );
349+ r = execute_spi_sql_with_args (mem , sql ,1 ,types ,values ,NULL );
343350
344351if (r -> retval < 0 )
345352{
346353rv = r -> retval ;
347- * error = _copy_string ( r -> error );
354+ * error = _mcopy_string ( mem , r -> error );
348355destroy_spi_data (r );
349356return rv ;
350357}
351358if (r -> n_rows == 0 )
352359{
353360STOP_SPI_SNAP ();
354361sprintf (buff ,"Cannot find user with name: %s" ,username );
355- * error = _copy_string ( buff );
362+ * error = _mcopy_string ( mem , buff );
356363destroy_spi_data (r );
357364
358365return -200 ;
@@ -415,7 +422,7 @@ TimestampTz get_next_excution_time(char *sql, executor_error_t *ee)
415422
416423START_SPI_SNAP ();
417424pgstat_report_activity (STATE_RUNNING ,"culc next time execution time" );
418- r = execute_spi (sql );
425+ r = execute_spi (CurrentMemoryContext , sql );
419426if (r -> retval < 0 )
420427{
421428if (r -> error )
@@ -469,7 +476,7 @@ int executor_onrollback(job_t *job, executor_error_t *ee)
469476pgstat_report_activity (STATE_RUNNING ,"execure onrollback" );
470477
471478START_SPI_SNAP ();
472- r = execute_spi (job -> onrollback );
479+ r = execute_spi (CurrentMemoryContext , job -> onrollback );
473480if (r -> retval < 0 )
474481{
475482if (r -> error )
@@ -502,7 +509,7 @@ void set_pg_var(bool result, executor_error_t *ee)
502509
503510vals [0 ]= PointerGetDatum (cstring_to_text (result ?"success" :"failure" ));
504511
505- r = execute_spi_sql_with_args (sql ,1 ,argtypes ,vals ,NULL );
512+ r = execute_spi_sql_with_args (NULL , sql ,1 ,argtypes ,vals ,NULL );
506513if (r -> retval < 0 )
507514{
508515if (r -> error )
@@ -712,14 +719,16 @@ int process_one_job(schd_executor_share_state_t *shared, schd_executor_status_t
712719int set_ret ;
713720char buff [512 ];
714721spi_response_t * r ;
722+ MemoryContext old ;
723+ MemoryContext mem = init_mem_ctx ("at job processor" );
724+ old = MemoryContextSwitchTo (mem );
715725
716726* status = shared -> status = SchdExecutorWork ;
717727
718728pgstat_report_activity (STATE_RUNNING ,"initialize at job" );
719729START_SPI_SNAP ();
720730
721- /* job = get_next_at_job_with_lock(shared->nodename, &error); */
722- job = get_at_job_for_process (shared -> nodename ,& error );
731+ job = get_at_job_for_process (mem ,shared -> nodename ,& error );
723732if (!job )
724733{
725734if (error )
@@ -765,7 +774,8 @@ int process_one_job(schd_executor_share_state_t *shared, schd_executor_status_t
765774return -1 ;
766775}
767776STOP_SPI_SNAP ();
768- elog (LOG ,"JOB MOVED TO DONE" );
777+ MemoryContextSwitchTo (old );
778+ MemoryContextDelete (mem );
769779return 1 ;
770780}
771781
@@ -780,11 +790,11 @@ int process_one_job(schd_executor_share_state_t *shared, schd_executor_status_t
780790
781791if (job -> sql_params_n > 0 )
782792{
783- r = execute_spi_params_prepared (job -> dosql [0 ],job -> sql_params_n ,job -> sql_params );
793+ r = execute_spi_params_prepared (mem , job -> dosql [0 ],job -> sql_params_n ,job -> sql_params );
784794}
785795else
786796{
787- r = execute_spi (job -> dosql [0 ]);
797+ r = execute_spi (mem , job -> dosql [0 ]);
788798}
789799if (job -> timelimit )
790800{
@@ -819,6 +829,8 @@ int process_one_job(schd_executor_share_state_t *shared, schd_executor_status_t
819829if (set_ret > 0 )
820830{
821831STOP_SPI_SNAP ();
832+ MemoryContextSwitchTo (old );
833+ MemoryContextDelete (mem );
822834return 1 ;
823835}
824836if (set_error )
@@ -831,6 +843,8 @@ int process_one_job(schd_executor_share_state_t *shared, schd_executor_status_t
831843elog (LOG ,"AT_EXECUTOR ERROR: set log: unknown error" );
832844}
833845ABORT_SPI_SNAP ();
846+ MemoryContextSwitchTo (old );
847+ MemoryContextDelete (mem );
834848
835849return -1 ;
836850}
@@ -846,7 +860,7 @@ Oid set_session_authorization_by_name(char *rolename, char **error)
846860if (!HeapTupleIsValid (roleTup ))
847861{
848862snprintf (buffer ,512 ,"There is no user name: %s" ,rolename );
849- * error = _copy_string ( buffer );
863+ * error = _mcopy_string ( NULL , buffer );
850864return InvalidOid ;
851865}
852866rform = (Form_pg_authid )GETSTRUCT (roleTup );