프린트 하기

OS환경 : Oracle Linux 8.4 (64bit)

 

DB 환경 : PostgreSQL 16

 

방법 : PostgreSQL 16 pg_ctl shutdown 옵션

postgresql 의 shutdown 옵션은 3가지가 존재함
smart : 모든 클라이언트의 연결이 끊어진 후 종료함(새로운 연결을 거부하고 현재 연결된 모든 클라이언트가 끊길 때까지 기다린 후 종료함(핫 스탠바이 복구 중이라면 모든 클라이언트가 끊긴 후 스트리밍 복제와 복구를 중지한다고함)
fast : 클라이언트의 연결을 기다리지 않고, 활성 트랜잭션을 롤백한 뒤 클라이언트를 강제로 끊고 clean하게 종료함, 이후 기동시 복구 과정 불필요함(oracle의 shutdown immediate 옵션에 매칭되는 옵션인듯함)
immediate : 서버 프로세스를 즉시 중단시키고 종료함, 이후 기동시 인스턴스 복구를 수행함
기본값은 fast임

 

 

pg 중지 smart 옵션

1
2
3
$ pg_ctl stop -m smart
waiting for server to shut down.... done
server stopped

 

 

pg 중지 smart 옵션 사용시 로그

1
2
3
4
5
6
7
8
$ cd /var/lib/pgsql/16/data/log
$ tail -300f postgresql-Sat.log
2024-03-23 07:18:56.152 KST [3012] LOG:  received smart shutdown request
2024-03-23 07:18:56.161 KST [3012] LOG:  background worker "logical replication launcher" (PID 3019) exited with exit code 1
2024-03-23 07:18:56.161 KST [3014] LOG:  shutting down
2024-03-23 07:18:56.163 KST [3014] LOG:  checkpoint starting: shutdown immediate
2024-03-23 07:18:56.170 KST [3014] LOG:  checkpoint complete: wrote 3 buffers (0.0%); 0 WAL file(s) added, 0 removed, 0 recycled; write=0.001 s, sync=0.002 s, total=0.010 s; sync files=2, longest=0.002 s, average=0.001 s; distance=0 kB, estimate=0 kB; lsn=0/1526D30, redo lsn=0/1526D30
2024-03-23 07:18:56.175 KST [3012] LOG:  database system is shut down

 

 

pg 중지 fast 옵션(기본값)

1
2
3
$ pg_ctl stop -m fast
waiting for server to shut down.... done
server stopped

 

 

pg 중지 fast 옵션 사용시 로그

1
2
3
4
5
6
7
8
9
$ cd /var/lib/pgsql/16/data/log
$ tail -300f postgresql-Sat.log
2024-03-23 07:19:10.403 KST [3023] LOG:  received fast shutdown request
2024-03-23 07:19:10.405 KST [3023] LOG:  aborting any active transactions
2024-03-23 07:19:10.412 KST [3023] LOG:  background worker "logical replication launcher" (PID 3030) exited with exit code 1
2024-03-23 07:19:10.412 KST [3025] LOG:  shutting down
2024-03-23 07:19:10.414 KST [3025] LOG:  checkpoint starting: shutdown immediate
2024-03-23 07:19:10.420 KST [3025] LOG:  checkpoint complete: wrote 3 buffers (0.0%); 0 WAL file(s) added, 0 removed, 0 recycled; write=0.001 s, sync=0.002 s, total=0.009 s; sync files=2, longest=0.002 s, average=0.001 s; distance=0 kB, estimate=0 kB; lsn=0/1526DA8, redo lsn=0/1526DA8
2024-03-23 07:19:10.424 KST [3023] LOG:  database system is shut down

 

 

pg 중지 immediate 옵션

1
2
3
$ pg_ctl stop -m immediate
waiting for server to shut down.... done
server stopped

 

 

pg 중지 immediate 옵션 사용시 로그

1
2
3
4
$ cd /var/lib/pgsql/16/data/log
$ tail -300f postgresql-Sat.log
2024-03-23 07:19:45.504 KST [3036] LOG:  received immediate shutdown request
2024-03-23 07:19:45.513 KST [3036] LOG:  database system is shut down

 

 

참고용 pg_ctl help

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
$ pg_ctl --help
pg_ctl is a utility to initialize, start, stop, or control a PostgreSQL server.
 
Usage:
  pg_ctl init[db]   [-D DATADIR] [-s] [-o OPTIONS]
  pg_ctl start      [-D DATADIR] [-l FILENAME] [-W] [-t SECS] [-s]
                    [-o OPTIONS] [-p PATH] [-c]
  pg_ctl stop       [-D DATADIR] [-m SHUTDOWN-MODE] [-W] [-t SECS] [-s]
  pg_ctl restart    [-D DATADIR] [-m SHUTDOWN-MODE] [-W] [-t SECS] [-s]
                    [-o OPTIONS] [-c]
  pg_ctl reload     [-D DATADIR] [-s]
  pg_ctl status     [-D DATADIR]
  pg_ctl promote    [-D DATADIR] [-W] [-t SECS] [-s]
  pg_ctl logrotate  [-D DATADIR] [-s]
  pg_ctl kill       SIGNALNAME PID
 
Common options:
  -D, --pgdata=DATADIR   location of the database storage area
  -s, --silent           only print errors, no informational messages
  -t, --timeout=SECS     seconds to wait when using -w option
  -V, --version          output version information, then exit
  -w, --wait             wait until operation completes (default)
  -W, --no-wait          do not wait until operation completes
  -?, --help             show this help, then exit
If the -D option is omitted, the environment variable PGDATA is used.
 
Options for start or restart:
  -c, --core-files       allow postgres to produce core files
  -l, --log=FILENAME     write (or append) server log to FILENAME
  -o, --options=OPTIONS  command line options to pass to postgres
                         (PostgreSQL server executable) or initdb
  -p PATH-TO-POSTGRES    normally not necessary
 
Options for stop or restart:
  -m, --mode=MODE        MODE can be "smart", "fast", or "immediate"
 
Shutdown modes are:
  smart       quit after all clients have disconnected
  fast        quit directly, with proper shutdown (default)
  immediate   quit without complete shutdown; will lead to recovery on restart
 
Allowed signal names for kill:
  ABRT HUP INT KILL QUIT TERM USR1 USR2
 
Report bugs to <pgsql-bugs@lists.postgresql.org>.
PostgreSQL home page: <https://www.postgresql.org/>

 

 

참조 : 

https://dbrang.tistory.com/744
https://www.postgresdba.com/bbs/board.php?bo_table=B12&wr_id=16
https://runebook.dev/ko/docs/postgresql/hot-standby
https://www.postgresql.org/docs/16/tutorial-start.html