728x90
반응형
SMALL
728x90
반응형
LIST
728x90
반응형
SMALL
서버에 postgresql 설치했으면, 외부 클라이언트에서 서버에 접속할 수 있도록 설정을 해주어야 한다.
서버가 Ubuntu일 경우와 Windows일 경우 설정하는 방법,

설정 후 DBeaver에서 접속하는 방법을 알아보도록 하자.

 

■ 서버가 Ubuntu일 경우

1. postgres에 접속한다.

pmk@pmk-virtual-machine:~$ sudo -i -u postgres

 

2. pg_hba.conf 파일 위치를 확인한다.

postgres@pmk-virtual-machine:~$ psql

postgres=# show data_directory;    # 위치 출력 : /var/lib/postgresql/14/main

 

3. pg_hba.conf 파일 내용을 수정한다. (0.0.0.0/0으로 수정)

postgres@pmk-virtual-machine:~$ vi /etc/postgresql/14/main/pg_hba.conf

IPv4 변경

 

5. postgresql.conf 파일 내용을 수정한다.

  - listen_addresses = '*'로 수정하고, 앞에 # 표시도 제거(주석 해제)

postgres@pmk-virtual-machine:~$ vi /etc/postgresql/14/main/postgresql.conf

listen_addresses 변경

 

6. 수정 후 postgres 계정에서 나온다.

postgres@pmk-virtual-machine:~$ exit    # 실행하면 logout, There are stopped jobs. 표시

postgres@pmk-virtual-machine:~$ exit    # 실행하면 logout, 마지막에 Vim: Finished. 표시

 

7. postgresql 서비스를 재실행한다.

pmk@pmk-virtual-machine:~$ sudo service postgresql restart

 

8. DBeaver를 실행하여 Host 부분을 서버 IP주소로 변경하고 Test Connection.. 클릭하면 Connected 메시지와 함께 팝업이 뜨면 접속 성공!

DBeaver 접속

참고) postgres 비번을 모를 경우 설정방법

pmk@pmk-virtual-machine:~$ sudo -i -u postgres

postgres@pmk-virtual-machine:~$ psql

postgres=# alter user postgres with password 'postgres';    # alter user 사용자 with password '비밀번호'

 

■ 서버가 Windows일 경우

1. C:\Program Files\PostgreSQL\15\data 폴더 안에 pg_hba 파일을 수정한다. (경로는 다를 수 있음)

pg_hba 파일

2. C:\Program Files\PostgreSQL\15\data 폴더 안에 postgresql 파일을 수정한다. (경로는 다를 수 있음)

postgresql 파일

3. postgresql 서비스를 재실행한다.

postgresql 서비스를 재실행

 

4. DBeaver를 실행하여 앞서했던 방식과 동일하게 접속한다.

728x90
반응형
LIST

'Postgresql' 카테고리의 다른 글

postgresql 설치 방법 - Windows  (0) 2023.07.01
postgresql 삭제 방법 - Ubuntu22.04.2.LTS  (0) 2023.06.30
postgresql 설치 방법 - Ubuntu22.04.2.LTS  (0) 2023.06.25
728x90
반응형
SMALL

■ postgresql 다운로드

1. postgresql 다운로드 : https://www.postgresql.org/download/

2. 아래 Windows 클릭 후, Download the installer 클릭한다.

3. 원하는 버전을 클릭하여 다운로드한다. (필자는 15.3을 선택)

 

■ postgresql 설치

1. postgresql 다운로드 파일을 클릭하여 설치를 진행한다.

2. 아래 이미지 순서대로 설치한다.

3. postgreSQL Server : PostgreSQL 서버 설치

    pgAdmin 4 : postgresql 서버에 접속하기 위한 클라이언트 프로그램

    Stack Builder : postgresql의 추가적인 유틸리티 프로그램

    Command Line Tools : 말 그대로 Command Line Tools로 Command Line으로 postgresql로 접속할 수 있다.

4. password는 초기에 postgresql 접속할 때 사용한다.

5. postgresql port는 기본적으로 5432를 사용하지만, 변경해도 무방하다.

6. Locale은 Korean, Korea로 변경한다. (데이터에 한글이 들어올 수 있으므로..)

    Locale 설정은 아래와 같은 영향을 준다.

  - 대소문자 구분

  - 문자열 정렬

  - like문에서 인덱스 사용여부 결정

7. 설치가 완료되면 작업 관리자를 실행하여 postgresql 서버가 실행되고 있는지 확인한다.

postgresql 서버 실행 확인

■ postgresql 실행

1. 클라이언트 프로그램을 사용하여 postgresql에 접속한다.

    postgresql을 처음 설치할 때, pgAdmin4 설치 옵션 체크를 하고 설치를 하였기 때문에 별도로 다운로드하지 않아도 된다.

    pgAdmin4를 실행하여 postgresql에 접속한다. (접속 비밀번호는 설치할 때 설정했던 비밀번호)

pgAdmin4 실행화면

