-
Notifications
You must be signed in to change notification settings - Fork 40
Check collector has started in pg_wait_sampling_reset_profile. #100
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
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
392b87c
to
18088dd
Compare
Воспроизведение. Можно запускать в любой директории, создается временный докер-контейнер. #!/bin/bash
sudo docker run --rm -i ubuntu:24.04 bash <<"EOF"
set -xe
apt-get update
apt-get install -y \
git build-essential pkg-config libicu-dev libipc-run-perl \
flex bison libreadline-dev libz-dev gettext libperl-dev
git clone -b REL_17_5 --depth 1 https://github.com/postgres/postgres
cd postgres
git clone https://github.com/postgrespro/pg_wait_sampling contrib/pg_wait_sampling
mkdir contrib/pgws_reproduce
cat - > contrib/pgws_reproduce/Makefile <<"_EOF"
MODULE_big = pgws_reproduce
OBJS = main.o
EXTENSION = pgws_reproduce
REGRESS =
subdir = contrib/pgws_reproduce
top_builddir = ../..
include $(top_builddir)/src/Makefile.global
include $(top_srcdir)/contrib/contrib-global.mk
_EOF
cat - > contrib/pgws_reproduce/pgws_reproduce.control <<"_EOF"
pg_wait_sampling extension
comment = 'reproduce bug'
default_version = '1'
module_pathname = '$libdir/pgws_reproduce'
relocatable = true
_EOF
cat - > contrib/pgws_reproduce/main.c <<"_EOF"
#include "postgres.h"
#include "postmaster/bgworker.h"
#include "fmgr.h"
#include <sched.h> /* Only works on linux. */
PG_MODULE_MAGIC;
void pgws_reproduce_worker_main(Datum main_arg);
void _PG_init(void);
void pgws_reproduce_worker_main(Datum main_arg) {
while (true) {
sched_yield();
}
}
void _PG_init(void) {
/* Default limit of workers is 8. */
for (int i = 0; i < 32; ++i) {
BackgroundWorker worker;
memset(&worker, 0, sizeof(worker));
worker.bgw_restart_time = 1;
worker.bgw_flags = BGWORKER_SHMEM_ACCESS;
snprintf(worker.bgw_library_name, BGW_MAXLEN, "pgws_reproduce");
snprintf(worker.bgw_function_name, BGW_MAXLEN, CppAsString(pgws_reproduce_worker_main));
worker.bgw_main_arg = (Datum) 0;
RegisterBackgroundWorker(&worker);
}
}
_EOF
grep -v '$(recurse' contrib/Makefile > output.txt
mv output.txt contrib/Makefile
echo 'SUBDIRS += pg_wait_sampling pgws_reproduce' >> contrib/Makefile
echo -e '$(recurse)\n$(recurse_always)' >> contrib/Makefile
CFLAGS='-ggdb -O0 -g' ./configure -q \
--enable-cassert --enable-tap-tests --enable-nls \
--with-icu --with-perl --prefix=$(pwd)/install
make -s -j$(nproc) world-bin
make -s -j$(nproc) install-world-bin
useradd postgres
chown -R postgres .
cd install
su postgres -c 'bin/initdb -D data'
su postgres -c "echo \"shared_preload_libraries = 'pgws_reproduce, pg_wait_sampling'\" > data/postgresql.conf"
su postgres -c 'bin/pg_ctl -D data -l logfile start' || (cat logfile; exit 1)
cd ..
su postgres -c 'make -C contrib/pg_wait_sampling installcheck' || (grep '(PID ' install/logfile; exit 2)
cat install/logfile
EOF
|
a734610
to
14d7d61
Compare
Medvecrab
requested changes
Jun 24, 2025
pg_wait_sampling.c
Outdated
@@ -819,6 +825,18 @@ pg_wait_sampling_reset_profile(PG_FUNCTION_ARGS) | |||
pgws_collector_hdr->request = PROFILE_RESET; | |||
LockRelease(&collectorTag, ExclusiveLock, false); | |||
|
|||
/* The collector may have not started yet (it'd be a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, start a comment with an empty line, such as
/*
* The collector may not have started yet...
14d7d61
to
25cf0e1
Compare
The worker might have not started yet or it may never start, because its registration was cancelled due to worker limit. This commit adds a check for NULL value of pgws_collector_hdr->latch. The previous usage in pg_wait_sampling.c has such a check, we should do the same here.
25cf0e1
to
930a67a
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The worker might have not started yet or it may never start, because its registration was cancelled due to worker limit.
This commit adds a check for NULL value of pgws_collector_hdr->latch. The previous usage in pg_wait_sampling.c has such a check, we should do the same here.