Skip to content

Commit fa2e874

Browse files
committed
Recalculate search_path after ALTER ROLE.
Renaming a role can affect the meaning of the special string $user, so must cause search_path to be recalculated. Discussion: https://postgr.es/m/186761d32c0255debbdf50b6310b581b9c973e6c.camel@j-davis.com Reviewed-by: Nathan Bossart, Michael Paquier Backpatch-through: 11
1 parent c27f862 commit fa2e874

File tree

4 files changed

+162
-1
lines changed

4 files changed

+162
-1
lines changed

src/backend/catalog/namespace.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4175,11 +4175,15 @@ InitializeSearchPath(void)
41754175
{
41764176
/*
41774177
* In normal mode, arrange for a callback on any syscache invalidation
4178-
* of pg_namespace rows.
4178+
* of pg_namespace or pg_authid rows. (Changing a role name may affect
4179+
* the meaning of the special string $user.)
41794180
*/
41804181
CacheRegisterSyscacheCallback(NAMESPACEOID,
41814182
NamespaceCallback,
41824183
(Datum) 0);
4184+
CacheRegisterSyscacheCallback(AUTHOID,
4185+
NamespaceCallback,
4186+
(Datum) 0);
41834187
/* Force search path to be recomputed on next use */
41844188
baseSearchPathValid = false;
41854189
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
Parsed test spec with 3 sessions
2+
3+
starting permutation: s1a s2a s1a s2b
4+
step s1a:
5+
SELECT CURRENT_USER;
6+
SHOW search_path;
7+
SELECT t FROM x;
8+
9+
current_user
10+
----------------
11+
regress_sp_user1
12+
(1 row)
13+
14+
search_path
15+
--------------------------
16+
"$user", regress_sp_public
17+
(1 row)
18+
19+
t
20+
--------------------------
21+
data in regress_sp_user1.x
22+
(1 row)
23+
24+
step s2a:
25+
ALTER ROLE regress_sp_user1 RENAME TO regress_sp_user2;
26+
27+
step s1a:
28+
SELECT CURRENT_USER;
29+
SHOW search_path;
30+
SELECT t FROM x;
31+
32+
current_user
33+
----------------
34+
regress_sp_user2
35+
(1 row)
36+
37+
search_path
38+
--------------------------
39+
"$user", regress_sp_public
40+
(1 row)
41+
42+
t
43+
---------------------------
44+
data in regress_sp_public.x
45+
(1 row)
46+
47+
step s2b:
48+
ALTER ROLE regress_sp_user2 RENAME TO regress_sp_user1;
49+
50+
51+
starting permutation: s1a s3a s1a s3b
52+
step s1a:
53+
SELECT CURRENT_USER;
54+
SHOW search_path;
55+
SELECT t FROM x;
56+
57+
current_user
58+
----------------
59+
regress_sp_user1
60+
(1 row)
61+
62+
search_path
63+
--------------------------
64+
"$user", regress_sp_public
65+
(1 row)
66+
67+
t
68+
--------------------------
69+
data in regress_sp_user1.x
70+
(1 row)
71+
72+
step s3a:
73+
ALTER SCHEMA regress_sp_user1 RENAME TO regress_sp_user2;
74+
75+
step s1a:
76+
SELECT CURRENT_USER;
77+
SHOW search_path;
78+
SELECT t FROM x;
79+
80+
current_user
81+
----------------
82+
regress_sp_user1
83+
(1 row)
84+
85+
search_path
86+
--------------------------
87+
"$user", regress_sp_public
88+
(1 row)
89+
90+
t
91+
---------------------------
92+
data in regress_sp_public.x
93+
(1 row)
94+
95+
step s3b:
96+
ALTER SCHEMA regress_sp_user2 RENAME TO regress_sp_user1;
97+

src/test/isolation/isolation_schedule

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,4 @@ test: serializable-parallel
110110
test: serializable-parallel-2
111111
test: serializable-parallel-3
112112
test: matview-write-skew
113+
test: search-path-inval
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Test search_path invalidation.
2+
3+
setup
4+
{
5+
CREATE USER regress_sp_user1;
6+
CREATE SCHEMA regress_sp_user1 AUTHORIZATION regress_sp_user1;
7+
CREATE SCHEMA regress_sp_public;
8+
GRANT ALL PRIVILEGES ON SCHEMA regress_sp_public TO regress_sp_user1;
9+
}
10+
11+
teardown
12+
{
13+
DROP SCHEMA regress_sp_public CASCADE;
14+
DROP SCHEMA regress_sp_user1 CASCADE;
15+
DROP USER regress_sp_user1;
16+
}
17+
18+
session s1
19+
setup
20+
{
21+
SET search_path = "$user", regress_sp_public;
22+
SET SESSION AUTHORIZATION regress_sp_user1;
23+
CREATE TABLE regress_sp_user1.x(t) AS SELECT 'data in regress_sp_user1.x';
24+
CREATE TABLE regress_sp_public.x(t) AS SELECT 'data in regress_sp_public.x';
25+
}
26+
step s1a
27+
{
28+
SELECT CURRENT_USER;
29+
SHOW search_path;
30+
SELECT t FROM x;
31+
}
32+
33+
session s2
34+
step s2a
35+
{
36+
ALTER ROLE regress_sp_user1 RENAME TO regress_sp_user2;
37+
}
38+
step s2b
39+
{
40+
ALTER ROLE regress_sp_user2 RENAME TO regress_sp_user1;
41+
}
42+
43+
session s3
44+
step s3a
45+
{
46+
ALTER SCHEMA regress_sp_user1 RENAME TO regress_sp_user2;
47+
}
48+
step s3b
49+
{
50+
ALTER SCHEMA regress_sp_user2 RENAME TO regress_sp_user1;
51+
}
52+
53+
# s1's search_path is invalidated by role name change in s2a, and
54+
# falls back to regress_sp_public.x
55+
permutation s1a s2a s1a s2b
56+
57+
# s1's search_path is invalidated by schema name change in s2b, and
58+
# falls back to regress_sp_public.x
59+
permutation s1a s3a s1a s3b

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy