• pg 模拟主库down机之pg_kaboom


        为了测试pg模拟down机,可使用插件pg_kaboom:GitHub - pgguru/pg_kaboom: Devious SQL-based SQL tools to crash your PostgreSQL server

    1. $ git clone git@github.com:CrunchyData/pg_kaboom.git
    2. $ cd pg_kaboom
    3. $ make PG_CONFIG=path/to/pg_config && make install PG_CONFIG=path/to/pg_config
    4. $ psql -c 'CREATE EXTENSION pg_kaboom' -U pg13 -d postgres

    开始模拟:

    1. [pg13@hdp1 ~]$ psql -d postgres
    2. psql (13.3, server 13.2)
    3. Type "help" for help.
    4. postgres=# SET pg_kaboom.disclaimer = 'I can afford to lose this data and server';
    5. SET
    6. postgres=# SET pg_kaboom.execute = on;
    7. SET
    8. postgres=# SELECT pg_kaboom('segfault');
    9. ERROR: for safety, pg_kaboom.disclaimer must be explicitly set to 'I can afford to lose this data and server'
    10. #这里需要再次确认
    11. postgres=# SET pg_kaboom.disclaimer = 'I can afford to lose this data and server';
    12. SET
    13. postgres=# SELECT pg_kaboom('segfault');
    14. server closed the connection unexpectedly
    15. This probably means the server terminated abnormally
    16. before or while processing the request.
    17. The connection to the server was lost. Attempting reset: Failed.
    18. #目前已经down机
    19. !?>

     所以我们可以通过这个工具模拟主库down机。来测试主备切换、生成数据库core文件等工作。

    除了上述函数pg_kaboom的参数segfault之外,参数还有以下几个:

    • break-archive :: install a broken archive_command and force a restart

    • fill-log :: allocate all of the space inside the logs directory

    • fill-pgdata :: allocate all of the space inside the $PGDATA directory

    • fill-pgwal :: allocate all of the space inside the $PGDATA/pg_wal directory

    • mem :: allocate some memory

    • restart :: do an immediate restart of the server

    • rm-pgdata :: do a rm -Rf $PGDATA

    • segfault :: cause a segfault in the running backend process

    • signal :: send a SIGKILL to the Postmaster process

    • xact-wrap :: force the database to run an xact-wraparound vacuum

    You can also use the following "special" weapons:

    • random :: choose a random weapon

    • null :: don't do anything, just go through the normal flow

  • 相关阅读:
    2022数学建模国赛C题思路分析
    2022.8前端面试准备题
    Office Tool Plus下载与神龙版官网下载
    浅谈JS——理解回调函数
    微信小程序之组件(一)
    【C语言】插入排序详解
    ubuntu安装gptsovits
    完整的电商平台后端API开发总结
    liunx 基础命令应用
    郑州分销系统开发|如何实现快速分销裂变?
  • 原文地址:https://blog.csdn.net/wdnq1022/article/details/134520055