Skip to content
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

feat(pgsql): param node_hugepage_count accepts value -1 to set hugepage automatically (only PG 15+) #541

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

waitingsong
Copy link
Contributor

@waitingsong waitingsong commented Mar 17, 2025

nr_hugepages calculated by shared_memory_size_in_huge_pages

if node_hugepage_count or node_hugepage_ratio changed, it will full backup the pg_cls and restart it gracefully

support usage:

  • pig install
  • bin/pgsql-add <pg_cls>
  • bin/pgsql-add <pg_cls> <ip>
    service of nodes in ansible_play_hosts_all will be unavailable during the process, other nodes in the same pg_cls ignored
  • pgsql.yml -t pg_hugepage
    entire service of all of the postgres clusters will be unavailable during the process
  • pgsql.yml -l <pg_cls> -t pg_hugepage
    entire service of this postgres cluster will be unavailable during the process
  • pgsql.yml -l '<ip>,&<pg_cls>' -t pg_hugepage
    service of nodes in ansible_play_hosts_all will be unavailable during the process, other nodes in the same pg_cls ignored

calculation rules:

  1. shared_memory_size_in_huge_pages (from PG15+): if node_hugepage_count is -1 and huge_pages (from PG) != off
  2. if node_hugepage_count > 0
    • shared_memory_size_in_huge_pages: if shared_memory_size_in_huge_pages > node_hugepage_count
    • node_hugepage_count
  3. disable hugepage if node_hugepage_count is 0
  4. if node_hugepage_ratio > 0
    - shared_memory_size_in_huge_pages: if shared_memory_size_in_huge_pages > pages calculated from node_hugepage_ratio
    - page value calculated from node_hugepage_ratio

All above rules and usages are tested successfully on Rocky Linux 9


patroni restart pg_cls gracefully, without switchover. switchover triggered when patroni restart primary failed.

tested usage:

  • ./pgsql.yml -l <pg_cls> -t pt_restart -e "pt_restart=true"
    • all nodes have been restarted
  • ./pgsql.yml -l '<ip>,&<pg_cls>' -t pt_restart -e "pt_restart=true"
    • nodes in ansible_play_hosts_all have been restarted, other nodes in the same pg_cls ignored
  • ./pgsql.yml -l '<replica>,<primary>,&<pg_cls>' -t pt_restart -e "pt_restart=true"
    • nodes in ansible_play_hosts_all have been restarted, other nodes in the same pg_cls ignored
    • switchover triggered when patroni restart primary failed

inner steps:

  1. patroni pause pg_cls
  2. patroni restart pg_cls
  3. patroni resume pg_cls

pg-backup strategy before update hugepage

  • full backup when ansible_play_hosts_all contains primary
  • full or incremental backup when ansible_play_hosts_all contains no primary

tested scenarios:

  • ./pgsql.yml -l <pg_cls> -t pg_hugepage
    • full backup
  • ./pgsql.yml -l '<replica>,<primary>,&<pg_cls>' -t pg_hugepage
    • full backup
  • ./pgsql.yml -l '<replica>,&<pg_cls>' -t pg_hugepage
    • full or incremental backup

@waitingsong waitingsong changed the title WIP feat(pgsql): param node_hugepage_count accepts value -1 to set hugepage automatically (only PG 15+) feat(pgsql): param node_hugepage_count accepts value -1 to set hugepage automatically (only PG 15+) Mar 17, 2025
- check_pg_ready
- is_patroni_paused
- start postgres
- start and stop postgres gracefully
- patroni pause|resume gracefully
- patroni_restart
- grace_patroni_restart
- pg_read_hugepage
- pg_write_hugepage
…page automatically (only PG 15+)

nr_hugepages calculated by `shared_memory_size_in_huge_pages`

if `node_hugepage_count` or `node_hugepage_ratio` changed, it will full backup the pg_cls and restart it gracefully

support usage:
  - `pig install`
  - `bin/pgsql-add <pg_cls>`
  -  `bin/pgsql-add <pg_cls> <ip>`
     only new nodes changed and restarted
  - `pgsql.yml -l <pg_cls> -t pg_hugepage`

calculation rules:
  1. `shared_memory_size_in_huge_pages` (from PG15+): if `node_hugepage_count` is -1 and huge_pages (from PG) != off
  2. if `node_hugepage_count` > 0
     - `shared_memory_size_in_huge_pages`: if `shared_memory_size_in_huge_pages` > `node_hugepage_count`
     - `node_hugepage_count`
  3. disable hugepage if `node_hugepage_count` is 0
  4. if `node_hugepage_ratio` > 0
    - `shared_memory_size_in_huge_pages`: if `shared_memory_size_in_huge_pages` > pages calculated from `node_hugepage_ratio`
    - page value calculated from `node_hugepage_ratio`

All above rules and usages are tested successfully on Rocky Linux 9
move import of pg_hugepage.yml and grace_patroni_restart.yml at bottom
tested scenarios:
- `./pgsql.yml -l <pg_cls> -t pt_restart -e "pt_restart=true"`
   - all nodes have been restarted
- `./pgsql.yml -l '<ip>,&<pg_cls>' -t pt_restart -e "pt_restart=true"`
   - nodes in ansible_play_hosts_all have been restarted, other nodes in the same pg_cls ignored
- `./pgsql.yml -l '<replica>,<primary>,&<pg_cls>' -t pt_restart -e "pt_restart=true"`
   - nodes in ansible_play_hosts_all have been restarted, other nodes in the same pg_cls ignored
   - switchover triggered when patroni restart primary failed
when new_nr_hugepages equals to pg_shared_memory_size_in_huge_pages
@waitingsong
Copy link
Contributor Author

waitingsong commented Mar 18, 2025

f28c2cc is same as 2f3aaea of PR

- full backup when ansible_play_hosts_all contains primary
- full or incremental backup when ansible_play_hosts_all contains no primary

tested scenarios:
- `./pgsql.yml -l <pg_cls> -t pg_hugepage`
  - full backup
- `./pgsql.yml -l '<replica>,<primary>,&<pg_cls>' -t pg_hugepage`
  - full backup
- `./pgsql.yml -l '<replica>,&<pg_cls>' -t pg_hugepage`
  - full or incremental backup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant