postgresql 端口混淆 5433 还是 5432?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15100368/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
postgresql port confusion 5433 or 5432?
提问by highBandWidth
I have installed postgresql on OSX. When I run psql, I get
我已经在 OSX 上安装了 postgresql。当我运行 psql 时,我得到
$ 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"?
However, from /etc/services
但是,从 /etc/services
postgresql 5432/udp # PostgreSQL Database
postgresql 5432/tcp # PostgreSQL Database
# Tom Lane <[email protected]>
pyrrho 5433/tcp # Pyrrho DBMS
pyrrho 5433/udp # Pyrrho DBMS
5433 is occupied by pyrrho, 5432 is assigned to pg. I can connect with
5433 被 pyrrho 占用,5432 被分配给 pg。我可以连接
psql -p 5432
but why does psql think it is 5433 and how do I make psql look in the right place by default?
但是为什么 psql 认为它是 5433 并且默认情况下如何让 psql 看起来正确?
回答by Craig Ringer
/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.
/etc/services
仅供参考,它是知名端口的列表。这并不意味着该端口上实际上正在运行任何东西,或者命名服务将在该端口上运行。
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.
在 PostgreSQL 的情况下,通常使用端口 5432(如果可用)。如果不是,大多数安装程序会选择下一个空闲端口,通常是 5433。
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).
您可以使用该netstat
工具查看实际运行的内容(在 OS X、Windows 和 Linux 上可用,命令行语法在这三者中各不相同)。
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.
这在 Mac OS X 系统上由于不同 PostgreSQL 包的可怕混乱而进一步复杂化 - Apple 古老版本的 PostgreSQL 内置于操作系统、Postgres.app、Homebrew、Macports、EnterpriseDB 安装程序等。
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.
什么最终发生的是,用户安装PG,并开始从一个包装一台服务器,但使用psql
和libpq
客户从不同的包装。通常,当他们运行 Postgres.app 或自制程序 Pg 并psql
与操作系统附带的连接时会发生这种情况。这些有时不仅具有不同的默认端口,而且 Mac OS X 附带的 Pg 具有不同的默认 unix socket path,因此即使服务器在同一端口上运行,它也不会侦听相同的 unix socket。
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;
.
大多数 Mac 用户只需将 tcp/ip 与psql -h localhost
. 如果需要,您还可以指定端口,例如psql -h localhost -p 5433
. 您可能有多个 PostgreSQL 实例在运行,因此请确保使用select version()
和连接到正确的实例SHOW data_directory;
。
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
.
你也可以指定一个unix socket目录;检查unix_socket_directories
您希望连接的 PostgreSQL 实例的设置,并用 指定它psql -h
,例如psql -h /tmp
.
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.
一个清洁的解决方案是校正系统PATH
,以便psql
与libpq
相关的与PostgreSQL的你实际上是在运行是什么先上找到PATH
。详细信息取决于您的 Mac OS X 版本和您安装的 Pg 包。我不使用 Mac 并且无法在不花费比当前可用时间更多的时间的情况下提供更多细节。
回答by DavidLStacy
Quick answer on OSX, set your environment variables.
在 OSX 上快速回答,设置您的环境变量。
export PGHOST=localhost
export PGPORT=5432
导出 PGHOST=本地主机
出口PGPORT=5432
Or whatever you need.
或者任何你需要的。
回答by Risadinha
The default port of Postgres is commonly configured in:
Postgres 的默认端口通常配置在:
sudo vi /<path to your installation>/data/postgresql.conf
On Ubuntu this might be:
在 Ubuntu 上,这可能是:
sudo vi /<path to your installation>/main/postgresql.conf
Search for port
in this file.
port
在此文件中搜索。
回答by Eron Lloyd
It seems that one of the most common reasons this happens is if you install a new version of PostgreSQL without stopping the service of an existing installation. This was a particular headache of mine, too. Before installing or upgrading, particularly on OS X and using the one click installer from Enterprise DB, make sure you check the status of the old installation before proceeding.
发生这种情况的最常见原因之一似乎是,如果您在不停止现有安装服务的情况下安装了新版本的 PostgreSQL。这也是我特别头疼的问题。在安装或升级之前,尤其是在 OS X 和使用 Enterprise DB 中的一键安装程序之前,请确保在继续之前检查旧安装的状态。
回答by highBandWidth
Thanks to @a_horse_with_no_name's comment, I changed my PGPORT definition to 5432 in pg_env.sh. That fixed the problem for me. I don't know why postgres set it as 5433 initially when it was hosting the service at 5432.
感谢@a_horse_with_no_name的评论,我在 pg_env.sh 中将我的 PGPORT 定义更改为 5432。那为我解决了问题。我不知道为什么 postgres 最初在 5432 托管服务时将其设置为 5433。
回答by Krazzzeee
I ran into this problem as well, it ended up that I had two postgres servers running at the same time. I uninstalled one of them and changed the port back to 5432 and works fine now.
我也遇到了这个问题,结果我同时运行了两个 postgres 服务器。我卸载了其中一个并将端口改回 5432,现在工作正常。
回答by Alan Simpson
For me in PgAdmin 4on Mac OS High Sierra, Clicking the PostrgreSQL10database under Serversin the left column, then the Propertiestab, showed 5433as the port under Connection. (I don't know why, because I chose 5432 during install). Anyway, I clicked the Editicon under the Propertiestab, change that to 5432, saved, and that solved the problem. Go figure.
对于我在Mac OS High Sierra上的PgAdmin 4 中,单击左列中Servers下的PostrgreSQL10数据库,然后单击Properties选项卡,显示5433作为Connection下的端口。(我不知道为什么,因为我在安装过程中选择了 5432)。无论如何,我单击“属性”选项卡下的“编辑”图标,将其更改为5432,保存,并解决了问题。去搞清楚。