PostgreSQL 错误:无法连接到数据库模板 1:无法连接到服务器:没有这样的文件或目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30095546/
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 error: could not connect to database template1: could not connect to server: No such file or directory
提问by pptt
I need to create database.
我需要创建数据库。
First I run: sudo su - postgres
, then: createdb test
首先我运行:sudo su - postgres
,然后:createdb test
And I keep getting this error:
我不断收到此错误:
createdb: could not connect to database template1: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"
This is unexpected, I have never encountered any problems with psql, but this time I don't get what is wrong. And there is no external server, I am connected locally.
这是出乎意料的,我从来没有遇到过psql的任何问题,但是这次我不明白出了什么问题。并且没有外部服务器,我是本地连接的。
I am running on Ubuntu.
我在 Ubuntu 上运行。
回答by Daniel Vérité
The error message suggests:
错误消息表明:
Is the server running locally
服务器是否在本地运行
and according to the result of ps -ef | grep "post"
posted in the comments, the answer is a definitive No, the server processesare not there, the server is not running.
并且根据ps -ef | grep "post"
评论中发布的结果,答案是明确的No,服务器进程不在那里,服务器没有运行。
That fact that you write i have never encountered any problems with psql,suggests that it was installed and working before, in that case look at the most recent log file inside /var/log/postgresql
to check for any fatal error message indicating why the server didn't start.
你写的我从来没有遇到过 psql 的任何问题,这表明它之前已经安装并可以工作,在这种情况下,请查看里面的最新日志文件/var/log/postgresql
以检查是否有任何致命错误消息表明服务器没有启动的原因。
回答by jainvikram444
The error means that the Postgres server is not running. Try starting it:
该错误意味着 Postgres 服务器没有运行。尝试启动它:
sudo systemctl start postgresql
I believe the service name is postgresql, but if that doesn't work, try typing
我相信服务名称是 postgresql,但如果这不起作用,请尝试输入
sudo systemctl start postgres
须藤 systemctl 启动 postgres
and pressing tab to auto-complete.
并按 Tab 键自动完成。
Make sure that the server starts on boot:
确保服务器在引导时启动:
sudo systemctl enable postgresql
须藤 systemctl 启用 postgresql
回答by Aishwarya kabadi
- Install and run postgreSQL
- 安装并运行 postgreSQL
createdb -h localhost -p 5432 -U postgres testdb password ******
createdb -h localhost -p 5432 -U postgres testdb password ******