forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit85c5428
committed
Fix connection string handling in psql's \connect command.
psql's \connect claims to be able to re-use previous connectionparameters, but in fact it only re-uses the database name, user name,host name (and possibly hostaddr, depending on version), and port.This is problematic for assorted use cases. Notably, pg_dump[all]emits "\connect databasename" commands which we would like to havere-use all other parameters. If such a script is loaded in a psql runthat initially had "-d connstring" with some non-default parameters,those other parameters would be lost, potentially causing connectionfailure. (Thus, this is the same kind of bug addressed in commitsa45bc8a and8e5793a, although the details are much different.)To fix, redesign do_connect() so that it pulls out all propertiesof the old PGconn using PQconninfo(), and then replaces individualproperties in that array. In the case where we don't wish to re-useanything, get libpq's default settings using PQconndefaults() andreplace entries in that, so that we don't need different code pathsfor the two cases.This does result in an additional behavioral change for cases wherethe original connection parameters allowed multiple hosts, say"psql -h host1,host2", and the \connect request allows re-use of thehost setting. Because the previous coding relied on PQhost(), itwould only permit reconnection to the same host originally selected.Although one can think of scenarios where that's a good thing, thereare others where it is not. Moreover, that behavior doesn't seem tomeet the principle of least surprise, nor was it documented; nor isit even clear it was intended, since that coding long pre-dates theaddition of multi-host support to libpq. Hence, this patch is contentto drop it and re-use the host list as given.Per Peter Eisentraut's comments on bug #16604. Back-patch to allsupported branches.Discussion:https://postgr.es/m/16604-933f4b8791227b15@postgresql.org1 parent831611b commit85c5428
2 files changed
+217
-126
lines changedLines changed: 29 additions & 16 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
889 | 889 |
| |
890 | 890 |
| |
891 | 891 |
| |
892 |
| - | |
893 |
| - | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
894 | 897 |
| |
895 | 898 |
| |
896 | 899 |
| |
897 |
| - | |
898 |
| - | |
899 |
| - | |
900 |
| - | |
901 |
| - | |
902 |
| - | |
903 |
| - | |
904 |
| - | |
| 900 | + | |
905 | 901 |
| |
906 | 902 |
| |
907 | 903 |
| |
908 | 904 |
| |
909 | 905 |
| |
910 |
| - | |
911 |
| - | |
912 |
| - | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
913 | 925 |
| |
914 | 926 |
| |
915 | 927 |
| |
916 | 928 |
| |
917 | 929 |
| |
918 |
| - | |
919 |
| - | |
920 |
| - | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
921 | 933 |
| |
922 | 934 |
| |
923 | 935 |
| |
| |||
932 | 944 |
| |
933 | 945 |
| |
934 | 946 |
| |
| 947 | + | |
935 | 948 |
| |
936 | 949 |
| |
937 | 950 |
| |
|
0 commit comments
Comments
(0)