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

Commitea80138

Browse files
committed
Fix psql's \connect command some more.
Jasen Betts reported yet another unintended side effect of commit85c5428: reconnecting with "\c service=whatever" did not have theexpected results. The reason is that starting from the output ofPQconndefaults() effectively allows environment variables (suchas PGPORT) to override entries in the service file, whereas thenormal priority is the other way around.Not using PQconndefaults at all would require yet a third main codepath in do_connect's parameter setup, so I don't really want to fixit that way. But we can have the logic effectively ignore all thedefault values for just a couple more lines of code.This patch doesn't change the behavior for "\c -reuse-previous=onservice=whatever". That remains significantly different from before85c5428, because many more parameters will be re-used, and thusnot be possible for service entries to replace. But I think thisis (mostly?) intentional. In any case, since libpq does not reportwhere it got parameter values from, it's hard to do differently.Per bug #16936 from Jasen Betts. As with the previous patches,back-patch to all supported branches. (9.5 is unfortunately nowout of support, so this won't get fixed there.)Discussion:https://postgr.es/m/16936-3f524322a53a29f0@postgresql.org
1 parent9d52311 commitea80138

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

‎src/bin/psql/command.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3132,6 +3132,25 @@ do_connect(enum trivalue reuse_previous_specification,
31323132
if (strcmp(replci->keyword,"password")==0)
31333133
have_password= true;
31343134
}
3135+
elseif (!reuse_previous)
3136+
{
3137+
/*
3138+
* When we have a connstring and are not re-using
3139+
* parameters, swap *all* entries, even those not set
3140+
* by the connstring. This avoids absorbing
3141+
* environment-dependent defaults from the result of
3142+
* PQconndefaults(). We don't want to do that because
3143+
* they'd override service-file entries if the
3144+
* connstring specifies a service parameter, whereas
3145+
* the priority should be the other way around. libpq
3146+
* can certainly recompute any defaults we don't pass
3147+
* here. (In this situation, it's a bit wasteful to
3148+
* have called PQconndefaults() at all, but not doing
3149+
* so would require yet another major code path here.)
3150+
*/
3151+
replci->val=ci->val;
3152+
ci->val=NULL;
3153+
}
31353154
}
31363155
Assert(ci->keyword==NULL&&replci->keyword==NULL);
31373156

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp