본문 바로가기
WIKI 기술 지식 베이스

Backstage를 SQLite에서 PostgreSQL로 전환

원문 보기 위키 갱신

Backstage를 SQLite에서 PostgreSQL로 전환 (Switching Backstage from SQLite to PostgreSQL)

기본 @backstage/create-app 데이터베이스는 인메모리 데이터베이스인 SQLite입니다.

출처: 문서

본문

기본 @backstage/create-app 데이터베이스는 인메모리 데이터베이스인 SQLite로, 환경 설정이 필요 없어 초기 실험에 완벽합니다.

Backstage를 프로덕션에 배포할 준비가 되었거나 더 지속적인 개발 설정을 원한다면 Backstage 데이터베이스를 PostgreSQL로 전환할 수 있습니다. Backstage는 Knex 라이브러리를 사용하므로 데이터베이스 백엔드 간 전환이 상당히 쉽습니다.

PostgreSQL 설치 (Install PostgreSQL)

먼저 backend 패키지에 PostgreSQL을 추가하세요.

From your Backstage root directory

yarn --cwd packages/backend add pg

PostgreSQL 구성 추가 (Add PostgreSQL configuration)

다음으로 루트 폴더의 app-config.yaml을 수정해 백엔드에 PostgreSQL 구성을 추가하세요.

app-config.yaml

backend:  database:    client: better-sqlite3    connection: ':memory:'    # config options: https://node-postgres.com/apis/client    client: pg    connection:      host: ${POSTGRES_HOST}      port: ${POSTGRES_PORT}      user: ${POSTGRES_USER}      password: ${POSTGRES_PASSWORD}      # https://node-postgres.com/features/ssl      # you can set the sslmode configuration option via the `PGSSLMODE` environment variable      # see https://www.postgresql.org/docs/current/libpq-ssl.html Table 33.1. SSL Mode Descriptions (e.g. require)      # ssl:      #   ca: # if you have a CA file and want to verify it you can uncomment this section      #     $file: <file-path>/ca/server.crt

로컬 개발용 app-config.local.yaml이 있다면 거기에도 유사한 업데이트를 해야 합니다. Backstage를 시작하기 전에 POSTGRES_ 환경 변수를 설정하거나, ${...} 값을 제거하고 개발을 위해 실제 값을 직접 설정할 수 있습니다.

이제 Backstage 앱은 PostgreSQL 지원 데이터베이스로 시작할 준비가 되었습니다.

기본 PostgreSQL 데이터베이스 풀 구성 오버라이드 (Override default PostgreSQL Database Pool Configuration)

기본 연결 풀 설정을 오버라이드하려면 아래 구성을 사용하세요.

app-config.local.yaml

backend:  database:    client: better-sqlite3    connection: ':memory:'    # config options: https://node-postgres.com/apis/client    client: pg    connection:      host: ${POSTGRES_HOST}      port: ${POSTGRES_PORT}      user: ${POSTGRES_USER}      password: ${POSTGRES_PASSWORD}      # https://node-postgres.com/features/ssl      # you can set the sslmode configuration option via the `PGSSLMODE` environment variable      # see https://www.postgresql.org/docs/current/libpq-ssl.html Table 33.1. SSL Mode Descriptions (e.g. require)      # ssl:      #   ca: # if you have a CA file and want to verify it you can uncomment this section      #     $file: <file-path>/ca/server.crt    # Refer to Tarn docs for default values on PostgreSQL pool configuration - https://github.com/Vincit/tarn.js    knexConfig:      pool:        min: 3        max: 12        acquireTimeoutMillis: 60000        idleTimeoutMillis: 60000

단일 데이터베이스 사용 (Using a single database)

기본적으로 각 플러그인은 고유한 논리 데이터베이스를 갖게 되는데, 이는 설치하는 플러그인 전체에서 테이블 이름 충돌이 없도록 하고 이후의 다른 사용 사례를 위해 관심사를 분리하기 위함입니다. 단일 데이터베이스만 사용할 수 있는 제한이 있다면, 구성에서 client: pg와 함께 특수 옵션 pluginDivisionMode를 사용해 별도의 데이터베이스를 만드는 대신 별도의 PostgreSQL 스키마를 만들 수 있습니다.

다음 구성을 사용해 활성화할 수 있습니다.

backend:  database:    client: pg    pluginDivisionMode: schema # defaults to database, but changing this to schema means plugins will be given their own schema (in the specified/default database)

데이터베이스의 기존 스키마와 충돌을 피해야 한다면 모든 플러그인 스키마 이름에 접두사를 추가할 수 있습니다.

backend:  database:    client: pg    pluginDivisionMode: schema    schemaPrefix: 'backstage_' # defaults to empty string

그러면 backstage_catalog, backstage_auth 등으로 명명된 스키마가 생성됩니다. 결합된 스키마 이름은 63바이트를 초과할 수 없습니다.

Existing Deployments

기존 배포에서 schemaPrefix를 활성화하면 접두사가 붙은 새 스키마가 생성되며 기존 비접두사 스키마의 데이터는 마이그레이션되지 않습니다. 이 구성은 새 배포를 위한 것이거나 데이터베이스의 기존 스키마와 충돌을 피하기 위한 것입니다. 기존 Backstage 인스턴스에서 이를 활성화하면 데이터는 원래 비접두사 스키마에 남아 있고, Backstage는 새 접두사 스키마를 사용합니다.

더 알아보기 (Learn more)