출처: https://bumcrush.tistory.com/182 [맑음때때로 겨울]
반응형

환경 Ubuntu 18.04

PostgreSQL-13

 

※설치된 패키지 목록

postgresql/bionic-pgdg,bionic-pgdg,now 13+226.pgdg18.04+1 all [installed]
postgresql-13/bionic-pgdg,now 13.4-1.pgdg18.04+1 amd64 [installed,automatic]
postgresql-client-13/bionic-pgdg,now 13.4-1.pgdg18.04+1 amd64 [installed,automatic]
postgresql-client-common/bionic-pgdg,bionic-pgdg,now 226.pgdg18.04+1 all [installed,automatic]
postgresql-common/bionic-pgdg,bionic-pgdg,now 226.pgdg18.04+1 all [installed,automatic]
postgresql-contrib/bionic-pgdg,bionic-pgdg,now 13+226.pgdg18.04+1 all [installed]

 

1. pgagent 패키지를 설치한다 ( Version : 4.0.0 )

sudo apt update
sudo apt install pgagent

2.1 pgAgent 데이터 베이스에 설치

sudo su postgres
psql

postgres 유저로 postgreSQL 접근 한다.

 

2.2 pgAgent 데이터 베이스 설치

CREATE EXTENSION pgagent;
CREATE EXTENSION plpgsql;

example 데이터베이스를 생성하고 여기에 관련된 Scheduler 를 실행하고 싶어서 쿼리를 'example' 데이터 베이스 접속후 생성했는데 실행 되지 않았다.

결국 실행 되는건 postgres 기본적으로 주어지는 데이터 베이스안에 pgAgent 잡에 관련한 스키마라던가 이런것들이 생성된다.

여기서는 pgagent 라는 스키마를 postgres 데이터 베이스 안에 생성하는 방법이다.

그냥 postgres에서 쿼리 날리면 된다.

 

3. USER 생성

CREATE USER "pgagent" WITH
  LOGIN
  NOSUPERUSER
  INHERIT
  NOCREATEDB
  NOCREATEROLE
  NOREPLICATION
  encrypted password 'securepassword';

GRANT USAGE ON SCHEMA pgagent TO pgagent;
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA pgagent TO pgagent;
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA pgagent TO pgagent;

'securepassword' 여기에 사용하고 싶은 비밀번호 입력하면된다.

USER는 안만들어도 되는데 보안문제로 사용한다고 한다.

여기서 Super유저 권한을 안주는데 이러면 나중에 스키마에 접근권한이 없어서 Insert 하면 Fail 나온다.

-> 모르면 그냥 일단 따라서 만들어 놓자. 

 

4. .pgpass 생성 (중요 ★★★★★★★★★★★★★★★★★★)

pgagent 데몬이 안돌아가서 일주일동안 해맷는데 문제는 이놈이다.

sudo su - postgres
echo 127.0.0.1:5432:*:pgagent:securepassword >> ~/.pgpass
chmod 600 ~/.pgpass
chown postgres:postgres ~/.pgpass

.pgpass 위치는 home 위치에다가 만들면된다. 우분투 접속시 시작 경로

securepassword 는 위에서 만든 계정의 비밀번호 입력한다 

(※주의사항 securepassword 시 ' ' 작은따옴표로 감싸야 한다. 안그러면 특수문자 입력시 문자열 다르게입력됨)

 

.pgpass 를 만들고

cd ~
nano .pgpass

편집기로 열어서 잘들어갔나 확인한다.

안들어갔으면 편집기에서 수정해도 된다.

 

5. pgAgent 데몬실행 (중요 ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★)

일주일동안 삽질한게 4번 pgpass 랑 pgAgent 데몬실행 여부 합작품.

pgAgent 데몬을 켜야지만 생성해놓은 스케쥴러가 돌아간다.

sudo su - postgres
pgagent hostaddr=127.0.0.1 dbname=postgres user=pgagent

 

아까 우리는 postgres 데이터 베이스에 Extention 을 만들었고 pgagent 계정으로 Demon 을 실행 할거다.

 

하고 ps -al 해서 pgagent 프로세스 돌아가나 확인한다.

 

여기까지만 하면 Scheduler 사용할준비 끝.

 

2탄에는 pgAdmin 설치해서 스케쥴러 등록하는 방법을 알아보자.

반응형

+ Recent posts