指定 PG 启动端口

@

修改配置文件

echo "port=5555" >> $PGDATA/postgresql.auto.conf
su - postgres -c "pg_ctl start -D $PGDATA"
su - postgres -c "pg_ctl stop -m fast -D $PGDATA"

通过 postmaster 或者 postgres 指定

方法

su - postgres -c "postmaster -D $PGDATA -p 5555 & "
su - postgres -c "postgres -D $PGDATA -p 5555 & "

示例

[root@localhost ~]# su - postgres -c "postmaster -D $PGDATA -p 5555 & "
[root@localhost ~]# 
[root@localhost ~]# 2025-01-13 08:14:34.745 UTC     1409046:LOG:  redirecting log output to logging collector process
2025-01-13 08:14:34.745 UTC     1409046:HINT:  Future log output will appear in directory "/var/log/pg_log".
[root@localhost ~]# ps -ef | grep postm
postgres 1409046       1  2 16:14 ?        00:00:00 postmaster -D $PGDATA -p 5555
root     1409738 1278677  0 16:14 pts/0    00:00:00 grep --color=auto postm
[root@localhost ~]# ps -ef | grep postgres
postgres 1409046       1  1 16:14 ?        00:00:00 postmaster -D $PGDATA -p 5555
postgres 1409048 1409046  0 16:14 ?        00:00:00 postgres: logger 
postgres 1409058 1409046  0 16:14 ?        00:00:00 postgres: checkpointer 
postgres 1409059 1409046  0 16:14 ?        00:00:00 postgres: background writer 
postgres 1409061 1409046  0 16:14 ?        00:00:00 postgres: walwriter 
postgres 1409062 1409046  0 16:14 ?        00:00:00 postgres: autovacuum launcher 
postgres 1409063 1409046  0 16:14 ?        00:00:00 postgres: logical replication launcher 
root     1409973 1278677  0 16:14 pts/0    00:00:00 grep --color=auto postgres
[root@localhost ~]# 
[root@localhost ~]# su - postgres -c "pg_ctl stop -m fast -D $PGDATA"
waiting for server to shut down....
 done
server stopped





[root@localhost ~]# su - postgres -c "postgres -D $PGDATA -p 5555 & "
[root@localhost ~]# 2025-01-13 08:15:12.847 UTC     1412129:LOG:  redirecting log output to logging collector process
2025-01-13 08:15:12.847 UTC     1412129:HINT:  Future log output will appear in directory "/var/log/pg_log".

[root@localhost ~]# ps -ef | grep postgres
postgres 1412129       1  5 16:15 ?        00:00:00 postgres -D $PGDATA -p 5555
postgres 1412147 1412129  0 16:15 ?        00:00:00 postgres: logger 
postgres 1412148 1412129  0 16:15 ?        00:00:00 postgres: checkpointer 
postgres 1412149 1412129  0 16:15 ?        00:00:00 postgres: background writer 
postgres 1412154 1412129  0 16:15 ?        00:00:00 postgres: walwriter 
postgres 1412158 1412129  0 16:15 ?        00:00:00 postgres: autovacuum launcher 
postgres 1412160 1412129  0 16:15 ?        00:00:00 postgres: logical replication launcher 
root     1412373 1278677  0 16:15 pts/0    00:00:00 grep --color=auto postgres
[root@localhost ~]# 
[root@localhost ~]# su - postgres -c "pg_ctl stop -m fast -D $PGDATA"
waiting for server to shut down.... done
server stopped

通过 pg_ctl 参数执行

方法

su - postgres -c "pg_ctl start -D $PGDATA -o '-p 5555'"

示例

[root@localhost ~]# su - postgres -c "pg_ctl start -D $PGDATA -o '-p 5555'"
waiting for server to start....2025-01-13 08:12:25.634 UTC     1399371:LOG:  redirecting log output to logging collector process
2025-01-13 08:12:25.634 UTC     1399371:HINT:  Future log output will appear in directory "/var/log/pg_log".
 done
server started
[root@localhost ~]# 
[root@localhost ~]# ps -ef |grep postgres
postgres 1399371       1  3 16:12 ?        00:00:00 postgres -D $PGDATA -p 5555
postgres 1399393 1399371  0 16:12 ?        00:00:00 postgres: logger 
postgres 1399394 1399371  0 16:12 ?        00:00:00 postgres: checkpointer 
postgres 1399395 1399371  0 16:12 ?        00:00:00 postgres: background writer 
postgres 1399397 1399371  0 16:12 ?        00:00:00 postgres: walwriter 
postgres 1399398 1399371  0 16:12 ?        00:00:00 postgres: autovacuum launcher 
postgres 1399399 1399371  0 16:12 ?        00:00:00 postgres: logical replication launcher 
root     1399882 1278677  0 16:12 pts/0    00:00:00 grep --color=auto postgres
[root@localhost ~]# 

[root@localhost ~]# su - postgres -c "pg_ctl stop -m fast -D $PGDATA"
waiting for server to shut down.... done
server stopped

posted @   岳麓丹枫  阅读(14)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
点击右上角即可分享
微信分享提示