文章目录
- 修改配置文件
- 通过 postmaster 或者 postgres 指定
-
- 通过 pg_ctl 参数执行
-
修改配置文件
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