dbcli / pgcli

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

OperationalError on all queries #860

Open joaodlf opened 6 years ago

joaodlf commented 6 years ago

Description

I get the following error when I start pgcli:

Exception in thread completion_refresh:
Traceback (most recent call last):
  File "/usr/lib64/python2.7/threading.py", line 812, in __bootstrap_inner
    self.run()
  File "/usr/lib64/python2.7/threading.py", line 765, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/usr/lib/python2.7/site-packages/pgcli/completion_refresher.py", line 60, in _bg_refresh
    **e.extra_args)
  File "/usr/lib/python2.7/site-packages/pgcli/pgexecute.py", line 173, in __init__
    self.connect()
  File "/usr/lib/python2.7/site-packages/pgcli/pgexecute.py", line 198, in connect
    **kwargs)
  File "/usr/lib64/python2.7/site-packages/psycopg2/__init__.py", line 130, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
OperationalError: could not translate host name " /tmp" to address: Name or service not known

I can execute psql commands fine, but all queries just return the above error, as well.

Your environment

Centos 7 Python 2.7.5 Installed pgcli via pip Postgres version 10.3

I've tried installing pgcli on an empty virtualenv, but get the same results.

pip freeze:

backports.csv==1.0.5
backports.ssl-match-hostname==3.4.0.2
chardet==2.2.1
cli-helpers==1.0.1
click==6.7
configobj==5.0.6
decorator==3.4.0
fail2ban==0.9.7
humanize==0.5.1
iniparse==0.4
iotop==0.6
kitchen==1.1.1
langtable==0.0.31
perf==0.1
pgcli==1.9.0
pgspecial==1.10.0
prompt-toolkit==1.0.15
psycopg2-binary==2.7.4
pycurl==7.19.0
Pygments==2.2.0
pygobject==3.22.0
pygpgme==0.3
pyliblzma==0.5.3
python-augeas==0.5.0
python-dmidecode==3.10.13
python-linux-procfs==0.4.9
pyudev==0.15
pyxattr==0.5.1
schedutils==0.4
setproctitle==1.1.10
six==1.9.0
slip==0.4.0
slip.dbus==0.4.0
sqlparse==0.2.4
tabulate==0.8.2
terminaltables==3.1.0
urlgrabber==3.10
virtualenv==15.2.0
wcwidth==0.1.7
yum-langpacks==0.4.2
yum-metadata-parser==1.1.4
joaodlf commented 6 years ago

Managed to get around it with tweaking the pg_hba.conf, needed to set a few local connections to "trust". Oh well.

j-bennet commented 6 years ago

I'm going to leave this open, because it's a bug, even though there's a workaround. Thanks for the report!

joaodlf commented 6 years ago

Cool! I also noticed I can only get pgcli to work properly using the -h flag (ex: pgcli -U postgres -h localhost), without that specific flag, I get the same error, even with the pg_hba.conf tweaks.

j-bennet commented 6 years ago

@joaodlf could you attach your pg_hba.conf? might be helpful to recreate the problem.

joaodlf commented 6 years ago

Sure!

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     trust
# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
# IPv6 local connections:
host    all             all             ::1/128                 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     trust
host    replication     all             127.0.0.1/32            trust
host    replication     all             ::1/128                 trust

# Allow external connections with a password
host    all             all             0.0.0.0/0               md5
host    all             all             ::/0                    md5

This is from the same machine as expressed in my initial report:

PostgreSQL 10.3 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-16), 64-bit

pgcli will only work as expected with the following command: pgcli -U postgres -h localhost

trstringer commented 6 years ago

For what it's worth, I'm running into the same problem and @joaodlf's workaround is working.