pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: Fix connection string handling in src/bin/scripts/ programs. 14+ messages / 1 participants [nested] [flat]
* pgsql: Fix connection string handling in src/bin/scripts/ programs. @ 2020-10-19 23:04 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 14+ messages in thread From: Tom Lane @ 2020-10-19 23:04 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix connection string handling in src/bin/scripts/ programs. When told to process all databases, clusterdb, reindexdb, and vacuumdb would reconnect by replacing their --maintenance-db parameter with the name of the target database. If that parameter is a connstring (which has been allowed for a long time, though we failed to document that before this patch), we'd lose any other options it might specify, for example SSL or GSS parameters, possibly resulting in failure to connect. Thus, this is the same bug as commit a45bc8a4f fixed in pg_dump and pg_restore. We can fix it in the same way, by using libpq's rules for handling multiple "dbname" parameters to add the target database name separately. I chose to apply the same refactoring approach as in that patch, with a struct to handle the command line parameters that need to be passed through to connectDatabase. (Maybe someday we can unify the very similar functions here and in pg_dump/pg_restore.) Per Peter Eisentraut's comments on bug #16604. Back-patch to all supported branches. Discussion: https://postgr.es/m/16604-933f4b8791227b15@postgresql.org Branch ------ REL9_5_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/da129a04a6dea8c30eec2477c08d17736c92d431 Modified Files -------------- doc/src/sgml/ref/clusterdb.sgml | 20 +++++---- doc/src/sgml/ref/createdb.sgml | 3 ++ doc/src/sgml/ref/dropdb.sgml | 3 ++ doc/src/sgml/ref/reindexdb.sgml | 20 +++++---- doc/src/sgml/ref/vacuumdb.sgml | 20 +++++---- src/bin/scripts/clusterdb.c | 67 ++++++++++++++----------------- src/bin/scripts/common.c | 89 ++++++++++++++++++++++++----------------- src/bin/scripts/common.h | 26 ++++++++---- src/bin/scripts/createdb.c | 11 ++++- src/bin/scripts/createlang.c | 12 +++++- src/bin/scripts/createuser.c | 11 ++++- src/bin/scripts/dropdb.c | 12 ++++-- src/bin/scripts/droplang.c | 12 +++++- src/bin/scripts/dropuser.c | 13 ++++-- src/bin/scripts/reindexdb.c | 85 +++++++++++++++++++-------------------- src/bin/scripts/vacuumdb.c | 70 ++++++++++++++------------------ 16 files changed, 274 insertions(+), 200 deletions(-) ^ permalink raw reply [nested|flat] 14+ messages in thread
* pgsql: Fix connection string handling in src/bin/scripts/ programs. @ 2020-10-19 23:04 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 14+ messages in thread From: Tom Lane @ 2020-10-19 23:04 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix connection string handling in src/bin/scripts/ programs. When told to process all databases, clusterdb, reindexdb, and vacuumdb would reconnect by replacing their --maintenance-db parameter with the name of the target database. If that parameter is a connstring (which has been allowed for a long time, though we failed to document that before this patch), we'd lose any other options it might specify, for example SSL or GSS parameters, possibly resulting in failure to connect. Thus, this is the same bug as commit a45bc8a4f fixed in pg_dump and pg_restore. We can fix it in the same way, by using libpq's rules for handling multiple "dbname" parameters to add the target database name separately. I chose to apply the same refactoring approach as in that patch, with a struct to handle the command line parameters that need to be passed through to connectDatabase. (Maybe someday we can unify the very similar functions here and in pg_dump/pg_restore.) Per Peter Eisentraut's comments on bug #16604. Back-patch to all supported branches. Discussion: https://postgr.es/m/16604-933f4b8791227b15@postgresql.org Branch ------ REL_13_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/1814f915b526d5022b3e2a6ce4ea3bcbe59abe2c Modified Files -------------- doc/src/sgml/ref/clusterdb.sgml | 20 ++++++--- doc/src/sgml/ref/createdb.sgml | 3 ++ doc/src/sgml/ref/dropdb.sgml | 3 ++ doc/src/sgml/ref/reindexdb.sgml | 20 ++++++--- doc/src/sgml/ref/vacuumdb.sgml | 20 ++++++--- src/bin/scripts/clusterdb.c | 67 +++++++++++++--------------- src/bin/scripts/common.c | 89 +++++++++++++++++++++++--------------- src/bin/scripts/common.h | 26 ++++++++--- src/bin/scripts/createdb.c | 11 ++++- src/bin/scripts/createuser.c | 11 ++++- src/bin/scripts/dropdb.c | 12 +++-- src/bin/scripts/dropuser.c | 13 ++++-- src/bin/scripts/reindexdb.c | 89 ++++++++++++++++++-------------------- src/bin/scripts/scripts_parallel.c | 6 +-- src/bin/scripts/scripts_parallel.h | 6 +-- src/bin/scripts/vacuumdb.c | 70 +++++++++++++----------------- 16 files changed, 260 insertions(+), 206 deletions(-) ^ permalink raw reply [nested|flat] 14+ messages in thread
* pgsql: Fix connection string handling in src/bin/scripts/ programs. @ 2020-10-19 23:04 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 14+ messages in thread From: Tom Lane @ 2020-10-19 23:04 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix connection string handling in src/bin/scripts/ programs. When told to process all databases, clusterdb, reindexdb, and vacuumdb would reconnect by replacing their --maintenance-db parameter with the name of the target database. If that parameter is a connstring (which has been allowed for a long time, though we failed to document that before this patch), we'd lose any other options it might specify, for example SSL or GSS parameters, possibly resulting in failure to connect. Thus, this is the same bug as commit a45bc8a4f fixed in pg_dump and pg_restore. We can fix it in the same way, by using libpq's rules for handling multiple "dbname" parameters to add the target database name separately. I chose to apply the same refactoring approach as in that patch, with a struct to handle the command line parameters that need to be passed through to connectDatabase. (Maybe someday we can unify the very similar functions here and in pg_dump/pg_restore.) Per Peter Eisentraut's comments on bug #16604. Back-patch to all supported branches. Discussion: https://postgr.es/m/16604-933f4b8791227b15@postgresql.org Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/8e5793ab60bba65ffaa0f2237b39c9580d8972c7 Modified Files -------------- doc/src/sgml/ref/clusterdb.sgml | 20 ++++++--- doc/src/sgml/ref/createdb.sgml | 3 ++ doc/src/sgml/ref/dropdb.sgml | 3 ++ doc/src/sgml/ref/reindexdb.sgml | 20 ++++++--- doc/src/sgml/ref/vacuumdb.sgml | 20 ++++++--- src/bin/scripts/clusterdb.c | 67 +++++++++++++--------------- src/bin/scripts/common.c | 89 +++++++++++++++++++++++--------------- src/bin/scripts/common.h | 26 ++++++++--- src/bin/scripts/createdb.c | 11 ++++- src/bin/scripts/createuser.c | 11 ++++- src/bin/scripts/dropdb.c | 12 +++-- src/bin/scripts/dropuser.c | 13 ++++-- src/bin/scripts/reindexdb.c | 89 ++++++++++++++++++-------------------- src/bin/scripts/scripts_parallel.c | 6 +-- src/bin/scripts/scripts_parallel.h | 6 +-- src/bin/scripts/vacuumdb.c | 70 +++++++++++++----------------- 16 files changed, 260 insertions(+), 206 deletions(-) ^ permalink raw reply [nested|flat] 14+ messages in thread
* pgsql: Fix connection string handling in src/bin/scripts/ programs. @ 2020-10-19 23:04 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 14+ messages in thread From: Tom Lane @ 2020-10-19 23:04 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix connection string handling in src/bin/scripts/ programs. When told to process all databases, clusterdb, reindexdb, and vacuumdb would reconnect by replacing their --maintenance-db parameter with the name of the target database. If that parameter is a connstring (which has been allowed for a long time, though we failed to document that before this patch), we'd lose any other options it might specify, for example SSL or GSS parameters, possibly resulting in failure to connect. Thus, this is the same bug as commit a45bc8a4f fixed in pg_dump and pg_restore. We can fix it in the same way, by using libpq's rules for handling multiple "dbname" parameters to add the target database name separately. I chose to apply the same refactoring approach as in that patch, with a struct to handle the command line parameters that need to be passed through to connectDatabase. (Maybe someday we can unify the very similar functions here and in pg_dump/pg_restore.) Per Peter Eisentraut's comments on bug #16604. Back-patch to all supported branches. Discussion: https://postgr.es/m/16604-933f4b8791227b15@postgresql.org Branch ------ REL_12_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/c6d0b9b1668cde5f13e632bad813bd9d666caf9b Modified Files -------------- doc/src/sgml/ref/clusterdb.sgml | 20 +++++---- doc/src/sgml/ref/createdb.sgml | 3 ++ doc/src/sgml/ref/dropdb.sgml | 3 ++ doc/src/sgml/ref/reindexdb.sgml | 20 +++++---- doc/src/sgml/ref/vacuumdb.sgml | 20 +++++---- src/bin/scripts/clusterdb.c | 67 ++++++++++++++----------------- src/bin/scripts/common.c | 89 ++++++++++++++++++++++++----------------- src/bin/scripts/common.h | 26 ++++++++---- src/bin/scripts/createdb.c | 11 ++++- src/bin/scripts/createuser.c | 11 ++++- src/bin/scripts/dropdb.c | 12 ++++-- src/bin/scripts/dropuser.c | 13 ++++-- src/bin/scripts/reindexdb.c | 85 +++++++++++++++++++-------------------- src/bin/scripts/vacuumdb.c | 70 ++++++++++++++------------------ 14 files changed, 254 insertions(+), 196 deletions(-) ^ permalink raw reply [nested|flat] 14+ messages in thread
* pgsql: Fix connection string handling in src/bin/scripts/ programs. @ 2020-10-19 23:04 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 14+ messages in thread From: Tom Lane @ 2020-10-19 23:04 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix connection string handling in src/bin/scripts/ programs. When told to process all databases, clusterdb, reindexdb, and vacuumdb would reconnect by replacing their --maintenance-db parameter with the name of the target database. If that parameter is a connstring (which has been allowed for a long time, though we failed to document that before this patch), we'd lose any other options it might specify, for example SSL or GSS parameters, possibly resulting in failure to connect. Thus, this is the same bug as commit a45bc8a4f fixed in pg_dump and pg_restore. We can fix it in the same way, by using libpq's rules for handling multiple "dbname" parameters to add the target database name separately. I chose to apply the same refactoring approach as in that patch, with a struct to handle the command line parameters that need to be passed through to connectDatabase. (Maybe someday we can unify the very similar functions here and in pg_dump/pg_restore.) Per Peter Eisentraut's comments on bug #16604. Back-patch to all supported branches. Discussion: https://postgr.es/m/16604-933f4b8791227b15@postgresql.org Branch ------ REL9_6_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/5c78f797701b90546279b994791fc07af5bbb5c9 Modified Files -------------- doc/src/sgml/ref/clusterdb.sgml | 20 +++++---- doc/src/sgml/ref/createdb.sgml | 3 ++ doc/src/sgml/ref/dropdb.sgml | 3 ++ doc/src/sgml/ref/reindexdb.sgml | 20 +++++---- doc/src/sgml/ref/vacuumdb.sgml | 20 +++++---- src/bin/scripts/clusterdb.c | 67 ++++++++++++++----------------- src/bin/scripts/common.c | 89 ++++++++++++++++++++++++----------------- src/bin/scripts/common.h | 26 ++++++++---- src/bin/scripts/createdb.c | 11 ++++- src/bin/scripts/createlang.c | 12 +++++- src/bin/scripts/createuser.c | 11 ++++- src/bin/scripts/dropdb.c | 12 ++++-- src/bin/scripts/droplang.c | 12 +++++- src/bin/scripts/dropuser.c | 13 ++++-- src/bin/scripts/reindexdb.c | 85 +++++++++++++++++++-------------------- src/bin/scripts/vacuumdb.c | 70 ++++++++++++++------------------ 16 files changed, 274 insertions(+), 200 deletions(-) ^ permalink raw reply [nested|flat] 14+ messages in thread
* pgsql: Fix connection string handling in src/bin/scripts/ programs. @ 2020-10-19 23:04 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 14+ messages in thread From: Tom Lane @ 2020-10-19 23:04 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix connection string handling in src/bin/scripts/ programs. When told to process all databases, clusterdb, reindexdb, and vacuumdb would reconnect by replacing their --maintenance-db parameter with the name of the target database. If that parameter is a connstring (which has been allowed for a long time, though we failed to document that before this patch), we'd lose any other options it might specify, for example SSL or GSS parameters, possibly resulting in failure to connect. Thus, this is the same bug as commit a45bc8a4f fixed in pg_dump and pg_restore. We can fix it in the same way, by using libpq's rules for handling multiple "dbname" parameters to add the target database name separately. I chose to apply the same refactoring approach as in that patch, with a struct to handle the command line parameters that need to be passed through to connectDatabase. (Maybe someday we can unify the very similar functions here and in pg_dump/pg_restore.) Per Peter Eisentraut's comments on bug #16604. Back-patch to all supported branches. Discussion: https://postgr.es/m/16604-933f4b8791227b15@postgresql.org Branch ------ REL_10_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/68f2369930f923df79fef4c62843a40baa1facec Modified Files -------------- doc/src/sgml/ref/clusterdb.sgml | 20 +++++---- doc/src/sgml/ref/createdb.sgml | 3 ++ doc/src/sgml/ref/dropdb.sgml | 3 ++ doc/src/sgml/ref/reindexdb.sgml | 20 +++++---- doc/src/sgml/ref/vacuumdb.sgml | 20 +++++---- src/bin/scripts/clusterdb.c | 67 ++++++++++++++----------------- src/bin/scripts/common.c | 89 ++++++++++++++++++++++++----------------- src/bin/scripts/common.h | 26 ++++++++---- src/bin/scripts/createdb.c | 11 ++++- src/bin/scripts/createuser.c | 11 ++++- src/bin/scripts/dropdb.c | 12 ++++-- src/bin/scripts/dropuser.c | 13 ++++-- src/bin/scripts/reindexdb.c | 85 +++++++++++++++++++-------------------- src/bin/scripts/vacuumdb.c | 70 ++++++++++++++------------------ 14 files changed, 254 insertions(+), 196 deletions(-) ^ permalink raw reply [nested|flat] 14+ messages in thread
* pgsql: Fix connection string handling in src/bin/scripts/ programs. @ 2020-10-19 23:04 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 14+ messages in thread From: Tom Lane @ 2020-10-19 23:04 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix connection string handling in src/bin/scripts/ programs. When told to process all databases, clusterdb, reindexdb, and vacuumdb would reconnect by replacing their --maintenance-db parameter with the name of the target database. If that parameter is a connstring (which has been allowed for a long time, though we failed to document that before this patch), we'd lose any other options it might specify, for example SSL or GSS parameters, possibly resulting in failure to connect. Thus, this is the same bug as commit a45bc8a4f fixed in pg_dump and pg_restore. We can fix it in the same way, by using libpq's rules for handling multiple "dbname" parameters to add the target database name separately. I chose to apply the same refactoring approach as in that patch, with a struct to handle the command line parameters that need to be passed through to connectDatabase. (Maybe someday we can unify the very similar functions here and in pg_dump/pg_restore.) Per Peter Eisentraut's comments on bug #16604. Back-patch to all supported branches. Discussion: https://postgr.es/m/16604-933f4b8791227b15@postgresql.org Branch ------ REL_11_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/5a9f99bed8cbd4a2aafaedbf464eedf9ae9e73a8 Modified Files -------------- doc/src/sgml/ref/clusterdb.sgml | 20 +++++---- doc/src/sgml/ref/createdb.sgml | 3 ++ doc/src/sgml/ref/dropdb.sgml | 3 ++ doc/src/sgml/ref/reindexdb.sgml | 20 +++++---- doc/src/sgml/ref/vacuumdb.sgml | 20 +++++---- src/bin/scripts/clusterdb.c | 67 ++++++++++++++----------------- src/bin/scripts/common.c | 89 ++++++++++++++++++++++++----------------- src/bin/scripts/common.h | 26 ++++++++---- src/bin/scripts/createdb.c | 11 ++++- src/bin/scripts/createuser.c | 11 ++++- src/bin/scripts/dropdb.c | 12 ++++-- src/bin/scripts/dropuser.c | 13 ++++-- src/bin/scripts/reindexdb.c | 85 +++++++++++++++++++-------------------- src/bin/scripts/vacuumdb.c | 70 ++++++++++++++------------------ 14 files changed, 254 insertions(+), 196 deletions(-) ^ permalink raw reply [nested|flat] 14+ messages in thread
* pgsql: Fix connection string handling in psql's \connect command. @ 2020-10-21 20:19 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 14+ messages in thread From: Tom Lane @ 2020-10-21 20:19 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix connection string handling in psql's \connect command. psql's \connect claims to be able to re-use previous connection parameters, 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 have re-use all other parameters. If such a script is loaded in a psql run that initially had "-d connstring" with some non-default parameters, those other parameters would be lost, potentially causing connection failure. (Thus, this is the same kind of bug addressed in commits a45bc8a4f and 8e5793ab6, although the details are much different.) To fix, redesign do_connect() so that it pulls out all properties of the old PGconn using PQconninfo(), and then replaces individual properties in that array. In the case where we don't wish to re-use anything, get libpq's default settings using PQconndefaults() and replace entries in that, so that we don't need different code paths for the two cases. This does result in an additional behavioral change for cases where the original connection parameters allowed multiple hosts, say "psql -h host1,host2", and the \connect request allows re-use of the host setting. Because the previous coding relied on PQhost(), it would only permit reconnection to the same host originally selected. Although one can think of scenarios where that's a good thing, there are others where it is not. Moreover, that behavior doesn't seem to meet the principle of least surprise, nor was it documented; nor is it even clear it was intended, since that coding long pre-dates the addition of multi-host support to libpq. Hence, this patch is content to drop it and re-use the host list as given. Per Peter Eisentraut's comments on bug #16604. Back-patch to all supported branches. Discussion: https://postgr.es/m/16604-933f4b8791227b15@postgresql.org Branch ------ REL_11_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/20be76d5c4ac6bac2c2bac98bfb8125756bf7aae Modified Files -------------- doc/src/sgml/ref/psql-ref.sgml | 42 +++++-- src/bin/psql/command.c | 272 ++++++++++++++++++++++++++++++----------- 2 files changed, 227 insertions(+), 87 deletions(-) ^ permalink raw reply [nested|flat] 14+ messages in thread
* pgsql: Fix connection string handling in psql's \connect command. @ 2020-10-21 20:19 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 14+ messages in thread From: Tom Lane @ 2020-10-21 20:19 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix connection string handling in psql's \connect command. psql's \connect claims to be able to re-use previous connection parameters, 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 have re-use all other parameters. If such a script is loaded in a psql run that initially had "-d connstring" with some non-default parameters, those other parameters would be lost, potentially causing connection failure. (Thus, this is the same kind of bug addressed in commits a45bc8a4f and 8e5793ab6, although the details are much different.) To fix, redesign do_connect() so that it pulls out all properties of the old PGconn using PQconninfo(), and then replaces individual properties in that array. In the case where we don't wish to re-use anything, get libpq's default settings using PQconndefaults() and replace entries in that, so that we don't need different code paths for the two cases. This does result in an additional behavioral change for cases where the original connection parameters allowed multiple hosts, say "psql -h host1,host2", and the \connect request allows re-use of the host setting. Because the previous coding relied on PQhost(), it would only permit reconnection to the same host originally selected. Although one can think of scenarios where that's a good thing, there are others where it is not. Moreover, that behavior doesn't seem to meet the principle of least surprise, nor was it documented; nor is it even clear it was intended, since that coding long pre-dates the addition of multi-host support to libpq. Hence, this patch is content to drop it and re-use the host list as given. Per Peter Eisentraut's comments on bug #16604. Back-patch to all supported branches. Discussion: https://postgr.es/m/16604-933f4b8791227b15@postgresql.org Branch ------ REL9_6_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/870a2323033e8b96b27cdf65a53f3e0c7c7b9a88 Modified Files -------------- doc/src/sgml/ref/psql-ref.sgml | 44 ++++--- src/bin/psql/command.c | 270 ++++++++++++++++++++++++++++++----------- 2 files changed, 229 insertions(+), 85 deletions(-) ^ permalink raw reply [nested|flat] 14+ messages in thread
* pgsql: Fix connection string handling in psql's \connect command. @ 2020-10-21 20:19 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 14+ messages in thread From: Tom Lane @ 2020-10-21 20:19 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix connection string handling in psql's \connect command. psql's \connect claims to be able to re-use previous connection parameters, 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 have re-use all other parameters. If such a script is loaded in a psql run that initially had "-d connstring" with some non-default parameters, those other parameters would be lost, potentially causing connection failure. (Thus, this is the same kind of bug addressed in commits a45bc8a4f and 8e5793ab6, although the details are much different.) To fix, redesign do_connect() so that it pulls out all properties of the old PGconn using PQconninfo(), and then replaces individual properties in that array. In the case where we don't wish to re-use anything, get libpq's default settings using PQconndefaults() and replace entries in that, so that we don't need different code paths for the two cases. This does result in an additional behavioral change for cases where the original connection parameters allowed multiple hosts, say "psql -h host1,host2", and the \connect request allows re-use of the host setting. Because the previous coding relied on PQhost(), it would only permit reconnection to the same host originally selected. Although one can think of scenarios where that's a good thing, there are others where it is not. Moreover, that behavior doesn't seem to meet the principle of least surprise, nor was it documented; nor is it even clear it was intended, since that coding long pre-dates the addition of multi-host support to libpq. Hence, this patch is content to drop it and re-use the host list as given. Per Peter Eisentraut's comments on bug #16604. Back-patch to all supported branches. Discussion: https://postgr.es/m/16604-933f4b8791227b15@postgresql.org Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/85c54287af56fe351b53913ea2b81e9d6145f964 Modified Files -------------- doc/src/sgml/ref/psql-ref.sgml | 45 ++++--- src/bin/psql/command.c | 298 ++++++++++++++++++++++++++--------------- 2 files changed, 217 insertions(+), 126 deletions(-) ^ permalink raw reply [nested|flat] 14+ messages in thread
* pgsql: Fix connection string handling in psql's \connect command. @ 2020-10-21 20:19 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 14+ messages in thread From: Tom Lane @ 2020-10-21 20:19 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix connection string handling in psql's \connect command. psql's \connect claims to be able to re-use previous connection parameters, 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 have re-use all other parameters. If such a script is loaded in a psql run that initially had "-d connstring" with some non-default parameters, those other parameters would be lost, potentially causing connection failure. (Thus, this is the same kind of bug addressed in commits a45bc8a4f and 8e5793ab6, although the details are much different.) To fix, redesign do_connect() so that it pulls out all properties of the old PGconn using PQconninfo(), and then replaces individual properties in that array. In the case where we don't wish to re-use anything, get libpq's default settings using PQconndefaults() and replace entries in that, so that we don't need different code paths for the two cases. This does result in an additional behavioral change for cases where the original connection parameters allowed multiple hosts, say "psql -h host1,host2", and the \connect request allows re-use of the host setting. Because the previous coding relied on PQhost(), it would only permit reconnection to the same host originally selected. Although one can think of scenarios where that's a good thing, there are others where it is not. Moreover, that behavior doesn't seem to meet the principle of least surprise, nor was it documented; nor is it even clear it was intended, since that coding long pre-dates the addition of multi-host support to libpq. Hence, this patch is content to drop it and re-use the host list as given. Per Peter Eisentraut's comments on bug #16604. Back-patch to all supported branches. Discussion: https://postgr.es/m/16604-933f4b8791227b15@postgresql.org Branch ------ REL_12_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/f656517ecdf405abeac26b4aebc97ebfefaba633 Modified Files -------------- doc/src/sgml/ref/psql-ref.sgml | 45 ++++--- src/bin/psql/command.c | 298 ++++++++++++++++++++++++++--------------- 2 files changed, 217 insertions(+), 126 deletions(-) ^ permalink raw reply [nested|flat] 14+ messages in thread
* pgsql: Fix connection string handling in psql's \connect command. @ 2020-10-21 20:19 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 14+ messages in thread From: Tom Lane @ 2020-10-21 20:19 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix connection string handling in psql's \connect command. psql's \connect claims to be able to re-use previous connection parameters, 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 have re-use all other parameters. If such a script is loaded in a psql run that initially had "-d connstring" with some non-default parameters, those other parameters would be lost, potentially causing connection failure. (Thus, this is the same kind of bug addressed in commits a45bc8a4f and 8e5793ab6, although the details are much different.) To fix, redesign do_connect() so that it pulls out all properties of the old PGconn using PQconninfo(), and then replaces individual properties in that array. In the case where we don't wish to re-use anything, get libpq's default settings using PQconndefaults() and replace entries in that, so that we don't need different code paths for the two cases. This does result in an additional behavioral change for cases where the original connection parameters allowed multiple hosts, say "psql -h host1,host2", and the \connect request allows re-use of the host setting. Because the previous coding relied on PQhost(), it would only permit reconnection to the same host originally selected. Although one can think of scenarios where that's a good thing, there are others where it is not. Moreover, that behavior doesn't seem to meet the principle of least surprise, nor was it documented; nor is it even clear it was intended, since that coding long pre-dates the addition of multi-host support to libpq. Hence, this patch is content to drop it and re-use the host list as given. Per Peter Eisentraut's comments on bug #16604. Back-patch to all supported branches. Discussion: https://postgr.es/m/16604-933f4b8791227b15@postgresql.org Branch ------ REL_13_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/2e4af411075c10c5007eb09bcb67abf7f825572d Modified Files -------------- doc/src/sgml/ref/psql-ref.sgml | 45 ++++--- src/bin/psql/command.c | 298 ++++++++++++++++++++++++++--------------- 2 files changed, 217 insertions(+), 126 deletions(-) ^ permalink raw reply [nested|flat] 14+ messages in thread
* pgsql: Fix connection string handling in psql's \connect command. @ 2020-10-21 20:19 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 14+ messages in thread From: Tom Lane @ 2020-10-21 20:19 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix connection string handling in psql's \connect command. psql's \connect claims to be able to re-use previous connection parameters, 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 have re-use all other parameters. If such a script is loaded in a psql run that initially had "-d connstring" with some non-default parameters, those other parameters would be lost, potentially causing connection failure. (Thus, this is the same kind of bug addressed in commits a45bc8a4f and 8e5793ab6, although the details are much different.) To fix, redesign do_connect() so that it pulls out all properties of the old PGconn using PQconninfo(), and then replaces individual properties in that array. In the case where we don't wish to re-use anything, get libpq's default settings using PQconndefaults() and replace entries in that, so that we don't need different code paths for the two cases. This does result in an additional behavioral change for cases where the original connection parameters allowed multiple hosts, say "psql -h host1,host2", and the \connect request allows re-use of the host setting. Because the previous coding relied on PQhost(), it would only permit reconnection to the same host originally selected. Although one can think of scenarios where that's a good thing, there are others where it is not. Moreover, that behavior doesn't seem to meet the principle of least surprise, nor was it documented; nor is it even clear it was intended, since that coding long pre-dates the addition of multi-host support to libpq. Hence, this patch is content to drop it and re-use the host list as given. Per Peter Eisentraut's comments on bug #16604. Back-patch to all supported branches. Discussion: https://postgr.es/m/16604-933f4b8791227b15@postgresql.org Branch ------ REL_10_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/8175da6e796e64bf45bc4bd27c1f12b3265b803f Modified Files -------------- doc/src/sgml/ref/psql-ref.sgml | 44 ++++--- src/bin/psql/command.c | 272 ++++++++++++++++++++++++++++++----------- 2 files changed, 230 insertions(+), 86 deletions(-) ^ permalink raw reply [nested|flat] 14+ messages in thread
* pgsql: Fix connection string handling in psql's \connect command. @ 2020-10-21 20:19 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 14+ messages in thread From: Tom Lane @ 2020-10-21 20:19 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix connection string handling in psql's \connect command. psql's \connect claims to be able to re-use previous connection parameters, 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 have re-use all other parameters. If such a script is loaded in a psql run that initially had "-d connstring" with some non-default parameters, those other parameters would be lost, potentially causing connection failure. (Thus, this is the same kind of bug addressed in commits a45bc8a4f and 8e5793ab6, although the details are much different.) To fix, redesign do_connect() so that it pulls out all properties of the old PGconn using PQconninfo(), and then replaces individual properties in that array. In the case where we don't wish to re-use anything, get libpq's default settings using PQconndefaults() and replace entries in that, so that we don't need different code paths for the two cases. This does result in an additional behavioral change for cases where the original connection parameters allowed multiple hosts, say "psql -h host1,host2", and the \connect request allows re-use of the host setting. Because the previous coding relied on PQhost(), it would only permit reconnection to the same host originally selected. Although one can think of scenarios where that's a good thing, there are others where it is not. Moreover, that behavior doesn't seem to meet the principle of least surprise, nor was it documented; nor is it even clear it was intended, since that coding long pre-dates the addition of multi-host support to libpq. Hence, this patch is content to drop it and re-use the host list as given. Per Peter Eisentraut's comments on bug #16604. Back-patch to all supported branches. Discussion: https://postgr.es/m/16604-933f4b8791227b15@postgresql.org Branch ------ REL9_5_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/6997da09a41f613695575fbfcb213f14784c92bb Modified Files -------------- doc/src/sgml/ref/psql-ref.sgml | 44 ++++--- src/bin/psql/command.c | 272 ++++++++++++++++++++++++++++++----------- 2 files changed, 229 insertions(+), 87 deletions(-) ^ permalink raw reply [nested|flat] 14+ messages in thread
end of thread, other threads:[~2020-10-21 20:19 UTC | newest] Thread overview: 14+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2020-10-19 23:04 pgsql: Fix connection string handling in src/bin/scripts/ programs. Tom Lane <tgl@sss.pgh.pa.us> 2020-10-19 23:04 pgsql: Fix connection string handling in src/bin/scripts/ programs. Tom Lane <tgl@sss.pgh.pa.us> 2020-10-19 23:04 pgsql: Fix connection string handling in src/bin/scripts/ programs. Tom Lane <tgl@sss.pgh.pa.us> 2020-10-19 23:04 pgsql: Fix connection string handling in src/bin/scripts/ programs. Tom Lane <tgl@sss.pgh.pa.us> 2020-10-19 23:04 pgsql: Fix connection string handling in src/bin/scripts/ programs. Tom Lane <tgl@sss.pgh.pa.us> 2020-10-19 23:04 pgsql: Fix connection string handling in src/bin/scripts/ programs. Tom Lane <tgl@sss.pgh.pa.us> 2020-10-19 23:04 pgsql: Fix connection string handling in src/bin/scripts/ programs. Tom Lane <tgl@sss.pgh.pa.us> 2020-10-21 20:19 pgsql: Fix connection string handling in psql's \connect command. Tom Lane <tgl@sss.pgh.pa.us> 2020-10-21 20:19 pgsql: Fix connection string handling in psql's \connect command. Tom Lane <tgl@sss.pgh.pa.us> 2020-10-21 20:19 pgsql: Fix connection string handling in psql's \connect command. Tom Lane <tgl@sss.pgh.pa.us> 2020-10-21 20:19 pgsql: Fix connection string handling in psql's \connect command. Tom Lane <tgl@sss.pgh.pa.us> 2020-10-21 20:19 pgsql: Fix connection string handling in psql's \connect command. Tom Lane <tgl@sss.pgh.pa.us> 2020-10-21 20:19 pgsql: Fix connection string handling in psql's \connect command. Tom Lane <tgl@sss.pgh.pa.us> 2020-10-21 20:19 pgsql: Fix connection string handling in psql's \connect command. Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions for how to clone and mirror all data and code used for this inbox