Skip to content

Commit b9c8419

Browse files
committed
(WIP) feat: deploy pgbouncer using system manager
1 parent fc77a26 commit b9c8419

File tree

7 files changed

+52
-153
lines changed

7 files changed

+52
-153
lines changed

ansible/playbook.yml

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
dest: "00-schema.sql",
1414
}
1515
- { source: "stat_extension.sql", dest: "01-extension.sql" }
16-
16+
1717
environment:
1818
PATH: /usr/lib/postgresql/bin:{{ ansible_env.PATH }}
1919

@@ -29,13 +29,6 @@
2929
- name: Install Postgres from source
3030
import_tasks: tasks/setup-postgres.yml
3131

32-
- name: Install PgBouncer
33-
import_tasks: tasks/setup-pgbouncer.yml
34-
tags:
35-
- install-pgbouncer
36-
- install-supabase-internal
37-
when: debpkg_mode or nixpkg_mode
38-
3932
- name: Install WAL-G
4033
import_tasks: tasks/setup-wal-g.yml
4134
when: debpkg_mode or nixpkg_mode or stage2_nix
@@ -46,7 +39,7 @@
4639
- install-gotrue
4740
- install-supabase-internal
4841
when: debpkg_mode or nixpkg_mode
49-
42+
5043
- name: Install PostgREST
5144
import_tasks: tasks/setup-postgrest.yml
5245
tags:
@@ -96,7 +89,7 @@
9689
src: files/apt_periodic
9790
dest: /etc/apt/apt.conf.d/10periodic
9891
when: debpkg_mode or nixpkg_mode
99-
92+
10093
- name: Transfer init SQL files
10194
copy:
10295
src: files/{{ item.source }}
@@ -131,13 +124,13 @@
131124
tags:
132125
- install-supabase-internal
133126
when: debpkg_mode or stage2_nix
134-
127+
135128
- name: Finalize AMI
136129
import_tasks: tasks/finalize-ami.yml
137130
tags:
138131
- install-supabase-internal
139132
when: debpkg_mode or nixpkg_mode
140-
133+
141134
- name: Enhance fail2ban
142135
import_tasks: tasks/setup-fail2ban.yml
143136
when: debpkg_mode or nixpkg_mode
@@ -218,7 +211,7 @@
218211
systemctl stop postgresql.service
219212
when: stage2_nix
220213

221-
- name: Remove osquery
214+
- name: Remove osquery
222215
become: yes
223216
shell: |
224217
sudo -u ubuntu bash -c ". /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh && nix profile remove osquery"

ansible/tasks/setup-pgbouncer.yml

Lines changed: 0 additions & 135 deletions
This file was deleted.

ansible/vars.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ postgres_release:
1313
postgres17: "17.6.1.003-nixpkgs-4"
1414
postgres15: "15.14.1.003-nixpkgs-4"
1515

16-
# Non Postgres Extensions
17-
pgbouncer_release: "1.19.0"
18-
pgbouncer_release_checksum: sha256:af0b05e97d0e1fd9ad45fe00ea6d2a934c63075f67f7e2ccef2ca59e3d8ce682
19-
2016
# The checksum can be found under "Assets", in the GitHub release page for each version.
2117
# The binaries used are: ubuntu-aarch64 and linux-static.
2218
# https://github.com/PostgREST/postgrest/releases

nix/systemConfigs.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
{ self, inputs, ... }:
22
let
33
mkModules = system: [
4+
self.systemModules.pgbouncer
45
({
56
services.nginx.enable = true;
67
nixpkgs.hostPlatform = system;
8+
supabase.services.pgbouncer.enable = true;
79
})
810
];
911

nix/systemModules/default.nix

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
{
55
imports = [ ./tests ];
66
flake = {
7-
systemModules = { };
7+
systemModules = {
8+
pgbouncer = ./pgbouncer.nix;
9+
};
810
};
911
}

nix/systemModules/pgbouncer.nix

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
lib,
3+
nixosModulesPath,
4+
system,
5+
config,
6+
...
7+
}:
8+
let
9+
cfg = config.supabase.services.pgbouncer;
10+
in
11+
{
12+
imports = map (path: nixosModulesPath + path) [
13+
"/services/databases/pgbouncer.nix"
14+
];
15+
16+
options = {
17+
supabase.services.pgbouncer = {
18+
enable = lib.mkEnableOption "Whether to enable PostgreSQL connection pooler.";
19+
};
20+
};
21+
22+
config = lib.mkIf cfg.enable {
23+
services.pgbouncer = {
24+
enable = true;
25+
package =
26+
(import (fetchTarball {
27+
# pgbouncer v1.19.0
28+
url = "https://github.com/NixOS/nixpkgs/archive/db7534df5fb9b7dfd3404ec26d977997ff2cc1a0.tar.gz";
29+
sha256 = "sha256:0lrsnz80a3jfjdyjs4njipvmq34w6wjr5ql645z1l1s9f9cyvk0g";
30+
}) { system = system; }).pgbouncer;
31+
};
32+
systemd.services.pgbouncer = {
33+
wantedBy = lib.mkForce [
34+
"system-manager.target"
35+
];
36+
};
37+
};
38+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
def test_pgbouncer_service(host):
2+
assert host.service("pgbouncer.service").is_valid
3+
assert host.service("pgbouncer.service").is_running

0 commit comments

Comments
 (0)