- Notifications
You must be signed in to change notification settings - Fork39
Various fixes for compatibility with pg 15#49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
4 commits Select commitHold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
13 changes: 12 additions & 1 deletioncollector.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
84 changes: 58 additions & 26 deletionspg_wait_sampling.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -39,7 +39,6 @@ | ||
PG_MODULE_MAGIC; | ||
void_PG_init(void); | ||
/* Global variables */ | ||
boolshmem_initialized = false; | ||
@@ -59,6 +58,9 @@ shm_mq *recv_mq = NULL; | ||
shm_mq_handle *recv_mqh = NULL; | ||
LOCKTAGqueueTag; | ||
#if PG_VERSION_NUM >= 150000 | ||
static shmem_request_hook_type prev_shmem_request_hook = NULL; | ||
#endif | ||
static shmem_startup_hook_type prev_shmem_startup_hook = NULL; | ||
static PGPROC * search_proc(int backendPid); | ||
static PlannedStmt *pgws_planner_hook(Query *parse, | ||
@@ -74,28 +76,40 @@ static void pgws_ExecutorEnd(QueryDesc *queryDesc); | ||
* The value has to be in sync with ProcGlobal->allProcCount, initialized in | ||
* InitProcGlobal() (proc.c). | ||
* | ||
*/ | ||
static int | ||
get_max_procs_count(void) | ||
{ | ||
int count = 0; | ||
/* First, add the maximum number of backends (MaxBackends). */ | ||
#if PG_VERSION_NUM >= 150000 | ||
/* | ||
* On pg15+, we can directly access the MaxBackends variable, as it will | ||
* have already been initialized in shmem_request_hook. | ||
*/ | ||
Assert(MaxBackends > 0); | ||
count += MaxBackends; | ||
#else | ||
/* | ||
* On older versions, we need to compute MaxBackends: bgworkers, autovacuum | ||
* workers and launcher. | ||
* This has to be in sync with the value computed in | ||
maksm90 marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
* InitializeMaxBackends() (postinit.c) | ||
* | ||
* Note that we need to calculate the value as it won't initialized when we | ||
* need it during _PG_init(). | ||
* | ||
* Note also that the value returned during _PG_init() might be different | ||
* from the value returned later if some third-party modules change one of | ||
* the underlying GUC. This isn't ideal but can't lead to a crash, as the | ||
* value returned during _PG_init() is only used to ask for additional | ||
* shmem with RequestAddinShmemSpace(), and postgres has an extra 100kB of | ||
* shmem to compensate some small unaccounted usage. So if the value later | ||
* changes, we will allocate and initialize the new (and correct) memory | ||
* size, which will either work thanks for the extra 100kB of shmem, of | ||
* fail (and prevent postgres startup) due to an out of shared memory | ||
* error. | ||
*/ | ||
count += MaxConnections + autovacuum_max_workers + 1 | ||
+ max_worker_processes; | ||
@@ -106,9 +120,11 @@ get_max_procs_count(void) | ||
*/ | ||
#if PG_VERSION_NUM >= 120000 | ||
count += max_wal_senders; | ||
#endif/* pg 12+ */ | ||
#endif/* pg 15- */ | ||
/* End of MaxBackends calculation. */ | ||
/*AddAuxiliaryProcs */ | ||
count += NUM_AUXILIARY_PROCS; | ||
return count; | ||
@@ -266,6 +282,23 @@ setup_gucs() | ||
} | ||
} | ||
#if PG_VERSION_NUM >= 150000 | ||
/* | ||
* shmem_request hook: request additional shared memory resources. | ||
* | ||
* If you change code here, don't forget to also report the modifications in | ||
* _PG_init() for pg14 and below. | ||
*/ | ||
static void | ||
pgws_shmem_request(void) | ||
{ | ||
if (prev_shmem_request_hook) | ||
prev_shmem_request_hook(); | ||
RequestAddinShmemSpace(pgws_shmem_size()); | ||
} | ||
#endif | ||
/* | ||
* Distribute shared memory. | ||
*/ | ||
@@ -345,18 +378,27 @@ _PG_init(void) | ||
if (!process_shared_preload_libraries_in_progress) | ||
return; | ||
#if PG_VERSION_NUM < 150000 | ||
/* | ||
* Request additional shared resources. (These are no-ops if we're not in | ||
* the postmaster process.) We'll allocate or attach to the shared | ||
* resources in pgws_shmem_startup(). | ||
* | ||
* If you change code here, don't forget to also report the modifications | ||
* in pgsp_shmem_request() for pg15 and later. | ||
*/ | ||
RequestAddinShmemSpace(pgws_shmem_size()); | ||
#endif | ||
register_wait_collector(); | ||
/* | ||
* Install hooks. | ||
*/ | ||
#if PG_VERSION_NUM >= 150000 | ||
prev_shmem_request_hook = shmem_request_hook; | ||
shmem_request_hook= pgws_shmem_request; | ||
#endif | ||
prev_shmem_startup_hook = shmem_startup_hook; | ||
shmem_startup_hook= pgws_shmem_startup; | ||
planner_hook_next= planner_hook; | ||
@@ -365,16 +407,6 @@ _PG_init(void) | ||
ExecutorEnd_hook= pgws_ExecutorEnd; | ||
} | ||
/* | ||
* Find PGPROC entry responsible for given pid assuming ProcArrayLock was | ||
* already taken. | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.