在我的/var/lib/pgsql9/data/postgresql.conf我添加了port = 55434 ,如果我启动Postgres与/usr/bin/pg_ctl start -D /var/lib/pgsql9/data/作为postgres用户然后Postgres是听正确的端口lsof -i -nP :
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME postgres 12127 postgres 3u IPv4 49394 0t0 TCP *:55434 (LISTEN) postgres 12127 postgres 4u IPv6 49395 0t0 TCP *:55434 (LISTEN) postgres 12127 postgres 10u IPv4 49402 0t0 UDP 127.0.0.1:57562->127.0.0.1:57562 postgres 12130 postgres 10u IPv4 49402 0t0 UDP 127.0.0.1:57562->127.0.0.1:57562 postgres 12131 postgres 10u IPv4 49402 0t0 UDP 127.0.0.1:57562->127.0.0.1:57562 postgres 12132 postgres 10u IPv4 49402 0t0 UDP 127.0.0.1:57562->127.0.0.1:57562 postgres 12133 postgres 10u IPv4 49402 0t0 UDP 127.0.0.1:57562->127.0.0.1:57562 postgres 12134 postgres 10u IPv4 49402 0t0 UDP 127.0.0.1:57562->127.0.0.1:57562
但是,如果我尝试使用service postgresql start作为root service postgresql start ,那么它会侦听默认的5432
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME postmaste 12256 postgres 3u IPv4 49690 0t0 TCP *:5432 (LISTEN) postmaste 12256 postgres 4u IPv6 49691 0t0 TCP *:5432 (LISTEN) postmaste 12256 postgres 10u IPv4 49698 0t0 UDP 127.0.0.1:42404->127.0.0.1:42404 postmaste 12260 postgres 10u IPv4 49698 0t0 UDP 127.0.0.1:42404->127.0.0.1:42404 postmaste 12261 postgres 10u IPv4 49698 0t0 UDP 127.0.0.1:42404->127.0.0.1:42404 postmaste 12262 postgres 10u IPv4 49698 0t0 UDP 127.0.0.1:42404->127.0.0.1:42404 postmaste 12263 postgres 10u IPv4 49698 0t0 UDP 127.0.0.1:42404->127.0.0.1:42404 postmaste 12264 postgres 10u IPv4 49698 0t0 UDP 127.0.0.1:42404->127.0.0.1:42404
我已经注意到了COMMAND ( postmaste vs postgres )的区别,但我不知道为什么运行service不读取我编辑的postgresql.conf 。 我会假定root可以读取它。 我想使用service因为我可以很容易地设置Postgres在启动时运行chkconfig postgresql on ,但是如果我必须使用pg_ctrl那么我想我将不得不在/etc/rc.local添加启动命令(任何错误有了这个?)。
这是在64位Amazon Linux AMI t1.micro实例上(截至编写时的最新版本)。 并运行psql (PostgreSQL) 9.2.7 (通过yum安装)。
我不是很擅长Linux,所以任何帮助和技巧都是值得赞赏的! 谢谢!
其实,事实certificate我没有仔细阅读postgres.conf 。 它阅读(在评论中):
#port = 5432 # (change requires restart) # Note: In RHEL/Fedora installations, you can't set the port number here; # adjust it in the service file instead.
所以我发现要编辑的文件是/etc/rc.d/init.d/postgresql ,我改变了以下几行的端口设置:
# Set defaults for configuration variables PGENGINE=/usr/bin PGPORT=55434 PGDATA=/var/lib/pgsql9/data PGLOG=/var/lib/pgsql9/pgstartup.log # Value to set as postmaster process's oom_adj PG_OOM_ADJ=-17
然后,我只是service postgresql restart ,它终于开始监听我的55434端口。