我刚安装了postgresql(正如postgresql上所说的那样),服务器运行起来就像魅力一样,完全没问题。
我只是尝试(想要)将默认端口(5432)更改为(9898)。
首先,我试图通过/var/lib/pgsql/data/postgresql.conf
下的postgresql.conf文件来实现
我只是删除port
相关行的注释,并将其更改为port=9898
,但有一条评论说这里覆盖端口不会改变任何RHEL和派生家伙,它还说试图覆盖服务配置文件(cannot find it, where is it?)
的端口配置。
我也改变了postmaster.opts
(不起作用)。
最后!如何更改CentOS 7上的Postgresql 9.2.7端口号?
答案 0 :(得分:2)
最后我发现它,服务文件是/lib/systemd/system/postgresql.service
,我只是更改了以下行。
Environment=PGPORT=9898
停止服务
service postgresql stop
然后使用此
重新加载守护程序服务systemctl daemon-reload
最后使用
启动postgresqlservice postgresql start
现在它像魅力一样工作:D
答案 1 :(得分:1)
登录psql。试试
show config_file ;
这是您应该更改的文件。更改端口后重启服务器了吗? 如果PostgreSQL作为服务运行,你也可以在/etc/rc.d/init.d下尝试该文件。
答案 2 :(得分:1)
来自/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.
我认为最好按照上述步骤进行操作。
答案 3 :(得分:0)
我正在使用Amazon EC2实例和Amazon Linux AMI版本(似乎是一种CentOS)。我需要在/etc/init.d/postgresql文件中更改PGPORT变量,并使用'service postgresql restart'重新启动postgresql服务。它有效!!
PGPORT=some_new_port # /etc/init.d/postgresql