pg 模拟主库down机之pg_kaboom

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

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

开始模拟:

[pg13@hdp1 ~]$ psql -d postgres
psql (13.3, server 13.2)
Type "help" for help.

postgres=# SET pg_kaboom.disclaimer = 'I can afford to lose this data and server';
SET
postgres=# SET pg_kaboom.execute = on;
SET
postgres=# SELECT pg_kaboom('segfault');
ERROR:  for safety, pg_kaboom.disclaimer must be explicitly set to 'I can afford to lose this data and server'

#这里需要再次确认
postgres=# SET pg_kaboom.disclaimer = 'I can afford to lose this data and server';
SET

postgres=# SELECT pg_kaboom('segfault');
server closed the connection unexpectedly
        This probably means the server terminated abnormally
        before or while processing the request.
The connection to the server was lost. Attempting reset: Failed.

#目前已经down机
!?>

 所以我们可以通过这个工具模拟主库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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值