pax_global_header00006660000000000000000000000064150230357170014515gustar00rootroot0000000000000052 comment=1f261763895e94cabe3c5005d7a95093a7c58381 pg_crash-0.3/000077500000000000000000000000001502303571700131455ustar00rootroot00000000000000pg_crash-0.3/.editorconfig000066400000000000000000000005441502303571700156250ustar00rootroot00000000000000root = true [*] indent_size = tab [*] trim_trailing_whitespace = true insert_final_newline = true indent_style = unset tab_width = unset [*.[chly]] trim_trailing_whitespace = true insert_final_newline = true indent_style = tab tab_width = 4 [*.out] indent_style = unset indent_size = unset trim_trailing_whitespace = unset insert_final_newline = unset pg_crash-0.3/LICENSE000066400000000000000000000030071502303571700141520ustar00rootroot00000000000000BSD 3-Clause License Copyright (c) 2017, 2025 CYBERTEC PostgreSQL International GmbH All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. pg_crash-0.3/Makefile000066400000000000000000000002301502303571700146000ustar00rootroot00000000000000MODULE_big = pg_crash OBJS = pg_crash.o $(WIN32RES) PGFILEDESC = "pg_crash" PG_CONFIG = pg_config PGXS := $(shell $(PG_CONFIG) --pgxs) include $(PGXS) pg_crash-0.3/README.md000066400000000000000000000020701502303571700144230ustar00rootroot00000000000000# pg\_crash If your database is too reliable - pg\_crash can kill it for you. pg\_crash is an extension to PostgreSQL, which allows you to periodically or randomly crash your database infrastructure by sending kill (or other) signals to your DB processes and make them fail. It is ideal for HA and failover testing. Works with Postgres >= 11. # Installation * Build the extension ``` PG_CONFIG=/usr/local/pgsql/bin/pg_config make sudo PG_CONFIG=/usr/local/pgsql/bin/pg_config make install ``` NB! Replace /usr/local/pgsql/bin with your desired binary * Edit server config Add 'pg\_crash to shared\_preload\_libraries and configure signals and timeouts ``` shared_preload_libraries = ',pg_crash' # any POSIX signals you want to emit from the background worker crash.signals = '1 2 3' # set delay (in seconds) between sending signals crash.delay = 30 ``` * restart the server ## Have fun troubleshooting! ### Developer Credits Antonin Houska, CYBERTEC PostgreSQL International GmbH. Visit our website: [www.cybertec-postgresql.com](https://www.cybertec-postgresql.com) pg_crash-0.3/debian/000077500000000000000000000000001502303571700143675ustar00rootroot00000000000000pg_crash-0.3/debian/changelog000066400000000000000000000004241502303571700162410ustar00rootroot00000000000000pg-crash (0.3-1) unstable; urgency=medium * New upstream version. -- Christoph Berg Fri, 13 Jun 2025 16:54:40 +0200 pg-crash (0.2-1) unstable; urgency=medium * Initial release. -- Christoph Berg Thu, 12 Jun 2025 16:44:40 +0200 pg_crash-0.3/debian/control000066400000000000000000000017721502303571700160010ustar00rootroot00000000000000Source: pg-crash Section: database Priority: optional Maintainer: Debian PostgreSQL Maintainers Uploaders: Christoph Berg , Build-Depends: architecture-is-64-bit , debhelper-compat (= 13), postgresql-all , postgresql-server-dev-all (>= 217~), Standards-Version: 4.7.2 Rules-Requires-Root: no Homepage: https://github.com/cybertec-postgresql/pg_crash Vcs-Browser: https://salsa.debian.org/postgresql/pg-crash Vcs-Git: https://salsa.debian.org/postgresql/pg-crash.git Package: postgresql-17-pg-crash Architecture: any Depends: ${misc:Depends}, ${postgresql:Depends}, ${shlibs:Depends}, Description: Periodically crash your PostgreSQL database If your database is too reliable - pg_crash can kill it for you. pg_crash is an extension to PostgreSQL that periodically crashes your database infrastructure by sending kill (or other) signals to your DB processes and make them fail. It is ideal for HA and failover testing. pg_crash-0.3/debian/control.in000066400000000000000000000020011502303571700163700ustar00rootroot00000000000000Source: pg-crash Section: database Priority: optional Maintainer: Debian PostgreSQL Maintainers Uploaders: Christoph Berg , Build-Depends: architecture-is-64-bit , debhelper-compat (= 13), postgresql-all , postgresql-server-dev-all (>= 217~), Standards-Version: 4.7.2 Rules-Requires-Root: no Homepage: https://github.com/cybertec-postgresql/pg_crash Vcs-Browser: https://salsa.debian.org/postgresql/pg-crash Vcs-Git: https://salsa.debian.org/postgresql/pg-crash.git Package: postgresql-PGVERSION-pg-crash Architecture: any Depends: ${misc:Depends}, ${postgresql:Depends}, ${shlibs:Depends}, Description: Periodically crash your PostgreSQL database If your database is too reliable - pg_crash can kill it for you. pg_crash is an extension to PostgreSQL that periodically crashes your database infrastructure by sending kill (or other) signals to your DB processes and make them fail. It is ideal for HA and failover testing. pg_crash-0.3/debian/copyright000066400000000000000000000033161502303571700163250ustar00rootroot00000000000000Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: pg-crash Source: https://github.com/cybertec-postgresql/pg_crash Files: * Copyright: Copyright (c) 2017, 2025 CYBERTEC PostgreSQL International GmbH License: BSD All rights reserved. . Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: . * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. . * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. . * Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. . THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. pg_crash-0.3/debian/gitlab-ci.yml000066400000000000000000000001371502303571700167460ustar00rootroot00000000000000include: https://salsa.debian.org/postgresql/postgresql-common/raw/master/gitlab/gitlab-ci.yml pg_crash-0.3/debian/pgversions000066400000000000000000000000041502303571700165030ustar00rootroot0000000000000011+ pg_crash-0.3/debian/rules000077500000000000000000000002521502303571700154460ustar00rootroot00000000000000#!/usr/bin/make -f %: dh $@ --with pgxs override_dh_pgxs_test: debian/tests/crash . . postgresql-%v-pg-crash override_dh_installdocs: dh_installdocs --all README.* pg_crash-0.3/debian/source/000077500000000000000000000000001502303571700156675ustar00rootroot00000000000000pg_crash-0.3/debian/source/format000066400000000000000000000000141502303571700170750ustar00rootroot000000000000003.0 (quilt) pg_crash-0.3/debian/tests/000077500000000000000000000000001502303571700155315ustar00rootroot00000000000000pg_crash-0.3/debian/tests/control000066400000000000000000000001151502303571700171310ustar00rootroot00000000000000Depends: postgresql-common-dev, @, Tests: crash Restrictions: allow-stderr pg_crash-0.3/debian/tests/crash000077500000000000000000000005051502303571700165570ustar00rootroot00000000000000#!/bin/sh set -e export LC_ALL=C.UTF-8 echo "psql -Xc 'SELECT pg_sleep(600)' 2>&1 | grep 'FATAL: terminating connection due to administrator command'" | \ pg_buildext \ -o "shared_preload_libraries=pg_crash" \ -o "superuser_reserved_connections=0" \ -o "max_wal_senders=0" \ -o "max_connections=1" \ virtualenv "$@" pg_crash-0.3/debian/watch000066400000000000000000000001201502303571700154110ustar00rootroot00000000000000version=4 https://github.com/cybertec-postgresql/pg_crash/tags .*/v?(.*).tar.gz pg_crash-0.3/pg_crash.c000066400000000000000000000071751502303571700151110ustar00rootroot00000000000000#include #include "c.h" #include "postgres.h" #include "fmgr.h" #include "miscadmin.h" #include "access/twophase.h" #include "catalog/pg_control.h" #include "postmaster/bgworker.h" #include "storage/proc.h" #include "utils/guc.h" PG_MODULE_MAGIC; extern void _PG_init(void); PGDLLEXPORT extern void crash_worker_main(Datum main_arg); static int signal_delay; static char *crash_signals; static List *signals = NIL; void _PG_init(void) { BackgroundWorker worker; DefineCustomIntVariable( "crash.delay", "Sleep time (in seconds) of the crash worker.", "Sleep this many seconds before sending the next signal.", &signal_delay, 1, 1, INT_MAX, PGC_POSTMASTER, GUC_UNIT_S, NULL, NULL, NULL); DefineCustomStringVariable( "crash.signals", "A list of signals to choose from.", "Random signal is chosen out of the ones contained in the set (space-separated).", &crash_signals, "15", PGC_POSTMASTER, 0, NULL, NULL, NULL); worker.bgw_flags = BGWORKER_SHMEM_ACCESS; worker.bgw_start_time = BgWorkerStart_RecoveryFinished; worker.bgw_restart_time = 0; sprintf(worker.bgw_type, "crash worker"); sprintf(worker.bgw_name, "crash worker"); sprintf(worker.bgw_library_name, "pg_crash"); sprintf(worker.bgw_function_name, "crash_worker_main"); worker.bgw_main_arg = (Datum) 0; worker.bgw_notify_pid = 0; RegisterBackgroundWorker(&worker); } static volatile sig_atomic_t got_sigterm = false; static void crash_worker_sigterm(SIGNAL_ARGS) { int save_errno = errno; got_sigterm = true; SetLatch(MyLatch); errno = save_errno; } void crash_worker_main(Datum main_arg) { uint32 nprocs = MaxBackends + NUM_AUXILIARY_PROCS + max_prepared_xacts; PGPROC *procs = ProcGlobal->allProcs; pqsignal(SIGTERM, crash_worker_sigterm); BackgroundWorkerUnblockSignals(); if (signals == NIL) { char *c, *start = NULL; /* Parse the list of signals. */ c = crash_signals; while (true) { /* Looking for the next value? */ if (isspace(*c) && start == NULL) { c++; /* Done? */ if (*c == '\0') break; continue; } if (start == NULL) { start = c++; continue; } else if (isspace(*c) || *c == '\0') { Size len = c - start; char *str = pnstrdup(start, len); long int nr; errno = 0; nr = strtol(str, NULL, 10); if (errno != 0) ereport(ERROR, (errmsg("\"%s\" is not a valid integer value", str))); pfree(str); signals = lappend_int(signals, nr); if (*c == '\0') break; start = NULL; } c++; } if (list_length(signals) == 0) ereport(ERROR, (errmsg("no signals specified"))); } ereport(LOG, (errmsg("pg_crash background worker started, crash.delay = %d, crash.signals = '%s'", signal_delay, crash_signals))); for (;;) { long int n; int i, j; int rc; int signal; /* wait for signal_delay seconds */ ResetLatch(MyLatch); rc = WaitLatch(MyLatch, WL_LATCH_SET | WL_POSTMASTER_DEATH | WL_TIMEOUT, signal_delay * 1000L, 0); if (rc & WL_POSTMASTER_DEATH) break; if (got_sigterm) break; /* Select signal. */ n = rand() % list_length(signals); signal = list_nth_int(signals, n); /* Select backend. */ n = rand() % nprocs; j = 0; for (i = 0;; i++) { PGPROC *proc = &procs[i % nprocs]; /* * Do not send signals to the bgworker, otherwise it won't be * restarted after a crash. */ if (proc->pid > 0 && proc->pid != MyProcPid) { if (j == n) { /* Send the signal. */ ereport(DEBUG1, (errmsg("sending signal %d to process %d", signal, proc->pid))); kill(proc->pid, signal); break; } j++; } } } } pg_crash-0.3/pg_crash.spec000066400000000000000000000035171502303571700156150ustar00rootroot00000000000000%global sname pg_crash %{!?llvm:%global llvm 1} Summary: Periodically crash your PostgreSQL database Name: %{sname}_%{pgmajorversion} Version: 0.3 Release: 1PGDG%{?dist} License: PostgreSQL Source0: https://github.com/cybertec-postgresql/%{sname}/archive/refs/tags/v%{version}.tar.gz URL: https://github.com/cybertec-postgresql/%{sname} BuildRequires: postgresql%{pgmajorversion}-devel Requires: postgresql%{pgmajorversion}-server %description If your database is too reliable - pg_crash can kill it for you. pg_crash is an extension to PostgreSQL that periodically crashes your database infrastructure by sending kill (or other) signals to your DB processes and make them fail. It is ideal for HA and failover testing. %if %llvm %package llvmjit Summary: Just-in-time compilation support for pg_crash Requires: %{name}%{?_isa} = %{version}-%{release} %if 0%{?suse_version} >= 1500 BuildRequires: llvm17-devel clang17-devel Requires: llvm17 %endif %if 0%{?fedora} || 0%{?rhel} >= 8 BuildRequires: llvm-devel >= 17.0 clang-devel >= 17.0 Requires: llvm => 17.0 %endif %description llvmjit This package provides JIT support for pg_crash %endif %prep %setup -q -n %{sname}-%{version} %build USE_PGXS=1 PATH=%{pginstdir}/bin/:$PATH %{__make} %{?_smp_mflags} %install %{__rm} -rf %{buildroot} USE_PGXS=1 PATH=%{pginstdir}/bin/:$PATH %{__make} %{?_smp_mflags} install DESTDIR=%{buildroot} %{__mkdir} -p %{buildroot}%{pginstdir}/doc/extension/ %{__cp} README.md %{buildroot}%{pginstdir}/doc/extension/README-%{sname}.md %files %license LICENSE %doc %{pginstdir}/doc/extension/README-%{sname}.md %defattr(644,root,root,755) %{pginstdir}/lib/%{sname}.so %if %llvm %files llvmjit %{pginstdir}/lib/bitcode/%{sname}*.bc %{pginstdir}/lib/bitcode/%{sname}/*.bc %endif %changelog * Fri Jun 13 2025 Christoph Berg - 0.2-1PGDG - Initial RPM packaging