오픈소스의 일상

#10. PostgRest 설치 및 확인 본문

오픈소스/PostgreSQL

#10. PostgRest 설치 및 확인

실버카미 2022. 1. 6. 09:31

1. 설치

참고 : https://postgrest.org/en/stable/tutorials/tut0.html#step-3-install-postgrest

 

Tutorial 0 - Get it Running — PostgREST 9.0.0 documentation

Welcome to PostgREST! In this pre-tutorial we’re going to get things running so you can create your first simple API. PostgREST is a standalone web server which turns a PostgreSQL database into a RESTful API. It serves an API that is customized based on

postgrest.org

참고 : https://github.com/PostgREST/postgrest/releases/tag/v9.0.0

 

Release v9.0.0 · PostgREST/postgrest

Added #1783, Include partitioned tables into the schema cache. Allows embedding, UPSERT, INSERT with Location response, OPTIONS request and OpenAPI support for partitioned tables - @laurenceisla #...

github.com

[root@flas /]# cd /home
[root@flas home]# wget https://github.com/PostgREST/postgrest/releases/download/v9.0.0/postgrest-v9.0.0-linux-static-x64.tar.xz
...

HTTP request sent, awaiting response... 200 OK
Length: 3251052 (3.1M) [application/octet-stream]
Saving to: ‘postgrest-v9.0.0-linux-static-x64.tar.xz’

100%[==================================================================>] 3,251,052   --.-K/s   in 0.02s

2022-01-06 09:26:44 (140 MB/s) - ‘postgrest-v9.0.0-linux-static-x64.tar.xz’ saved [3251052/3251052]

--압축풀기
[root@flas home]# tar xJf postgrest-v9.0.0-linux-static-x64.tar.xz

--실행파일 생성확인
[root@flas home]# ll
total 19100
-rwxr-xr-x 1 1001  121 16305296 Nov 27 05:04 postgrest

--실행파일 실행
--정상적인 동작 확인

[root@flas home]# ./postgrest
Usage: postgrest [-e|--example] [--dump-config | --dump-schema] FILENAME
  PostgREST 9.0.0 / create a REST API to an existing Postgres database

Available options:
  -h,--help                Show this help text
  -e,--example             Show an example configuration file
  --dump-config            Dump loaded configuration and exit
  --dump-schema            Dump loaded schema as JSON and exit (for debugging,
                           output structure is unstable)
  FILENAME                 Path to configuration file (optional with PGRST_
                           environment variables)

To run PostgREST, please pass the FILENAME argument or set PGRST_ environment
variables.

--Path폴더로 이동
[root@flas home]# mv /home/postgrest /usr/local/bin

2. 스키마, 계정 및 권한 설정

create schema api;

create table api.todos (
  id serial primary key,
  done boolean not null default false,
  task text not null,
  due timestamptz
);

insert into api.todos (task) values
  ('finish tutorial 0'), ('pat self on back');
  
create role web_anon nologin;
grant usage on schema api to web_anon;
grant select on api.todos to web_anon;

create role authenticator noinherit login password 'mysecretpassword';
grant web_anon to authenticator;

3. 접속정보 및 자동실행 설정

-- turorial.conf 생성
db-uri = "postgres://authenticator:mysecretpassword@localhost:5432/postgres"
db-schema = "api"
db-anon-role = "web_anon"

-- 서버 부팅시 자동실행
[root@flas bin]# cd /etc/rc.d
[root@flas rc.d]# vi rc.local
...
cd /usr/local/bin;
./postgrest tutorial.conf;

--재부팅
[root@flas rc.d]# reboot

4. 결과확인

 

Token 기능은 기본셋팅이 완료되면 작성예정

 

728x90