Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfa2e874

Browse files
committed
Recalculate search_path after ALTER ROLE.
Renaming a role can affect the meaning of the special string $user, somust cause search_path to be recalculated.Discussion:https://postgr.es/m/186761d32c0255debbdf50b6310b581b9c973e6c.camel@j-davis.comReviewed-by: Nathan Bossart, Michael PaquierBackpatch-through: 11
1 parentc27f862 commitfa2e874

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+
CREATEUSERregress_sp_user1;
6+
CREATESCHEMAregress_sp_user1AUTHORIZATIONregress_sp_user1;
7+
CREATESCHEMAregress_sp_public;
8+
GRANTALLPRIVILEGESONSCHEMAregress_sp_publicTOregress_sp_user1;
9+
}
10+
11+
teardown
12+
{
13+
DROPSCHEMAregress_sp_publicCASCADE;
14+
DROPSCHEMAregress_sp_user1CASCADE;
15+
DROPUSERregress_sp_user1;
16+
}
17+
18+
sessions1
19+
setup
20+
{
21+
SETsearch_path="$user",regress_sp_public;
22+
SETSESSIONAUTHORIZATIONregress_sp_user1;
23+
CREATETABLEregress_sp_user1.x(t)ASSELECT'data in regress_sp_user1.x';
24+
CREATETABLEregress_sp_public.x(t)ASSELECT'data in regress_sp_public.x';
25+
}
26+
steps1a
27+
{
28+
SELECTCURRENT_USER;
29+
SHOWsearch_path;
30+
SELECTtFROMx;
31+
}
32+
33+
sessions2
34+
steps2a
35+
{
36+
ALTERROLEregress_sp_user1RENAMETOregress_sp_user2;
37+
}
38+
steps2b
39+
{
40+
ALTERROLEregress_sp_user2RENAMETOregress_sp_user1;
41+
}
42+
43+
sessions3
44+
steps3a
45+
{
46+
ALTERSCHEMAregress_sp_user1RENAMETOregress_sp_user2;
47+
}
48+
steps3b
49+
{
50+
ALTERSCHEMAregress_sp_user2RENAMETOregress_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+
permutations1as2as1as2b
56+
57+
# s1's search_path is invalidated by schema name change in s2b, and
58+
# falls back to regress_sp_public.x
59+
permutations1as3as1as3b

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp