-
-
Notifications
You must be signed in to change notification settings - Fork 201
tests: create a tmp image that has coredumps enabled for testing #1754
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
Draft
samrose
wants to merge
11
commits into
develop
Choose a base branch
from
sam/tmp-coredump-img
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f851f55
tests: create a tmp image that has coredumps enabled for testing
samrose 069273d
fix:
samrose 63899ee
fix: more grub adjustments
samrose 5e26fde
fix: coredumps first
samrose 1b41b31
Update ansible/tasks/setup-coredumps.yml
samrose acf29e8
Update orioledb rev to include fix
za-arthur a09b238
Bump orioledb image name
za-arthur 2dd1c01
Bump orioledb image name
za-arthur 1f109be
Bump orioledb image name
za-arthur 4922dcf
Bump orioledb image name
za-arthur 5e3cd57
Bump orioledb image name
za-arthur File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,230 @@ | ||
--- | ||
# Setup coredump collection for debugging PostgreSQL crashes | ||
# This configuration is temporary and should be cleaned up after debugging | ||
|
||
- name: Create coredump directory | ||
become: yes | ||
file: | ||
path: /pg_coredump_debug | ||
state: directory | ||
mode: '0777' | ||
owner: root | ||
group: root | ||
when: stage2_nix | ||
|
||
- name: Configure kernel core pattern | ||
become: yes | ||
ansible.posix.sysctl: | ||
name: kernel.core_pattern | ||
value: '/pg_coredump_debug/core.%e.%p.%t' | ||
state: present | ||
sysctl_file: /etc/sysctl.d/99-coredump.conf | ||
reload: yes | ||
when: stage2_nix | ||
|
||
- name: Enable core dumps with PID | ||
become: yes | ||
ansible.posix.sysctl: | ||
name: kernel.core_uses_pid | ||
value: '1' | ||
state: present | ||
sysctl_file: /etc/sysctl.d/99-coredump.conf | ||
reload: yes | ||
when: stage2_nix | ||
|
||
- name: Enable SUID dumpable | ||
become: yes | ||
ansible.posix.sysctl: | ||
name: fs.suid_dumpable | ||
value: '1' | ||
state: present | ||
sysctl_file: /etc/sysctl.d/99-coredump.conf | ||
reload: yes | ||
when: stage2_nix | ||
|
||
- name: Create systemd system.conf.d directory | ||
become: yes | ||
file: | ||
path: /etc/systemd/system.conf.d | ||
state: directory | ||
mode: '0755' | ||
owner: root | ||
group: root | ||
when: stage2_nix | ||
|
||
- name: Configure systemd for coredumps | ||
become: yes | ||
copy: | ||
content: | | ||
# Temporary coredump configuration - remove after debugging | ||
[Manager] | ||
DefaultLimitCORE=infinity | ||
DumpCore=yes | ||
dest: /etc/systemd/system.conf.d/50-coredump.conf | ||
mode: '0644' | ||
owner: root | ||
group: root | ||
when: stage2_nix | ||
|
||
- name: Configure security limits for coredumps | ||
become: yes | ||
blockinfile: | ||
path: /etc/security/limits.conf | ||
block: | | ||
# Temporary coredump limits - remove after debugging | ||
* hard core 50000 | ||
* soft core 50000 | ||
marker: "# {mark} ANSIBLE MANAGED BLOCK - COREDUMP" | ||
state: present | ||
when: stage2_nix | ||
|
||
- name: Check current GRUB_CMDLINE_LINUX_DEFAULT | ||
become: yes | ||
shell: | | ||
if grep -q '^GRUB_CMDLINE_LINUX_DEFAULT=' /etc/default/grub; then | ||
grep '^GRUB_CMDLINE_LINUX_DEFAULT=' /etc/default/grub | sed 's/^GRUB_CMDLINE_LINUX_DEFAULT="\(.*\)"$/\1/' | ||
else | ||
echo "" | ||
fi | ||
register: current_grub_cmdline | ||
changed_when: false | ||
when: stage2_nix | ||
|
||
- name: Check for GRUB_CMDLINE_LINUX_DEFAULT in grub.d files | ||
become: yes | ||
shell: grep -l '^GRUB_CMDLINE_LINUX_DEFAULT=' /etc/default/grub.d/* 2>/dev/null || true | ||
register: grub_d_files | ||
changed_when: false | ||
when: stage2_nix | ||
|
||
- name: Prepare GRUB cmdline with coredump_filter | ||
set_fact: | ||
new_grub_cmdline: "{{ (current_grub_cmdline.stdout | regex_replace('coredump_filter=[0-9]+', '') | trim + ' coredump_filter=49') | trim }}" | ||
when: stage2_nix | ||
|
||
- name: Update GRUB configuration for coredump_filter in main grub file | ||
become: yes | ||
lineinfile: | ||
path: /etc/default/grub | ||
regexp: '^GRUB_CMDLINE_LINUX_DEFAULT=' | ||
line: 'GRUB_CMDLINE_LINUX_DEFAULT="{{ new_grub_cmdline }}"' | ||
create: yes | ||
when: | ||
- stage2_nix | ||
- grub_d_files.stdout == "" | ||
register: grub_main_updated | ||
|
||
- name: Update GRUB configuration for coredump_filter in grub.d files | ||
become: yes | ||
shell: | | ||
for file in {{ grub_d_files.stdout }}; do | ||
current=$(grep '^GRUB_CMDLINE_LINUX_DEFAULT=' "$file" | sed 's/^GRUB_CMDLINE_LINUX_DEFAULT="\(.*\)"$/\1/') | ||
new=$(echo "$current" | sed 's/coredump_filter=[0-9]*//g') | ||
new="${new} coredump_filter=49" | ||
sed -i "s/^GRUB_CMDLINE_LINUX_DEFAULT=.*/GRUB_CMDLINE_LINUX_DEFAULT=\"${new}\"/" "$file" | ||
done | ||
when: | ||
- stage2_nix | ||
- grub_d_files.stdout != "" | ||
register: grub_d_updated | ||
|
||
- name: Update GRUB after configuration changes | ||
become: yes | ||
command: update-grub | ||
when: | ||
- stage2_nix | ||
- (grub_main_updated is defined and grub_main_updated.changed) or (grub_d_updated is defined and grub_d_updated.changed) | ||
|
||
- name: Install gdb for debugging | ||
become: yes | ||
apt: | ||
pkg: | ||
- gdb | ||
state: present | ||
update_cache: yes | ||
cache_valid_time: 3600 | ||
when: stage2_nix | ||
|
||
- name: Create root .gdbinit configuration | ||
become: yes | ||
copy: | ||
content: | | ||
# GDB configuration for PostgreSQL debugging | ||
# Note: debug-file-directory and substitute-path need to be set manually | ||
# after installing debug symbols and source files from nix | ||
set auto-load safe-path / | ||
# Example paths - will be set dynamically when debugging: | ||
# set debug-file-directory /nix/store/<hash>-postgresql-<version>-debug/lib/debug/ | ||
# set substitute-path ./ /nix/store/<hash>-postgresql-<version>-src-<version>/ | ||
dest: /root/.gdbinit | ||
mode: '0644' | ||
owner: root | ||
group: root | ||
when: stage2_nix | ||
|
||
- name: Create postgres user .gdbinit configuration | ||
become: yes | ||
become_user: postgres | ||
copy: | ||
content: | | ||
# GDB configuration for PostgreSQL debugging | ||
# Note: debug-file-directory and substitute-path need to be set manually | ||
# after installing debug symbols and source files from nix | ||
set auto-load safe-path / | ||
# Example paths - will be set dynamically when debugging: | ||
# set debug-file-directory /nix/store/<hash>-postgresql-<version>-debug/lib/debug/ | ||
# set substitute-path ./ /nix/store/<hash>-postgresql-<version>-src-<version>/ | ||
dest: /var/lib/postgresql/.gdbinit | ||
mode: '0644' | ||
owner: postgres | ||
group: postgres | ||
when: stage2_nix | ||
|
||
- name: Create coredump setup documentation | ||
become: yes | ||
copy: | ||
content: | | ||
# PostgreSQL Coredump Configuration | ||
|
||
This AMI has been configured to collect PostgreSQL coredumps for debugging. | ||
|
||
## Configuration Files Modified: | ||
- /etc/sysctl.d/99-coredump.conf - Kernel coredump settings | ||
- /etc/systemd/system.conf.d/50-coredump.conf - Systemd coredump settings | ||
- /etc/security/limits.conf - User limits for coredump size | ||
- /etc/default/grub - GRUB configuration for coredump_filter | ||
|
||
## Coredump Location: | ||
Coredumps are saved to: /pg_coredump_debug/ | ||
|
||
## Debug Symbols: | ||
Debug symbols and source files are already installed via nix during the build. | ||
To find the paths: | ||
``` | ||
sudo -i -u postgres nix profile list | grep postgresql_.*_debug | ||
sudo -i -u postgres nix profile list | grep postgresql_.*_src | ||
``` | ||
|
||
## Using GDB: | ||
To analyze a coredump: | ||
``` | ||
sudo gdb postmaster -c /pg_coredump_debug/<core_file> | ||
``` | ||
|
||
Then in gdb, set the debug symbols path: | ||
``` | ||
symbol-file /nix/store/<hash>-postgresql-<version>-debug/lib/debug/postgres | ||
``` | ||
|
||
## Cleanup: | ||
To disable coredump collection after debugging: | ||
1. Remove /etc/sysctl.d/99-coredump.conf | ||
2. Remove /etc/systemd/system.conf.d/50-coredump.conf | ||
3. Remove coredump block from /etc/security/limits.conf | ||
4. Delete coredumps from /pg_coredump_debug/ | ||
5. Run: sudo sysctl -p && sudo systemctl daemon-reload | ||
dest: /pg_coredump_debug/README.md | ||
mode: '0644' | ||
owner: root | ||
group: root | ||
when: stage2_nix |
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
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
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
Oops, something went wrong.
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.
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.
I had to pass full path instead of just
postmaster
:I'm not sure how properly can I find the path. One can try:
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.
I think you can also find it in /var/lib/postgresql/.nix-profile/bin so there actually is already a conventional location (I just used the same "home" dir for the postgres user that infra team created before I did all the nix packaging, to make it easier for people to orient themselves who were already familiar with /var/lib/postgresql homedir)
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.
In my case I had to use the
.postgres-wrapped
file which isn't in/var/lib/postgresql/.nix-profile/bin
. TBH not sure how it is related to the originalpostgres
binary file.