dbcli / pgcli

Postgres CLI with autocompletion and syntax highlighting
http://pgcli.com
BSD 3-Clause "New" or "Revised" License
12.06k stars 553 forks source link

pgcli forces default port to be 5432, even if libpq is using different #1332

Closed depesz closed 2 years ago

depesz commented 2 years ago

Description

I have custom build of Pg, with port being, by default 5430. But when i try to connect using pgcli it tries to use 5432.

Sure, I can force port using -p or PGPORT, or alias/function on pgcli, but why would a tool change default port?

Pg was compiled from sources that were configured using ./configure --with-pgport=5430, and psql, without any options or env vars, connect to 5430.

Your environment

Linux ubuntu 21.10 (impish), with Postgresql 15dev compiled from sources, on port 5430.

pip freeze:

aiohttp==3.8.1
aiohttp-socks==0.7.1
aiorpcX==0.18.7
aiosignal==1.2.0
ansible==2.10.7
ansible-base==2.10.16
apt-xapian-index==0.49
asn1crypto==1.4.0
async-timeout==4.0.2
attrs==21.4.0
awscli==1.22.47
backcall==0.2.0
beautifulsoup4==4.9.3
bitstring==3.1.9
blinker==1.4
botocore==1.23.47
certifi==2020.6.20
chardet==4.0.0
charset-normalizer==2.0.10
cli-helpers==2.2.1
click==7.1.2
colorama==0.4.3
colour==0.1.5
command-not-found==0.3
configobj==5.0.6
cryptography==3.3.2
cupshelpers==1.0
daemonize==2.4.7
dbus-python==1.2.16
decorator==4.4.2
distro==1.5.0
distro-info==1.0
dnspython==2.0.0
docutils==0.15.2
ecdsa==0.16.1
Electrum @ file:///mnt/storage/depesz/tmp/Electrum-4.1.5.tar.gz
frozenlist==1.2.0
gpg===1.14.0-unknown
helpdev==0.7.1
html5lib==1.1
httplib2==0.18.1
idna==2.10
importlib-metadata==4.0.1
importlib-resources==5.4.0
iotop==0.6
ipython==7.20.0
ipython_genutils==0.2.0
jedi==0.18.0
jeepney==0.7.1
Jinja2==3.0.3
jmespath==0.10.0
keyring==23.0.1
language-selector==0.1
launchpadlib==1.10.13
lazr.restfulclient==0.14.2
lazr.uri==1.0.5
libvirt-python==7.6.0
lxml==4.6.3
Markdown==3.3.4
MarkupSafe==2.0.1
mechanize==0.4.5
more-itertools==4.2.0
multidict==5.2.0
netifaces==0.10.9
notify2==0.3
numpy==1.19.5
oauthlib==3.1.0
olefile==0.46
packaging==21.3
parso==0.8.1
pendulum==2.1.2
pexpect==4.8.0
pgcli==3.4.1
pglast==3.8
pgspecial==1.13.1
pgxnclient==1.3.2
pickleshare==0.7.5
Pillow==8.1.2
prompt-toolkit==3.0.19
protobuf==3.19.3
psycopg2==2.9.3
pyasn1==0.4.8
pycairo==1.16.2
pycryptodomex==3.9.7
pycups==2.0.1
Pygments==2.7.1
PyGObject==3.40.1
PyJWT==1.7.1
pylibacl==0.6.0
pyparsing==3.0.6
PyQt5==5.15.4
PyQt5-sip==12.9.0
PyQtWebEngine==5.15.4
python-apt==2.2.1
python-dateutil==2.8.1
python-debian===0.1.39ubuntu1
python-socks==2.0.2
pytzdata==2020.1
pyudev==0.22.0
pyxattr==0.7.2
pyxdg==0.27
PyYAML==5.3.1
QDarkStyle==2.8.1
qrcode==7.3.1
QtPy==2.0.0
rdiff-backup==2.0.5
reportlab==3.5.66
requests==2.25.1
roman==2.0.0
rsa==4.0
s3transfer==0.5.1
scour==0.38.2
SecretStorage==3.3.1
setproctitle==1.2.1
simplejson==3.17.2
six==1.16.0
soupsieve==2.2.1
sqlparse==0.4.2
ssh-import-id==5.11
systemd-python==234
tabulate==0.8.9
traitlets==5.0.5
ubuntu-advantage-tools==27.7
ubuntu-drivers-common==0.0.0
ufw==0.36.1
urllib3==1.26.5
usb-creator==0.3.7
wadllib==1.3.5
wcwidth==0.1.9
webencodings==0.5.1
xdg==5
xkit==0.0.0
yarl==1.7.2
zipp==3.7.0
amjith commented 2 years ago

I believe the configure flag is honored by Postgresql database and psql which is the default client that gets built as a result of the configure command. Pgcli is a third-party client that is not going to pick up the default port that was designated at compile time. That's why we provide multiple ways to override the PORT value. Unfortunately there is nothing we can do here to automatically detect the PORT that was designated at compile time.

depesz commented 2 years ago

While I understand that detecting port might be impossible, as far as I can read python, it seems you're forcing port to be 5432 (by default) in main.py, line 1222. Perhaps if you didn't do it, and allow port to be empty, it would make libpq use the port that it was compiled with?