postgresql - PostgreSQL 服务器没有监听
问题描述
大约一个月前,我在 Ubuntu 21.04 上使用 command 安装了 PostgreSQL sudo apt install postgresql
,直到今天才忘记它。今天,我尝试了 psql 并得到一个错误,表明它没有在 Unix 域套接字上侦听:
$ sudo -i -u postgres psql
psql: error: 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"?
$
netstat
表明它也没有在端口 5432 上侦听。
端口 5432 没有被任何防火墙或其他反恶意软件阻止:我可以nc -l -p 5432
从另一台机器连接到它。
我试过检查其他东西:
$ sudo systemctl is-active postgresql
active
$ sudo systemctl is-enabled postgresql
enabled
$ sudo systemctl status postgresql
● postgresql.service - PostgreSQL RDBMS
Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
Active: active (exited) since Tue 2021-07-20 12:38:20 BST; 3 weeks 1 days ago
Process: 706 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
Main PID: 706 (code=exited, status=0/SUCCESS)
Jul 20 12:38:20 pluto systemd[1]: Starting PostgreSQL RDBMS...
Jul 20 12:38:20 pluto systemd[1]: Finished PostgreSQL RDBMS.
$ ls -al /etc/postgresql
total 16
drwxr-xr-x 2 postgres postgres 4096 Feb 26 00:21 .
drwxr-xr-x 163 root root 12288 Aug 11 08:36 ..
$ pg_lsclusters
Ver Cluster Port Status Owner Data directory Log file
$
为了让服务器运行,我应该做apt install
一些我没有做的设置吗?
解决方案
感谢@AdrianKlaver 在他的评论中的提示,我已经使用这些命令运行了服务器:
$ sudo -i -u postgres
$ /usr/lib/postgresql/13/bin/initdb -D /tmp/pgdata #In /tmp as I'm just playing with it
$ /usr/lib/postgresql/13/bin/pg_ctl -D /tmp/pgdata -l logfile start
这使我可以连接到正在侦听端口 5432 的服务器,但我不确定每次重新启动时如何启动它。
推荐阅读
- ios - iOS/macOS 应用内购买 - 在 KeyChain 中保存什么
- c# - 在 C# 中修改对象属性时如何触发方法,而不直接修改对象?
- c - 合并排序输入不能大于 8
- java - InnoSetup 编译器设置文件不创建数据库文件
- python - python - 具有不同键的 Json 数据
- python - 如何让凯撒密码在保留案例的同时忽略空格和标点符号?
- angular - 我如何更改默认文本“按 Enter 键添加”标签输入表单中的角度?
- join - SAS多对多合并
- python - 无法使用 DearPyGui 为绘制的图形添加单击处理程序
- javascript - 将状态/数据传递给功能组件,我做错了/更容易吗?