postgresql 如何从浏览器访问数据库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25492358/
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
How do I access the database from my browser?
提问by CodyBugstein
I noticed with Postgres and other databases, the database itself runs a local version of a server.
我注意到 Postgres 和其他数据库,数据库本身运行服务器的本地版本。
For example, mine is running on localhost:5432
.
例如,我的正在运行localhost:5432
。
Curiously, I went to my web browser and tried typing in that address to see what I'd get, but I got a response that "This Web Page is Not Available".
奇怪的是,我转到我的网络浏览器并尝试输入该地址以查看我会得到什么,但我得到了“此网页不可用”的响应。
I also tried things like localhost:5432/mydata
but also to no avail.
我也尝试过类似localhost:5432/mydata
但也无济于事的事情。
Shouldn't I be able to see something if I visit the database through my web browser? If yes, how do you do it? If not, why not?
如果我通过 Web 浏览器访问数据库,难道我不能看到一些东西吗?如果是,你怎么做?如果没有,为什么不呢?
回答by deceze
Postgres is a service running on a port. A web server is also a service running on a port (80 and/or 443 usually). There are a lot of things running on various ports on any server, heck, on any single computer. That doesn't mean that everything is interchangeable. Ports 80 and 443 are commonly agreed to serve HTTP(S) connections. HTTP is a specific protocolwhich specifies how two things can communicate on a specific port. Postgres is not speaking HTTP; you need to speak Postgres' particular protocol if you want to talk to it. The browser does not speak that protocol, and Postgres doesn't by default offer communication in any protocol a browser understands.
Postgres 是运行在端口上的服务。Web 服务器也是在端口(通常为 80 和/或 443)上运行的服务。有很多东西在任何服务器的不同端口上运行,哎呀,在任何一台计算机上。这并不意味着一切都可以互换。端口 80 和 443 通常被同意为HTTP(S) 连接提供服务。HTTP 是一种特定的协议,它指定两个事物如何在特定端口上进行通信。Postgres 不是说 HTTP;如果你想与之交谈,你需要说出 Postgres 的特定协议。浏览器不使用该协议,并且 Postgres 默认不提供浏览器理解的任何协议中的通信。
回答by luksch
A web browser expects to "talk" to servers using a protocol it supports. Webbrowsers support obviously http. Some do support other protocols, like ftp. But your postgres does not speak http. So you don't see anything. The port number is just telling over which channel the server is accessible. Any protocol can be routed over any port, but usually http can be reached over port 80. Your postgress over port 5432.
Web 浏览器希望使用它支持的协议与服务器“交谈”。网络浏览器显然支持 http。有些确实支持其他协议,例如 ftp。但是你的 postgres 不会说 http。所以你什么也看不到。端口号只是告诉服务器可以访问哪个通道。任何协议都可以通过任何端口路由,但通常可以通过端口 80 访问 http。您的 postgress 通过端口 5432。