프린트 하기

OS환경 : Oracle Linux 8.4 (64bit)

 

DB 환경 : PostgreSQL 16

 

에러 : bash: pg_ctl: command not found...

PostgreSQL 설치 후 pg_ctl 명령을 실행하려할때 발생한 메세지

1
2
$ pg_ctl status
bash: pg_ctl: command not found...

 

 

해결 방법 : profile에 postgresql bin PATH 설정

postgres 프로세스 확인

1
2
3
4
5
6
7
8
9
10
11
12
$ ps -ef | grep postgres
postgres    1228       1  0 06:02 ?        00:00:00 /usr/pgsql-16/bin/postgres -/var/lib/pgsql/16/data/
postgres    1254    1228  0 06:02 ?        00:00:00 postgres: logger
postgres    1255    1228  0 06:02 ?        00:00:00 postgres: checkpointer
postgres    1256    1228  0 06:02 ?        00:00:00 postgres: background writer
postgres    1262    1228  0 06:02 ?        00:00:00 postgres: walwriter
postgres    1263    1228  0 06:02 ?        00:00:00 postgres: autovacuum launcher
postgres    1264    1228  0 06:02 ?        00:00:00 postgres: logical replication launcher
root        1784    1716  0 06:03 pts/0    00:00:00 su - postgres
postgres    1785    1784  0 06:03 pts/0    00:00:00 -bash
postgres    2204    1785  0 06:28 pts/0    00:00:00 ps -ef
postgres    2205    1785  0 06:28 pts/0    00:00:00 grep --color=auto postgres

/usr/pgsql-16/bin/에 bin(실행파일) 폴더가 존재함

 

 

postgres 유저의 .bash_profile 에 PATH 설정

하려고 .bash_profile 을 cat으로 확인했는데 이렇게 주석이 달려있음

1
2
3
4
5
6
7
8
9
10
11
12
$ cat .bash_profile
-/etc/profile ] && source /etc/profile
PGDATA=/var/lib/pgsql/16/data
export PGDATA
If you want to customize your settings,
Use the file below. This is not overridden
by the RPMS.
-/var/lib/pgsql/.pgsql_profile ] && source /var/lib/pgsql/.pgsql_profile
구글 번역
# 설정을 맞춤설정하고 싶다면,
# 아래 파일을 사용하세요. 이는 재정의되지 않습니다.
# RPMS를 이용해서

 

 

여기 설명한대로 /var/lib/pgsql/.pgsql_profile 파일 수정 후 저장

1
2
$ vi /var/lib/pgsql/.pgsql_profile
export PATH=$PATH:/usr/pgsql-16/bin;

 

 

profile 적용

1
$ source /var/lib/pgsql/.pgsql_profile

 

 

pg_ctl 명령 재시도

1
2
3
$ pg_ctl status
pg_ctl: server is running (PID: 1228)
/usr/pgsql-16/bin/postgres "-D" "/var/lib/pgsql/16/data/"

정상적으로 명령어가 수행됨

 

 

참고용 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/>

 

 

원인 : postgres 유저에 pg_ctl에 대한 PATH가 설정되어 있지 않아 발생한 문제

postgres 유저에 pg_ctl에 대한 PATH가 설정되어 있지 않아 발생한 문제

 

 

참조 : 

https://askubuntu.com/questions/385416/pg-ctl-command-not-found-what-package-has-this-command