PostgreSQL端口混乱5433或5432? [英] postgresql port confusion 5433 or 5432?

查看:974
本文介绍了PostgreSQL端口混乱5433或5432?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在OSX上安装了postgresql.当我运行psql时,我得到

I have installed postgresql on OSX. When I run psql, I get

$ psql
psql: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/tmp/.s.PGSQL.5433"?

但是,从/etc/services

However, from /etc/services

postgresql      5432/udp    # PostgreSQL Database
postgresql      5432/tcp    # PostgreSQL Database
#                          Tom Lane <tgl@sss.pgh.pa.us>
pyrrho          5433/tcp    # Pyrrho DBMS
pyrrho          5433/udp    # Pyrrho DBMS

5433被pyrrho占据,5432被分配给pg.我可以与

5433 is occupied by pyrrho, 5432 is assigned to pg. I can connect with

psql -p 5432

但是为什么psql认为它是5433,默认情况下如何使psql在正确的位置显示?

but why does psql think it is 5433 and how do I make psql look in the right place by default?

推荐答案

/etc/services仅是建议性的,它是知名端口的列表.这并不意味着该端口上实际上正在运行任何东西,也不意味着命名服务将在该端口上运行.

/etc/services is only advisory, it's a listing of well-known ports. It doesn't mean that anything is actually running on that port or that the named service will run on that port.

在PostgreSQL的情况下,通常使用端口5432(如果可用).如果不是,大多数安装程序将选择下一个可用端口,通常为5433.

In PostgreSQL's case it's typical to use port 5432 if it is available. If it isn't, most installers will choose the next free port, usually 5433.

您可以使用netstat工具(在OS X,Windows和Linux上可用,命令行语法在所有这三种情况下都可用)查看实际正在运行的内容.

You can see what is actually running using the netstat tool (available on OS X, Windows, and Linux, with command line syntax varying across all three).

在Mac OS X系统上,由于各种PostgreSQL软件包的可怕混乱而使情况变得更加复杂-苹果内置在操作系统中的古老版本的PostgreSQL,Postgres.app,Homebrew,Macports,EnterpriseDB安装程序等.

This is further complicated on Mac OS X systems by the horrible mess of different PostgreSQL packages - Apple's ancient version of PostgreSQL built in to the OS, Postgres.app, Homebrew, Macports, the EnterpriseDB installer, etc etc.

最终发生的事情是,用户安装Pg并从一个包装中启动服务器,但是使用来自不同包装的psqllibpq客户端.通常,这是在他们运行Postgres.app或自制软件Pg并与操作系统附带的psql连接时发生的.这些有时不仅具有不同的默认端口,而且Mac OS X随附的Pg具有不同的默认unix套接字路径,因此即使服务器在同一端口上运行,也不会监听同一个unix套接字.

What ends up happening is that the user installs Pg and starts a server from one packaging, but uses the psql and libpq client from a different packaging. Typically this occurs when they're running Postgres.app or homebrew Pg and connecting with the psql that shipped with the OS. Not only do these sometimes have different default ports, but the Pg that shipped with Mac OS X has a different default unix socket path, so even if the server is running on the same port it won't be listening to the same unix socket.

大多数Mac用户可以通过在psql -h localhost上使用tcp/ip来解决此问题.如果需要,您还可以指定端口,例如psql -h localhost -p 5433.您可能正在运行多个PostgreSQL实例,因此请确保使用select version()SHOW data_directory;连接到正确的实例.

Most Mac users work around this by just using tcp/ip with psql -h localhost. You can also specify a port if required, eg psql -h localhost -p 5433. You might have multiple PostgreSQL instances running so make sure you're connecting to the right one by using select version() and SHOW data_directory;.

您还可以指定一个UNIX套接字目录.检查您要连接的PostgreSQL实例的unix_socket_directories设置,并使用psql -h进行指定,例如psql -h /tmp.

You can also specify a unix socket directory; check the unix_socket_directories setting of the PostgreSQL instance you wish to connect to and specify that with psql -h, e.g.psql -h /tmp.

一种更清洁的解决方案是更正系统PATH,以便与psqllibpq与实际运行的PostgreSQL相关联的是首先在PATH上找到的.具体细节取决于您的Mac OS X版本以及已安装的Pg软件包.我不使用Mac,也不能在没有提供比当前更多时间的情况下提供更多细节.

A cleaner solution is to correct your system PATH so that the psql and libpq associated with the PostgreSQL you are actually running is what's found first on the PATH. The details of that depend on your Mac OS X version and which Pg packages you have installed. I don't use Mac and can't offer much more detail on that side without spending more time than is currently available.

这篇关于PostgreSQL端口混乱5433或5432?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