This article will help in changing the port number in PostgreSQL database.
Port numbers are using to connect the database remote server or application, each database having one unique port number, in PostgreSQL database the default port number is 5432, for security reasons organizations use different port number.
Database administrators having full access on servers and they can able to modify the port number of PostgreSQL database anytime.
Step 1 : Connect to the database.
-bash-4.2$ psql -U postgres -p 2221
psql (14.11)
Type "help" for help.
Step 2 : Verify the current PORT number of daabase
postgres=# select name,setting,reset_val from pg_settings where name='port';
name | setting | reset_val
------+---------+-----------
port | 2221 | 2221
Step 3 : Connect to the database and fond configurations file location.
postgres=# \conninfo
You are connected to database "postgres" as user "postgres" via socket in "/run/postgresql" at port "2221".
postgres=# show config_file;
config_file
---------------------------------
/app01/cluster1/postgresql.conf
Step 4 : Go to config file and edit the parameter
-bash-4.2$ vi /app01/cluster1/postgresql.conf
port = 4441 # (change requires restart)
port = 4441 # (change requires restart)
Step 5 : To reflect the new port number database cluster need to be restarted.
-bash-4.2$ pg_ctl -D /app01/cluster1/ stop
waiting for server to shut down.... done
server stopped
-bash-4.2$ pg_ctl -D /app01/cluster1/ start
waiting for server to start....2024-02-15 18:53:43.697 IST [24477] LOG: redirecting log output to logging collector process
2024-02-15 18:53:43.697 IST [24477] HINT: Future log output will appear in directory "log".
done
server started
Step 6 : Connect to the database with new port number and verify.
-bash-4.2$ psql -U postgres -p 4441
psql (14.11)
Type "help" for help.
postgres=# select name,setting,reset_val from pg_settings where name='port';
name | setting | reset_val
------+---------+-----------
port | 4441 | 4441
(1 row)
0 comments:
Post a Comment