需要帮助在 CentOS 7 上更改 postgresql 端口
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25148693/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Need help to change postgresql port on CentOS 7
提问by
I just installed the postgresql (as it says on postgresql), server is running like charm, no problem at all.
I just tried(want) to change the default port (5432) to (9898).
First I just tried to do it by postgresql.conf file under /var/lib/pgsql/data/postgresql.conf
.
I just remove the comment for port
related line, and change it as port=9898
, but there is a comment saying overriding port here doesn't change anything for RHEL and deriven guys, it also says try to override the port config by service config file(cannot find it, where is it?)
.
I also change the postmaster.opts
too (doesn't work the same).
Finally! how may I change the Postgresql 9.2.7 port number on CentOS 7?
我刚刚安装了 postgresql(正如它在 postgresql 上所说的那样),服务器运行得非常好,完全没问题。
我只是尝试(想要)将默认端口(5432)更改为(9898)。
首先,我只是尝试通过/var/lib/pgsql/data/postgresql.conf
.
我只是删除了port
相关行的注释,并将其更改为port=9898
,但是有一条评论说,在此处覆盖端口不会为 RHEL 和派生人员更改任何内容,它还说尝试通过服务配置文件覆盖端口配置(cannot find it, where is it?)
。
我也改变了postmaster.opts
(不起作用)。
最后!如何在 CentOS 7 上更改 Postgresql 9.2.7 端口号?
回答by
Finally I found it, the service file is /lib/systemd/system/postgresql.service
, I just change the following line.
终于找到了,服务文件是/lib/systemd/system/postgresql.service
,我只是改了下一行。
Environment=PGPORT=9898
stop the service as
停止服务作为
service postgresql stop
then reload the daemon services using this
然后使用此重新加载守护程序服务
systemctl daemon-reload
Finally start the postgresql using
最后使用启动 postgresql
service postgresql start
Now it's working like charm :D
现在它就像魅力一样工作:D
回答by Jayadevan
Login to psql. Try
登录到 psql。尝试
show config_file ;
That is the file you should change. Did you restart the server after changing the port? You can also try the file under /etc/rc.d/init.d for PostgreSQL if it is running as a service.
那是您应该更改的文件。更改端口后是否重新启动了服务器?如果 PostgreSQL 作为服务运行,您也可以尝试使用 /etc/rc.d/init.d 下的文件。
回答by noorul
From /lib/systemd/system/postgresql.service
来自 /lib/systemd/system/postgresql.service
# It's not recommended to modify this file in-place, because it will be
# overwritten during package upgrades. If you want to customize, the
# best way is to create a file "/etc/systemd/system/postgresql.service",
# containing
# .include /lib/systemd/system/postgresql.service
# ...make your changes here...
# For more info about custom unit files, see
# http://fedoraproject.org/wiki/Systemd#How_do_I_customize_a_unit_file.2F_add_a_custom_unit_file.3F
# For example, if you want to change the server's port number to 5433,
# create a file named "/etc/systemd/system/postgresql.service" containing:
# .include /lib/systemd/system/postgresql.service
# [Service]
# Environment=PGPORT=5433
# This will override the setting appearing below.
I think it is better to follow the steps above.
我认为最好按照上面的步骤操作。
回答by Sanket Dige
I am using Amazon EC2 instance with Amazon Linux AMI release ( A kind of CentOS it seems). I needed to change PGPORT variable in /etc/init.d/postgresql file and restart the postgresql service using 'service postgresql restart'. And it works!!
我正在将 Amazon EC2 实例与 Amazon Linux AMI 版本一起使用(似乎是一种 CentOS)。我需要更改 /etc/init.d/postgresql 文件中的 PGPORT 变量并使用“service postgresql restart”重新启动 postgresql 服务。它有效!!
PGPORT=some_new_port # /etc/init.d/postgresql