summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2023-04-08 15:53:36 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2023-04-08 15:53:36 +0900
commit9114c8cb8e7d0bb0f686190d47c60591ac211f35 (patch)
tree153b2ca2f6f07a291704ea5a8b7a1e003655cce1
parent:art (diff)
downloadsharkey-9114c8cb8e7d0bb0f686190d47c60591ac211f35.tar.gz
sharkey-9114c8cb8e7d0bb0f686190d47c60591ac211f35.tar.bz2
sharkey-9114c8cb8e7d0bb0f686190d47c60591ac211f35.zip
feat(backend): support replication of postgresql
Resolve #10205
-rw-r--r--.config/docker_example.yml17
-rw-r--r--.config/example.yml17
-rw-r--r--.devcontainer/devcontainer.yml17
-rw-r--r--CHANGELOG.md2
-rw-r--r--chart/files/default.yml17
-rw-r--r--packages/backend/src/config.ts10
-rw-r--r--packages/backend/src/postgres.ts16
7 files changed, 96 insertions, 0 deletions
diff --git a/.config/docker_example.yml b/.config/docker_example.yml
index d93cc8b70e..af0a90dc95 100644
--- a/.config/docker_example.yml
+++ b/.config/docker_example.yml
@@ -51,6 +51,23 @@ db:
#extra:
# ssl: true
+dbReplications: false
+
+# You can configure any number of replicas here
+#dbSlaves:
+# -
+# host:
+# port:
+# db:
+# user:
+# pass:
+# -
+# host:
+# port:
+# db:
+# user:
+# pass:
+
# ┌─────────────────────┐
#───┘ Redis configuration └─────────────────────────────────────
diff --git a/.config/example.yml b/.config/example.yml
index b61ed14809..57e2b56b78 100644
--- a/.config/example.yml
+++ b/.config/example.yml
@@ -51,6 +51,23 @@ db:
#extra:
# ssl: true
+dbReplications: false
+
+# You can configure any number of replicas here
+#dbSlaves:
+# -
+# host:
+# port:
+# db:
+# user:
+# pass:
+# -
+# host:
+# port:
+# db:
+# user:
+# pass:
+
# ┌─────────────────────┐
#───┘ Redis configuration └─────────────────────────────────────
diff --git a/.devcontainer/devcontainer.yml b/.devcontainer/devcontainer.yml
index 1350e70157..2af306e3da 100644
--- a/.devcontainer/devcontainer.yml
+++ b/.devcontainer/devcontainer.yml
@@ -51,6 +51,23 @@ db:
#extra:
# ssl: true
+dbReplications: false
+
+# You can configure any number of replicas here
+#dbSlaves:
+# -
+# host:
+# port:
+# db:
+# user:
+# pass:
+# -
+# host:
+# port:
+# db:
+# user:
+# pass:
+
# ┌─────────────────────┐
#───┘ Redis configuration └─────────────────────────────────────
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 615a3aad3c..2486a7e54f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -38,6 +38,8 @@
- Add Minimizing ("folding") of windows
### Server
+- PostgreSQLのレプリケーション対応
+ - 設定ファイルの `dbReplications` および `dbSlaves` にて設定できます
- イベント用Redisを別サーバーに分離できるように
- ジョブキュー用Redisを別サーバーに分離できるように
- サーバーの全体的なパフォーマンスを向上
diff --git a/chart/files/default.yml b/chart/files/default.yml
index 1d8e5b490a..1888669245 100644
--- a/chart/files/default.yml
+++ b/chart/files/default.yml
@@ -72,6 +72,23 @@ db:
#extra:
# ssl: true
+dbReplications: false
+
+# You can configure any number of replicas here
+#dbSlaves:
+# -
+# host:
+# port:
+# db:
+# user:
+# pass:
+# -
+# host:
+# port:
+# db:
+# user:
+# pass:
+
# ┌─────────────────────┐
#───┘ Redis configuration └─────────────────────────────────────
diff --git a/packages/backend/src/config.ts b/packages/backend/src/config.ts
index fd2b83cf2a..1443e63385 100644
--- a/packages/backend/src/config.ts
+++ b/packages/backend/src/config.ts
@@ -25,6 +25,16 @@ export type Source = {
disableCache?: boolean;
extra?: { [x: string]: string };
};
+ dbReplications?: boolean;
+ dbSlaves?: {
+ host: string;
+ port: number;
+ db: string;
+ user: string;
+ pass: string;
+ disableCache?: boolean;
+ extra?: { [x: string]: string };
+ }[];
redis: {
host: string;
port: number;
diff --git a/packages/backend/src/postgres.ts b/packages/backend/src/postgres.ts
index efeca46b49..bb21ed827e 100644
--- a/packages/backend/src/postgres.ts
+++ b/packages/backend/src/postgres.ts
@@ -200,6 +200,22 @@ export function createPostgresDataSource(config: Config) {
statement_timeout: 1000 * 10,
...config.db.extra,
},
+ replication: config.dbReplications ? {
+ master: {
+ host: config.db.host,
+ port: config.db.port,
+ username: config.db.user,
+ password: config.db.pass,
+ database: config.db.db,
+ },
+ slaves: config.dbSlaves!.map(rep => ({
+ host: rep.host,
+ port: rep.port,
+ username: rep.user,
+ password: rep.pass,
+ database: rep.db,
+ })),
+ } : undefined,
synchronize: process.env.NODE_ENV === 'test',
dropSchema: process.env.NODE_ENV === 'test',
cache: !config.db.disableCache && process.env.NODE_ENV !== 'test' ? { // dbをcloseしても何故かredisのコネクションが内部的に残り続けるようで、テストの際に支障が出るため無効にする(キャッシュも含めてテストしたいため本当は有効にしたいが...)