프린트 하기

OS환경 : Oracle Linux 8.4 (64bit)

 

DB 환경 : PostgreSQL 16

 

방법 : PostgreSQL 16 기동, 정지 방법 및 로그 확인

postgresql 16에서 기동 정지 하는 방법을 설명함
본문에서는 pg_ctl 명령어를 사용해서 기동, 정지를 수행함

 

 

postgresql 정지
DB가 여러개인 경우 data 경로 지정 필요(pg_ctl -D /var/lib/pgsql/16/data stop)

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

 

 

정시 시 log

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:14:08.115 KST [2923] LOG:  received fast shutdown request
2024-03-23 07:14:08.118 KST [2923] LOG:  aborting any active transactions
2024-03-23 07:14:08.127 KST [2923] LOG:  background worker "logical replication launcher" (PID 2930) exited with exit code 1
2024-03-23 07:14:08.127 KST [2925] LOG:  shutting down
2024-03-23 07:14:08.129 KST [2925] LOG:  checkpoint starting: shutdown immediate
2024-03-23 07:14:08.136 KST [2925] LOG:  checkpoint complete: wrote 3 buffers (0.0%); 0 WAL file(s) added, 0 removed, 0 recycled; write=0.001 s, sync=0.001 s, total=0.009 s; sync files=2, longest=0.001 s, average=0.001 s; distance=0 kB, estimate=0 kB; lsn=0/1526AE0, redo lsn=0/1526AE0
2024-03-23 07:14:08.139 KST [2923] LOG:  database system is shut down

 

 

postgresql 기동

1
2
3
4
5
$ pg_ctl start
waiting for server to start....2024-03-23 07:15:11.445 KST [2943] LOG:  redirecting log output to logging collector process
2024-03-23 07:15:11.445 KST [2943] HINT:  Future log output will appear in directory "log".
 done
server started

 

 

기동 시 log

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:15:11.446 KST [2943] LOG:  starting PostgreSQL 16.2 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 8.5.0 20210514 (Red Hat 8.5.0-20), 64-bit
2024-03-23 07:15:11.448 KST [2943] LOG:  listening on IPv6 address "::1", port 5432
2024-03-23 07:15:11.448 KST [2943] LOG:  listening on IPv4 address "127.0.0.1", port 5432
2024-03-23 07:15:11.451 KST [2943] LOG:  listening on Unix socket "/run/postgresql/.s.PGSQL.5432"
2024-03-23 07:15:11.454 KST [2943] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"
2024-03-23 07:15:11.461 KST [2947] LOG:  database system was shut down at 2024-03-23 07:14:08 KST
2024-03-23 07:15:11.468 KST [2943] LOG:  database system is ready to accept connections

 

 

postgresql 재기동

1
2
3
4
5
6
7
$ pg_ctl restart
waiting for server to shut down.... done
server stopped
waiting for server to start....2024-03-23 07:15:52.238 KST [2961] LOG:  redirecting log output to logging collector process
2024-03-23 07:15:52.238 KST [2961] HINT:  Future log output will appear in directory "log".
 done
server started

 

 

재기동 시 log

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$ cd /var/lib/pgsql/16/data/log
$ tail -300f postgresql-Sat.log
2024-03-23 07:15:52.091 KST [2943] LOG:  received fast shutdown request
2024-03-23 07:15:52.093 KST [2943] LOG:  aborting any active transactions
2024-03-23 07:15:52.099 KST [2943] LOG:  background worker "logical replication launcher" (PID 2950) exited with exit code 1
2024-03-23 07:15:52.100 KST [2945] LOG:  shutting down
2024-03-23 07:15:52.102 KST [2945] LOG:  checkpoint starting: shutdown immediate
2024-03-23 07:15:52.109 KST [2945] 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/1526B90, redo lsn=0/1526B90
2024-03-23 07:15:52.115 KST [2943] LOG:  database system is shut down
2024-03-23 07:15:52.239 KST [2961] LOG:  starting PostgreSQL 16.2 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 8.5.0 20210514 (Red Hat 8.5.0-20), 64-bit
2024-03-23 07:15:52.240 KST [2961] LOG:  listening on IPv6 address "::1", port 5432
2024-03-23 07:15:52.240 KST [2961] LOG:  listening on IPv4 address "127.0.0.1", port 5432
2024-03-23 07:15:52.244 KST [2961] LOG:  listening on Unix socket "/run/postgresql/.s.PGSQL.5432"
2024-03-23 07:15:52.247 KST [2961] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"
2024-03-23 07:15:52.252 KST [2965] LOG:  database system was shut down at 2024-03-23 07:15:52 KST
2024-03-23 07:15:52.260 KST [2961] LOG:  database system is ready to accept connections

 

 

참고용 로그 경로 찾는법

PG data_directory 확인

1
2
3
4
5
6
7
8
9
10
11
12
# su - postgres
$ echo $PGDATA
/var/lib/pgsql/16/data
 
또는
# su - postgres
$ psql
postgres=show data_directory;
     data_directory
------------------------
 /var/lib/pgsql/16/data
(1 row)

 

 

이 경로에 있는 log 디렉토리서 로그를 찾을수 있음

1
2
3
4
5
6
$ cd /var/lib/pgsql/16/data/log
$ ls -al
total 24
drwx-------  2 postgres postgres    32 Mar 23 06:36 .
drwx------. 20 postgres postgres  4096 Mar 23 07:38 ..
-rw-------.  1 postgres postgres 20398 Mar 23 07:48 postgresql-Sat.log

 

 

참고용 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://www.postgresql.org/docs/16/tutorial-start.html