pg_dump与数据库的连接失败

meo*_*ww- 1 postgresql

我正在尝试在本地计算机上使用pg_dump工具.但是,当我database_name在终端窗口中键入pg_dump时,我收到的消息表明:

pg_dump: [archiver (db)] connection to database "demo" failed: 
could not connect to server: No such file or directory
Run Code Online (Sandbox Code Playgroud)

收到此错误消息后,我进入了postgressql.conf文件(postgres的配置文件)并将listen_addresses设置为*.我的连接字符串如下所示:

  - Connection Settings -

 #listen_addresses = '*'        # what IP address(es) to listen on;
                # comma-separated list of addresses;
                # defaults to 'localhost'; use '*' for all
                # (change requires restart)
#port = 5432                # (change requires restart)
max_connections = 20            # (change requires restart)
# Note:  Increasing max_connections costs ~400 bytes of shared memory per
# connection slot, plus lock space (see max_locks_per_transaction).
#superuser_reserved_connections = 3 # (change requires restart)
#unix_socket_directory = ''     # (change requires restart)
#unix_socket_group = ''         # (change requires restart)
#unix_socket_permissions = 0777     # begin with 0 to use octal notation
                # (change requires restart)
#bonjour = off              # advertise server via Bonjour
                # (change requires restart)
#bonjour_name = ''          # defaults to the computer name
                # (change requires restart)
Run Code Online (Sandbox Code Playgroud)

然后我重新启动了我的机器,希望当我pg_dump在控制台中输入时,会发生一些不同的事情.但是,即使重启后,我仍然无法连接到服务器错误消息(如上所述).

我应该尝试下一步以解决此问题?

先感谢您

Cra*_*ger 6

你在Mac OS X上,对吧?

你的道路是错误的,它的发现psql,pg_dump从苹果公司的内置的复制等psqlPostgreSQL的,不是你单独安装了一个.

尝试使用-h /tmp-h localhost.如果有效,那就证实了这就是问题所在.要正确修复它,你需要调整你的位置,PATH以便首先找到正确的PostgreSQL二进制文件.

(我非常恼火地看到Apple将OS X中的PostgreSQL与默认系统PATH上的工具捆绑在一起,并与任何用户安装的工具发生冲突).

您的后续评论确认这是问题所在.您需要pg_dump从您安装的PostgreSQL版本运行.既然你没有说你如何安装PostgreSQL,你的操作系统,或者其他任何我建议你通过搜索现有的问题提到这一点.搜索类似的内容:

"OS X"postgresql路径

将提供信息.这将是Stack Overflow搜索.

或者,您可以明确地给出路径pg_dump.它取决于你如何安装PostgreSQL,你没有提到.这可能是/usr/local/bin/pg_dump,/opt/