我之前安装了PostgreSQL,遵循这份文件,然后使用以下命令卸载它(我在Fedora上)
sudo rm -rf /var/lib/pgsql/
sudo dnf remove postgresql postgresql-server之后,我再次尝试重新安装它,但将默认端口从5432更改为5433:
sudo dnf install postgresql postgresql-server
sudo postgresql-setup --initdb --unit postgresql --port 5433/var/lib/pgsql/data/postgresql.conf文件确实没有注释的行port = 5433。
但是,当我尝试使用sudo systemctl start postgresql启动服务时,我会得到以下错误
Job for postgresql.service failed because the control process exited with error code.
See "systemctl status postgresql.service" and "journalctl -xeu postgresql.service" for details.下面是来自log文件夹的日志:
2023-05-04 10:46:56.034 CEST [6340] LOG: starting PostgreSQL 15.1 on x86_64-redhat-linux-gnu, compiled by gcc (GCC) 13.0.1 20230117 (Red Hat 13.0.1-0), 64-bit
2023-05-04 10:46:56.034 CEST [6340] LOG: could not bind IPv6 address "::1": Permission denied
2023-05-04 10:46:56.034 CEST [6340] LOG: could not bind IPv4 address "127.0.0.1": Permission denied
2023-05-04 10:46:56.034 CEST [6340] WARNING: could not create listen socket for "localhost"
2023-05-04 10:46:56.034 CEST [6340] FATAL: could not create any TCP/IP sockets
2023-05-04 10:46:56.036 CEST [6340] LOG: database system is shut down但是,当我不使用PostgreSQL而启动postmaster时,它可以工作。
sudo su - postgres
/usr/bin/postmaster -D /var/lib/pgsql/data以下是日志:
2023-05-04 11:08:18.997 CEST [9385] LOG: starting PostgreSQL 15.1 on x86_64-redhat-linux-gnu, compiled by gcc (GCC) 13.0.1 20230117 (Red Hat 13.0.1-0), 64-bit
2023-05-04 11:08:18.998 CEST [9385] LOG: listening on IPv6 address "::1", port 5433
2023-05-04 11:08:18.998 CEST [9385] LOG: listening on IPv4 address "127.0.0.1", port 5433
2023-05-04 11:08:19.000 CEST [9385] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5433"
2023-05-04 11:08:19.002 CEST [9385] LOG: listening on Unix socket "/tmp/.s.PGSQL.5433"
2023-05-04 11:08:19.009 CEST [9389] LOG: database system was shut down at 2023-05-04 10:46:43 CEST
2023-05-04 11:08:19.030 CEST [9385] LOG: database system is ready to accept connections在/usr/lib/systemd/system中,我有两个与PostgreSQL相关的服务
-rw-r--r--. 1 root root 1546 20 janv. 01:00 postgresql.service
-rw-r--r--. 1 root root 1507 20 janv. 01:00 postgresql@.service我已经满意了,没什么好奇怪的。
In postgresql.conf file如果将端口更改为 5432 then,则可以成功启动服务!
我检查了是否有任何东西已经使用端口5433与命令netstat -aon | grep 5433,但似乎没有
当更改默认端口时,您知道是什么原因导致了这个问题吗?我对Linux有点陌生,对服务也不熟悉。
谢谢你的回答
发布于 2023-05-04 10:36:13
好的,原来是SELinux阻塞了它(再次!)
下面是我在SELinux日志文件中找到的一个日志:
~ $ sudo grep "postgre" /var/log/audit/audit.log | grep "5433"
type=AVC msg=audit(1683186096.646:1250): avc: denied { name_bind } for pid=56692 comm="postmaster" src=5433 scontext=system_u:system_r:postgresql_t:s0 tcontext=system_u:object_r:unreserved_port_t:s0 tclass=tcp_socket permissive=0只有端口5432和9898被SELinux允许
~ $ sudo semanage port -l | grep postgresql
postgresql_port_t tcp 5432, 9898因此,我只需要将端口5433添加到列表中:
~ $ sudo semanage port -a -t postgresql_port_t 5433 -p tcp
~ $ sudo semanage port -l | grep postgresql
postgresql_port_t tcp 5433, 5432, 9898在此之后,服务开始工作:
~ $ sudo systemctl start postgresql
~ $ sudo cat /var/lib/pgsql/data/log/postgresql-Thu.log
2023-05-04 12:34:30.786 CEST [14231] LOG: starting PostgreSQL 15.1 on x86_64-redhat-linux-gnu, compiled by gcc (GCC) 13.0.1 20230117 (Red Hat 13.0.1-0), 64-bit
2023-05-04 12:34:30.786 CEST [14231] LOG: listening on IPv6 address "::1", port 5433
2023-05-04 12:34:30.786 CEST [14231] LOG: listening on IPv4 address "127.0.0.1", port 5433
2023-05-04 12:34:30.788 CEST [14231] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5433"
2023-05-04 12:34:30.791 CEST [14231] LOG: listening on Unix socket "/tmp/.s.PGSQL.5433"
2023-05-04 12:34:30.799 CEST [14235] LOG: database system was shut down at 2023-05-04 12:34:05 CEST
2023-05-04 12:34:30.824 CEST [14231] LOG: database system is ready to accept connectionshttps://unix.stackexchange.com/questions/744896
复制相似问题