DB (데이터베이스)/Postgresql (포스트그래)

[POSTRESQL] postgresql 포트 번호 변경 (리눅스)

뜽배 2021. 4. 2. 10:50
728x90
반응형

postgresql에서 default 포트 번호는 5432이다. 이 번호를 변경하는 방법을 설명해드리겠습니다.

 

 

1. postgresql 서비스 확인 및 이름 확인

[root@localhost ~]# systemctl status | grep post

 

postgresql-9.6.service

위의 사진과 같이 현재 올라온 서비스의 postgresql을 확인 할 수 있다.

여기서 서비스 이름을 기억해 둔다 (postgresql-9.6.service)

 

 

2. psql 접속해서 config_file 위치 확인

postgresql계정으로 변환 후 psql을 실행시킨다

[root@localhost ~]# su - postgres
[postgres@localhost ~]$ psql
SQL > show config_file;

결과값으로 postgresql.conf파일의 절대경로가 나온다

 

3. postgresql.conf 파일의 port번호 수정

해당 경로로 이동해서 vi 편집기로 postgresql.conf파일을 연다.

[postgres@localhost ~]$ vi /var/lib/pgsql/data/postgresql.conf

 

port 부분에 원하는 포트 번호를 입력한다.

해당 파일의 63번째 줄 부분에

#port=5432

라고 되어있을 것이다. 이 부분에서 #을 없앤다 ( 주석을 제거한다)

그리고 원하는 번호로 변경한다.

 

 

4. postgresql 서비스 재시작

 

root계정으로 변환 후 postgresql서비스를 재시작한다.

[root@localhost ~]# systemctl stop postgresql-9.6.service
[root@localhost ~]# systemctl start postgresql-9.6.service
728x90
반응형