Need help changing postgresql port on CentOS 7
I just installed postgresql (as postgresql says), the server works like a charm, no problem.
I just tried (want to) change the default port (5432) to (9898).
At first I just tried to do it with the postgresql.conf file under /var/lib/pgsql/data/postgresql.conf
.
I just remove the comment for the port
linked line and change it like port=9898
, but there is a comment that says the overriding port here doesn't change anything for RHEL and deriven guys, it also says it is trying to override the port config to the service config file (cannot find it, where is it?)
.
I also change postmaster.opts
too (same does not work).
Finally! how can I change the port number of Postgresql 9.2.7 on CentOS 7?
Finally I found it, a service file /lib/systemd/system/postgresql.service
, I just change the following line.
Environment=PGPORT=9898
stop the service like
service postgresql stop
then restart the daemon services using this
systemctl daemon-reload
Finally, start postgresql using
service postgresql start
Now it works like a charm: D
From / lib / systemd / system / postgresql.service
# It 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 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.
source to share
I am using an Amazon EC2 instance with an Amazon Linux AMI release (like CentOS, it looks like). I needed to change the PGPORT variable in the /etc/init.d/postgresql file and restart the postgresql service using 'service postgresql restart'. And it works!
PGPORT=some_new_port # /etc/init.d/postgresql
source to share