Skip to content

Commit e19a051

Browse files
committed
Fix MDB-signal process and add TAP test for feature
1 parent b01d0e2 commit e19a051

2 files changed

Lines changed: 78 additions & 1 deletion

File tree

src/backend/storage/ipc/signalfuncs.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,10 @@ pg_signal_backend(int pid, int sig)
9393
*/
9494

9595
/* We allow to kill queries issued with MDB prefix */
96-
if (!superuser() && !OidIsValid(proc->roleId))
96+
if (!superuser() && OidIsValid(proc->roleId))
9797
{
98+
/* Ok, we are not superuser, and we try to kill
99+
* some backend, which can may be a MDB-cancellable query*/
98100
LocalPgBackendStatus *local_beentry;
99101
char * appname = NULL;
100102
local_beentry = pgstat_get_local_beentry_by_proc_number(GetNumberFromPGProc(proc));
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
2+
# Copyright (c) 2024-2024, MDB, Mother Russia
3+
4+
# Minimal test testing streaming replication
5+
use strict;
6+
use warnings;
7+
use PostgreSQL::Test::Cluster;
8+
use PostgreSQL::Test::Utils;
9+
use Test::More;
10+
11+
# Initialize primary node
12+
my $node_primary = PostgreSQL::Test::Cluster->new('primary');
13+
$node_primary->init();
14+
$node_primary->start;
15+
16+
# Create some content on primary and check its presence in standby nodes
17+
$node_primary->safe_psql('postgres',
18+
"
19+
CREATE DATABASE regress;
20+
CREATE ROLE mdb_reg_lh_app_name;
21+
GRANT pg_signal_backend to mdb_reg_lh_app_name;
22+
CREATE TABLE mdb_app_name_t(i int);
23+
");
24+
25+
my $main_sess = $node_primary->background_psql('postgres');
26+
27+
$main_sess->query_safe(
28+
q(
29+
SET application_name TO 'SU';
30+
BEGIN;
31+
INSERT INTO mdb_app_name_t VALUES(0);
32+
));
33+
34+
35+
my $res_pid = $node_primary->safe_psql('regress',
36+
"
37+
SELECT pid FROM pg_stat_activity WHERE application_name = 'SU';
38+
");
39+
40+
print "pid is $res_pid\n";
41+
42+
ok(1);
43+
44+
45+
my ($res_reg_lh_1, $stdout_reg_lh_1, $stderr_reg_lh_1) = $node_primary->psql('regress',
46+
"
47+
SET ROLE mdb_reg_lh_app_name;
48+
SELECT pg_terminate_backend($res_pid);
49+
");
50+
51+
# print ($res_reg_lh_1, $stdout_reg_lh_1, $stderr_reg_lh_1, "\n");
52+
53+
ok($res_reg_lh_1 != 0, "should fail for non-MDB");
54+
like($stderr_reg_lh_1, qr/Only roles with the SUPERUSER attribute may terminate processes of roles with the SUPERUSER attribute./, "matches");
55+
56+
# should succeed
57+
$main_sess->query_safe(qq[COMMIT]);
58+
59+
$main_sess->query_safe(
60+
q(
61+
SET application_name TO 'MDB';
62+
BEGIN;
63+
INSERT INTO mdb_app_name_t VALUES(1);
64+
));
65+
66+
67+
my ($res_reg_lh_2, $stdout_reg_lh_2, $stderr_reg_lh_2) = $node_primary->psql('regress',
68+
"
69+
SET ROLE mdb_reg_lh_app_name;
70+
SELECT pg_terminate_backend($res_pid);
71+
");
72+
73+
ok($res_reg_lh_2 == 0, "should success for MDB");
74+
75+
done_testing();

0 commit comments

Comments
 (0)