Postgresql 是在本地运行并接受 Unix 域上的连接的服务器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42749668/
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 is the server running locally and accepting connection on Unix domain
提问by Always Sunny
I am trying to install postgresql-9.5or postgresql-9.6on my ubuntu 16.04
or 14.04
machine, after following the installation process using below commands.
在使用以下命令执行安装过程后,我正在尝试在我的 ubuntu或机器上安装postgresql-9.5或postgresql-9.6。16.04
14.04
sudo apt-get install update
sudo apt-get install postgresql postgresql-contrib
But when I am trying to open psql
from my terminal using below commands
但是当我尝试psql
使用以下命令从终端打开时
sudo su postgres
psql
every time its just showing.
每次它只是显示。
psql: 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"?
psql:无法连接到服务器:没有这样的文件或目录服务器是否在本地运行并接受 Unix 域套接字“/var/run/postgresql/.s.PGSQL.5432”上的连接?
I have tried approximately 10 stackoverflow.com solutions but no success. Please help me out before I tear all my hairs :(
我尝试了大约 10 个 stackoverflow.com 解决方案,但没有成功。在我撕掉我所有的头发之前,请帮助我:(
$ service postgresql status
$ service postgresql 状态
● postgresql.service - PostgreSQL RDBMS
Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor prese
Active: active (**exited) since ??? 2017-03-12 21:45:56 BDT; 23min ago
Process: 917 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
Main PID: 917 (code=exited, status=0/SUCCESS)
Tasks: 0
Memory: 0B
CPU: 0
CGroup: /system.slice/postgresql.service
see this line carefully why exited ? Active: active (exited) since ??? 2017-03-12 21:45:56 BDT; 23min ago
仔细看这行为什么退出? 活动:活动(退出)自 ??? 2017-03-12 21:45:56 BDT; 23 分钟前
回答by Gab
You can run the following command to check if postgresql is running:
您可以运行以下命令来检查 postgresql 是否正在运行:
service postgresql status
If PostgreSQL is not started you can start it with:
如果 PostgreSQL 未启动,您可以使用以下命令启动它:
service postgresql start
service postgresql status
If it does not start properly, you can look at what is going on in the logs:
如果它没有正常启动,您可以查看日志中发生了什么:
tail /var/log/postgresql/postgresql-9.6-main.log
You might have to run createdb
to initialize a database (see https://www.postgresql.org/docs/current/static/app-createdb.html):
您可能必须运行createdb
以初始化数据库(请参阅https://www.postgresql.org/docs/current/static/app-createdb.html):
createdb demo
Update
更新
If PostgreSQL is running when you do service postgresql status
but you still can't connect, you should check if PostgreSQL is indeed running on port 5432 or another one with:
如果 PostgreSQL 正在运行,service postgresql status
但您仍然无法连接,您应该检查 PostgreSQL 是否确实在端口 5432 或另一个端口上运行:
netstat -na | grep postgres
Update 2
更新 2
Since the native packages on debian/ubuntu for PostgreSQL sucks, I advise you to install these instead: https://www.gab.lc/articles/install_postgresql_9-5_debian_ubuntu(replace 9-2
with 9-6
).
由于用于 PostgreSQL 的 debian/ubuntu 上的本机软件包很糟糕,我建议您改为安装这些:https: //www.gab.lc/articles/install_postgresql_9-5_debian_ubuntu(替换9-2
为9-6
)。
回答by Always Sunny
This is how finally solved my issue after removing the existing postgresql version and directory
这就是在删除现有的 postgresql 版本和目录后最终解决我的问题的方法
sudo apt-get --purge remove postgresql-*
sudo rm -Rf /etc/postgresql /var/lib/postgresql
sudo apt-get install postgresql