Postgresql是在本地运行并接受Unix域

时间:2017-03-12 16:02:42

标签: postgresql ubuntu-14.04 ubuntu-16.04 psql postgresql-9.4

按照安装过程,我尝试在我的ubuntu 16.0414.04计算机上安装 postgresql-9.5 postgresql-9.6 使用以下命令。

sudo apt-get install update
sudo apt-get install postgresql postgresql-contrib

但是当我尝试使用以下命令从我的终端打开psql

sudo su postgres 
psql 

每次只是表现出来。

  

psql:无法连接到服务器:没有这样的文件或目录   服务器在本地运行并接受Unix域上的连接   socket" /var/run/postgresql/.s.PGSQL.5432"?

我已经尝试了大约10个stackoverflow.com解决方案但没有成功。在撕掉我所有的头发之前请帮助我:(

$ 服务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

仔细看看这条线为什么退出? 主动:主动(退出)自রবি2017-03-12 21:45:56 BDT; 23分钟前

2 个答案:

答案 0 :(得分:12)

您可以运行以下命令来检查postgresql是否正在运行:

service postgresql status

如果没有启动PostgreSQL,您可以使用以下命令启动它:

service postgresql start
service postgresql status

如果它无法正常启动,您可以查看日志中发生的情况:

tail /var/log/postgresql/postgresql-9.6-main.log

您可能必须运行createdb来初始化数据库(请参阅https://www.postgresql.org/docs/current/static/app-createdb.html):

createdb demo

<强>更新

如果在service postgresql status执行PostgreSQL但仍然无法连接时,您应检查P​​ostgreSQL是否确实在端口5432上运行,或者另一个运行:

netstat -na | grep postgres

更新2

由于debian / ubuntu for PostgreSQL上的原生包很糟糕,我建议你安装这些包:https://www.gab.lc/articles/install_postgresql_9-5_debian_ubuntu(用9-2替换9-6)。

答案 1 :(得分:4)

这是在删除现有的postgresql版本和目录后最终解决了我的问题

sudo apt-get --purge remove postgresql-*
sudo rm -Rf /etc/postgresql /var/lib/postgresql
sudo apt-get install postgresql