after-logon-hook.diff

text/plain

Filename: after-logon-hook.diff
Type: text/plain
Part: 0
Message: proposal : backend startup hook / after logon trigger

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: unified
File+
src/backend/tcop/postgres.c 0 0
src/include/miscadmin.h 0 0
diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c
new file mode 100644
index 976a832..35f1926
*** a/src/backend/tcop/postgres.c
--- b/src/backend/tcop/postgres.c
*************** int			max_stack_depth = 100;
*** 104,110 ****
  /* wait N seconds to allow attach from a debugger */
  int			PostAuthDelay = 0;
  
! 
  
  /* ----------------
   *		private variables
--- 104,110 ----
  /* wait N seconds to allow attach from a debugger */
  int			PostAuthDelay = 0;
  
! backend_startup_hook_type backend_startup_hook = NULL;
  
  /* ----------------
   *		private variables
*************** PostgresMain(int argc, char *argv[], con
*** 3750,3755 ****
--- 3750,3769 ----
  	if (!ignore_till_sync)
  		send_ready_for_query = true;	/* initially, or after error */
  
+ 	if (backend_startup_hook != NULL)
+ 	{
+ 		PG_TRY();
+ 		{
+ 			backend_startup_hook(MyProcPid, MyDatabaseId, dbname, username);
+ 		}
+ 		PG_CATCH();
+ 		{
+ 			elog(FATAL, "Error calling after-logon trigger");
+ 			proc_exit(0);
+ 		}
+ 		PG_END_TRY();
+ 	}
+ 
  	/*
  	 * Non-error queries loop here.
  	 */
diff --git a/src/include/miscadmin.h b/src/include/miscadmin.h
new file mode 100644
index 9d19417..3971268
*** a/src/include/miscadmin.h
--- b/src/include/miscadmin.h
*************** extern bool is_authenticated_user_replic
*** 388,391 ****
--- 388,396 ----
  extern bool BackupInProgress(void);
  extern void CancelBackup(void);
  
+ typedef void (*backend_startup_hook_type) (pid_t pid, Oid databaseOid,
+                                            const char * dbname, const char * username);
+ 
+ extern backend_startup_hook_type backend_startup_hook;
+ 
  #endif   /* MISCADMIN_H */