Ubuntu 18.04 中的 PostgreSQL 奇怪行为

标签 postgresql linux ubuntu

<分区>

我使用以下方法安装了 PostgreSQL:

  • sudo apt install libpq-dev postgresql postgresql-contrib

一开始一切正常,但我还需要远程连接, 所以

  1. 我需要修改:

    pg_hba.confpostgresql.conf

  2. 但我会在修改之前对它们进行备份。

  3. 重启 - sudo systemctl restart posgresql
  4. 有时效果很好

  5. 但在其他情况下,当我尝试 sudo -u postgres psql 时,我收到以下错误:

    psql: colud not connect to the server: No such file or directory. Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432

    这很奇怪,因为我只更改了 pg_hba.conf 中的 IP 地址以允许远程连接,有时工作没有错误,有时我收到错误。也可以远程停止工作。

  6. 我回到备份文件,重启服务器(所以远程文件没有变化),错误仍然存​​在。

  7. 我检查服务:sudo systemctl status postgresql 积极工作。

我不知道出了什么问题,因为我希望从备份中返回到初始文件来修复错误。请帮忙

我发现多次询问错误,但在我的情况下,服务器处于事件状态,甚至返回备份并且不工作。

最佳答案

我设法通过以下方法解决了这个问题。

  1. 检查 postgresql 日志
> tail -f /var/log/postgresql/<what-ever-postgresql-log-name>.logs

如果您的日志显示 FATAL: could not remove old lock file 如下。然后进行第 2 步。

2019-09-06 01:49:13.477 UTC [5439] LOG:  database system is shut down
pg_ctl: another server might be running; trying to start server anyway
2019-09-06 01:51:17.668 UTC [1039] FATAL:  could not remove old lock file "postmaster.pid": Permission denied
2019-09-06 01:51:17.668 UTC [1039] HINT:  The file seems accidentally left over, but it could not be removed. Please remove the file by hand and try again.
pg_ctl: could not start server
Examine the log output.
  1. 删除 data_directory 路径中的 postmaster.pid。 您可以通过检查您的 data_directory 路径

    cat /etc/postgresql/*/main/postgresql.conf

确认您的 data_directory 路径 - 然后发出以下命令。

rm /var/lib/postgresql/10/main/postmaster.pid
  1. 将 postgres 权限设置为 data_directory 路径。在我的例子中是/var/lib/postgresql/-

Honestly I am still looking for a (why we still need to set permission) where by default it is already have permission for postgres user.

sudo chmod 765 /var/run/postgresql  
sudo chown postgres /var/run/postgresql
  1. 然后重启服务

sudo service postgresql restart

  1. 测试是否有效。

sudo -u postgres psql

注意:我使用的是Postgresql 10

关于Ubuntu 18.04 中的 PostgreSQL 奇怪行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51149879/

相关文章:

mysql - 使用 Postgres 在 Laravel 5.3 中更新区分大小写的数据库字段

postgresql - group by count查询耗时较长

c - 推荐捕捉的信号?

linux - CHOWN在LINUX(EC2)中运行进程

linux - ds3234的片选设置

sql - 将具有不同行类型的多个查询显示为一个结果

python - 给定唯一 ID,仅选择与之前的行相比列发生更改的行

linux - 用于文件名路径列表的 mkdir 命令

python 脚本作为 Ubuntu 上的服务

javascript - Angular 2/Nodejs 部署到 heroku 错误 heroku-postbuild : `ng build`