function for testing that causes the backend to terminate

Started by Dave Cramerover 4 years ago6 messages
#1Dave Cramer
davecramer@gmail.com

For testing unusual situations I'd like to be able to cause a backend to
terminate due to something like a segfault. Do we currently have this in
testing ?

Dave Cramer

#2Bharath Rupireddy
bharath.rupireddyforpostgres@gmail.com
In reply to: Dave Cramer (#1)
Re: function for testing that causes the backend to terminate

On Thu, Apr 29, 2021 at 4:27 PM Dave Cramer <davecramer@gmail.com> wrote:

For testing unusual situations I'd like to be able to cause a backend to terminate due to something like a segfault. Do we currently have this in testing ?

Well, you could use pg_terminate_backend which sends SIGTERM to the
backend. However, we don't have a function that sends SIGSEGV yet, you
could signal the backend with SIGSEGV directly, if possible.

With Regards,
Bharath Rupireddy.
EnterpriseDB: http://www.enterprisedb.com

#3Joe Conway
mail@joeconway.com
In reply to: Dave Cramer (#1)
Re: function for testing that causes the backend to terminate

On 4/29/21 6:56 AM, Dave Cramer wrote:

For testing unusual situations I'd like to be able to cause a backend to
terminate due to something like a segfault. Do we currently have this in
testing ?

If you can run SQL as a superuser from that backend, try:

COPY (SELECT pg_backend_pid())
TO PROGRAM 'xargs kill -SIGSEGV';

HTH,

Joe

--
Crunchy Data - http://crunchydata.com
PostgreSQL Support for Secure Enterprises
Consulting, Training, & Open Source Development

#4Bharath Rupireddy
bharath.rupireddyforpostgres@gmail.com
In reply to: Bharath Rupireddy (#2)
Re: function for testing that causes the backend to terminate

On Thu, Apr 29, 2021 at 4:36 PM Bharath Rupireddy
<bharath.rupireddyforpostgres@gmail.com> wrote:

On Thu, Apr 29, 2021 at 4:27 PM Dave Cramer <davecramer@gmail.com> wrote:

For testing unusual situations I'd like to be able to cause a backend to terminate due to something like a segfault. Do we currently have this in testing ?

Well, you could use pg_terminate_backend which sends SIGTERM to the
backend. However, we don't have a function that sends SIGSEGV yet, you
could signal the backend with SIGSEGV directly, if possible.

And, I came across an extension called pg_crash [1]https://www.cybertec-postgresql.com/en/pg_crash-crashing-postgresql-automatically/, see if that helps.

[1]: https://www.cybertec-postgresql.com/en/pg_crash-crashing-postgresql-automatically/

With Regards,
Bharath Rupireddy.
EnterpriseDB: http://www.enterprisedb.com

#5Andrew Dunstan
andrew@dunslane.net
In reply to: Joe Conway (#3)
Re: function for testing that causes the backend to terminate

On 4/29/21 4:16 PM, Joe Conway wrote:

On 4/29/21 6:56 AM, Dave Cramer wrote:

For testing unusual situations I'd like to be able to cause a backend
to terminate due to something like a segfault. Do we currently have
this in testing ?

If you can run SQL as a superuser from that backend, try:

COPY (SELECT pg_backend_pid())
 TO PROGRAM 'xargs kill -SIGSEGV';

HTH,

Joe

or a plperlu function that does 'kill 11, $$;' should do it.

cheers

andrew

--
Andrew Dunstan
EDB: https://www.enterprisedb.com

#6Dave Cramer
davecramer@gmail.com
In reply to: Joe Conway (#3)
Re: function for testing that causes the backend to terminate

Joe,

Thanks,

This works and I don't have to install anything!

Dave Cramer

On Thu, 29 Apr 2021 at 16:16, Joe Conway <mail@joeconway.com> wrote:

Show quoted text

On 4/29/21 6:56 AM, Dave Cramer wrote:

For testing unusual situations I'd like to be able to cause a backend to
terminate due to something like a segfault. Do we currently have this in
testing ?

If you can run SQL as a superuser from that backend, try:

COPY (SELECT pg_backend_pid())
TO PROGRAM 'xargs kill -SIGSEGV';

HTH,

Joe

--
Crunchy Data - http://crunchydata.com
PostgreSQL Support for Secure Enterprises
Consulting, Training, & Open Source Development