2. postgresql 클라이언트 프로그램은 pgAdmin4 말고도 DBeaver와 같은 많은 프로그램이 있기 때문에, 다른 클라이언트 프로그램으로 접속하려

    면 추가적인 설치를 통하여 사용하면 된다. (DBeaver 추천)

 

참고) postgresql 외부 접속 방법 : https://200-rush.tistory.com/entry/PostgresqlOutConnect

728x90
반응형
LIST
728x90
반응형
SMALL

■ postgresql 삭제방법

1. postgresql 서비스 상태

pmk@pmk-virtual-machine:~$ systemctl list-unit-files postgresql*

2. postgresql 서비스 중지

pmk@pmk-virtual-machine:~$ sudo systemctl stop postgresql.service

 

3. postgresql 서비스 비활성화

pmk@pmk-virtual-machine:~$ sudo systemctl disable postgresql.service    # 활성화는 disable 대신 enable

4. postgresql 삭제

pmk@pmk-virtual-machine:~$ sudo rm -rf /var/lib/postgresql    # postgresql 디렉터리 삭제

pmk@pmk-virtual-machine:~$ sudo apt remove "postgresql*"    # postgresql 패키지 삭제

pmk@pmk-virtual-machine:~$ sudo apt --purge remove "postgresql*"    # postgresql 패키지 및 패키지의 환경설정 삭제

pmk@pmk-virtual-machine:~$ sudo apt autoremove    # 의존성이 없는 패키지 삭제

 

5. postgresql 설치된 패키지 확인

pmk@pmk-virtual-machine:~$ dpkg -l | grep postgres*    # 아무것도 조회 안되면 삭제가 완료된 것

728x90
반응형
LIST
728x90
반응형
SMALL

■ postgresql 설치방법

1. postgresql 설치가능한 버전 확인

pmk@pmk-virtual-machine:~$ apt show postgresql

설치 가능한 postgresql 버전

2. 패키지 최신화

pmk@pmk-virtual-machine:~$ sudo apt update    # 설치 가능한 패키지 최신화

pmk@pmk-virtual-machine:~$ sudo apt upgrade    # 패키지 업그레이드

 

3. 버전을 확인했으면 postgresql 설치 (2개 모두 postgresql 설치 명령어로 하나만 선택하여 실행한다.)

pmk@pmk-virtual-machine:~$ sudo apt install postgresql postgresql-contrib

pmk@pmk-virtual-machine:~$ sudo apt install postgresql

(참고)

- postgresql-contrib 설치여부 (추가 유틸리니 및 기능추가 설치여부)

- 어떤 것을 설치해도 무방

- sudo apt install -y postgresql    # -y를 써주면 설치하면서 나오는 yes/no를 무조건 yes로 설치한다.

- 다음과 같은 메시지와 같이 설치 안될 때 재부팅

  E: Could not get lock /var/cache/apt/archives/lock. It is held by process 3072 (unattended-upgr)

  N: Be aware that removing the lock file is not a solution and may break your system.

  E: Unable to lock directory /var/cache/apt/archives/

 

4. postgresql 상태확인 (2개 모두 상태확인 명령어)

pmk@pmk-virtual-machine:~$ service postgresql status

pmk@pmk-virtual-machine:~$ systemctl status postgresql

 

5. postgresql 프로세스 확인

pmk@pmk-virtual-machine:~$ ps -ef | grep post    # 약 8개 정도 프로세스 확인

 

6. postgresql 리스너 확인

pmk@pmk-virtual-machine:~$ ss -lntp    # 5432 postgresql 포트 확인

 

7. postgresql 시작

pmk@pmk-virtual-machine:~$ sudo service postgresql start    # 설치되면 자동으로 active 상태임

 

8. postgresql 접속

pmk@pmk-virtual-machine:~$ sudo -i -u postgres    # -i(로그인 옵션) -u(유저 옵션)

postgres@pmk-virtual-machine:~$ psql

 

9. 사용자 확인 등 명령어

postgres=# \du    # 사용자 확인

postgres=# \l    # DB 확인

postgres=# create database pmk_test;    # pmk_test database 생성, 만들어졌으면 CREATE DATABASE라는 문구 표시

postgres=# \c pmk_test;    # pmk_test database로 이동 (You are now connected to database "pmk_test" as user "postgres")

pmk_test=# create table computer(brand varchar(100), year varchar(8));    # computer table, 칼럼 brand, year 생성, 만들어졌으면 CREATE TABLE라는 문구 표시

pmk_test=# insert into computer(brand, year) values('samsung', '20230625');    # 데이터 insert

pmk_test=# select * from computer;    # 데이터 조회

 

10. postgres 나오기

postgres=# \q

postgres@pmk-virtual-machine:~$ exit

 

참고)

postgresql 삭제방법 : https://200-rush.tistory.com/entry/UbuntuPostgresqlDelete

postgresql 외부 접속 방법 : https://200-rush.tistory.com/entry/PostgresqlOutConnect

728x90
반응형
LIST

+ Recent posts