Skip to content

Commit e710cac

Browse files
committed
feat: upgrade pgbouncer
1 parent 646bde8 commit e710cac

File tree

5 files changed

+113
-44
lines changed

5 files changed

+113
-44
lines changed

ansible/playbook.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
tags:
3535
- install-pgbouncer
3636
- install-supabase-internal
37-
when: debpkg_mode or nixpkg_mode
37+
when: debpkg_mode or nixpkg_mode or stage2_nix
3838

3939
- name: Install WAL-G
4040
import_tasks: tasks/setup-wal-g.yml

ansible/tasks/setup-pgbouncer.yml

Lines changed: 61 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,53 @@
11
# PgBouncer
2-
- name: PgBouncer - download & install dependencies
3-
apt:
4-
pkg:
5-
- build-essential
6-
- libssl-dev
7-
- pkg-config
8-
- libevent-dev
9-
- libsystemd-dev
10-
update_cache: yes
11-
cache_valid_time: 3600
12-
13-
- name: PgBouncer - download latest release
14-
get_url:
15-
url: "https://www.pgbouncer.org/downloads/files/{{ pgbouncer_release }}/pgbouncer-{{ pgbouncer_release }}.tar.gz"
16-
dest: /tmp/pgbouncer-{{ pgbouncer_release }}.tar.gz
17-
checksum: "{{ pgbouncer_release_checksum }}"
18-
timeout: 60
19-
20-
- name: PgBouncer - unpack archive
21-
unarchive:
22-
remote_src: yes
23-
src: /tmp/pgbouncer-{{ pgbouncer_release }}.tar.gz
24-
dest: /tmp
25-
become: yes
26-
27-
- name: PgBouncer - configure
28-
shell:
29-
cmd: "./configure --prefix=/usr/local --with-systemd"
30-
chdir: /tmp/pgbouncer-{{ pgbouncer_release }}
31-
become: yes
32-
33-
- name: PgBouncer - build
34-
make:
35-
chdir: /tmp/pgbouncer-{{ pgbouncer_release }}
36-
become: yes
37-
38-
- name: PgBouncer - install
39-
make:
40-
chdir: /tmp/pgbouncer-{{ pgbouncer_release }}
41-
target: install
42-
become: yes
2+
# - name: PgBouncer - download & install dependencies
3+
# apt:
4+
# pkg:
5+
# - build-essential
6+
# - libssl-dev
7+
# - pkg-config
8+
# - libevent-dev
9+
# - libsystemd-dev
10+
# update_cache: yes
11+
# cache_valid_time: 3600
12+
13+
# - name: PgBouncer - download latest release
14+
# get_url:
15+
# url: "https://www.pgbouncer.org/downloads/files/{{ pgbouncer_release }}/pgbouncer-{{ pgbouncer_release }}.tar.gz"
16+
# dest: /tmp/pgbouncer-{{ pgbouncer_release }}.tar.gz
17+
# checksum: "{{ pgbouncer_release_checksum }}"
18+
# timeout: 60
19+
20+
# - name: PgBouncer - unpack archive
21+
# unarchive:
22+
# remote_src: yes
23+
# src: /tmp/pgbouncer-{{ pgbouncer_release }}.tar.gz
24+
# dest: /tmp
25+
# become: yes
26+
27+
# - name: PgBouncer - configure
28+
# shell:
29+
# cmd: "./configure --prefix=/usr/local --with-systemd"
30+
# chdir: /tmp/pgbouncer-{{ pgbouncer_release }}
31+
# become: yes
32+
33+
# - name: PgBouncer - build
34+
# make:
35+
# chdir: /tmp/pgbouncer-{{ pgbouncer_release }}
36+
# become: yes
37+
38+
# - name: PgBouncer - install
39+
# make:
40+
# chdir: /tmp/pgbouncer-{{ pgbouncer_release }}
41+
# target: install
42+
# become: yes
4343

4444
- name: Create pgbouncer user
4545
user:
4646
name: pgbouncer
4747
shell: /bin/false
4848
comment: PgBouncer user
4949
groups: postgres,ssl-cert
50+
when: nixpkg_mode
5051

5152
- name: PgBouncer - create a directory if it does not exist
5253
file:
@@ -55,6 +56,7 @@
5556
owner: pgbouncer
5657
group: pgbouncer
5758
mode: '0700'
59+
when: nixpkg_mode
5860

5961
- name: PgBouncer - create a directory if it does not exist
6062
file:
@@ -65,6 +67,7 @@
6567
mode: '0775'
6668
with_items:
6769
- '/etc/pgbouncer-custom'
70+
when: nixpkg_mode
6871

6972
- name: create placeholder config files
7073
file:
@@ -77,59 +80,75 @@
7780
- 'generated-optimizations.ini'
7881
- 'custom-overrides.ini'
7982
- 'ssl-config.ini'
83+
when: nixpkg_mode
8084

8185
- name: PgBouncer - adjust pgbouncer.ini
8286
copy:
8387
src: files/pgbouncer_config/pgbouncer.ini.j2
8488
dest: /etc/pgbouncer/pgbouncer.ini
8589
owner: pgbouncer
8690
mode: '0700'
91+
when: nixpkg_mode
8792

8893
- name: PgBouncer - create a directory if it does not exist
8994
file:
9095
path: /etc/pgbouncer/userlist.txt
9196
state: touch
9297
owner: pgbouncer
9398
mode: '0700'
94-
99+
when: nixpkg_mode
100+
95101
- name: import /etc/tmpfiles.d/pgbouncer.conf
96102
template:
97103
src: files/pgbouncer_config/tmpfiles.d-pgbouncer.conf.j2
98104
dest: /etc/tmpfiles.d/pgbouncer.conf
99105
become: yes
106+
when: nixpkg_mode
100107

101108
- name: PgBouncer - By default allow ssl connections.
102109
become: yes
103110
copy:
104111
dest: /etc/pgbouncer-custom/ssl-config.ini
105112
content: |
106113
client_tls_sslmode = allow
114+
when: nixpkg_mode
107115

108116
- name: Grant pg_hba and pgbouncer grp perm for adminapi updates
109117
shell: |
110118
chmod g+w /etc/postgresql/pg_hba.conf
111119
chmod g+w /etc/pgbouncer-custom/ssl-config.ini
120+
when: nixpkg_mode
112121

113122
# Add fail2ban filter
114123
- name: import jail.d/pgbouncer.conf
115124
template:
116125
src: files/fail2ban_config/jail-pgbouncer.conf.j2
117126
dest: /etc/fail2ban/jail.d/pgbouncer.conf
118127
become: yes
128+
when: nixpkg_mode
119129

120130
- name: import filter.d/pgbouncer.conf
121131
template:
122132
src: files/fail2ban_config/filter-pgbouncer.conf.j2
123133
dest: /etc/fail2ban/filter.d/pgbouncer.conf
124134
become: yes
135+
when: nixpkg_mode
125136

126137
# Add systemd file for PgBouncer
127138
- name: PgBouncer - import postgresql.service
128139
template:
129140
src: files/pgbouncer_config/pgbouncer.service.j2
130141
dest: /etc/systemd/system/pgbouncer.service
131142
become: yes
143+
when: nixpkg_mode
144+
145+
- name: install pgbouncer from supabase nix binary cache
146+
become: yes
147+
shell: |
148+
sudo -u pgbouncer bash -c ". /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh && nix profile install github:supabase/postgres/{{ git_commit_sha }}#pgbouncer"
149+
when: stage2_nix
132150

133151
- name: PgBouncer - reload systemd
134152
systemd:
135153
daemon_reload: yes
154+
when: stage2_nix

docker/nix/build_nix.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ SYSTEM=$(nix-instantiate --eval -E builtins.currentSystem | tr -d '"')
1111
nix build .#checks.$SYSTEM.psql_15 -L --no-link
1212
nix build .#checks.$SYSTEM.psql_orioledb-17 -L --no-link
1313
nix build .#checks.$SYSTEM.psql_17 -L --no-link
14+
nix build .#pgbouncer -L
1415
nix build .#psql_15/bin -o psql_15 -L
1516
nix build .#psql_orioledb-17/bin -o psql_orioledb_17 -L
1617
nix build .#psql_17/bin -o psql_17 -L
@@ -20,6 +21,7 @@ nix build .#wal-g-3 -o wal-g-3 -L
2021
# Copy to S3
2122
nix copy --to s3://nix-postgres-artifacts?secret-key=nix-secret-key ./wal-g-2
2223
nix copy --to s3://nix-postgres-artifacts?secret-key=nix-secret-key ./wal-g-3
24+
nix copy --to s3://nix-postgres-artifacts?secret-key=nix-secret-key ./pgbouncer
2325
nix copy --to s3://nix-postgres-artifacts?secret-key=nix-secret-key ./psql_15
2426
nix copy --to s3://nix-postgres-artifacts?secret-key=nix-secret-key ./psql_orioledb_17
2527
nix copy --to s3://nix-postgres-artifacts?secret-key=nix-secret-key ./psql_17

flake.nix

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,10 @@
8484
})
8585
];
8686
};
87+
mecab-naist-jdic = pkgs.callPackage ./nix/ext/mecab-naist-jdic/default.nix { };
88+
pgbouncer = pkgs.callPackage ./nix/pgbouncer.nix { };
8789
sfcgal = pkgs.callPackage ./nix/ext/sfcgal/sfcgal.nix { };
8890
supabase-groonga = pkgs.callPackage ./nix/supabase-groonga.nix { };
89-
mecab-naist-jdic = pkgs.callPackage ./nix/ext/mecab-naist-jdic/default.nix { };
9091
inherit (pkgs.callPackage ./nix/wal-g.nix { }) wal-g-2 wal-g-3;
9192
# Our list of PostgreSQL extensions which come from upstream Nixpkgs.
9293
# These are maintained upstream and can easily be used here just by
@@ -400,6 +401,7 @@
400401
postgresql_orioledb-17 = getPostgresqlPackage "orioledb-17";
401402
in
402403
postgresVersions // {
404+
pgbouncer = pgbouncer;
403405
supabase-groonga = supabase-groonga;
404406
cargo-pgrx_0_11_3 = pkgs.cargo-pgrx.cargo-pgrx_0_11_3;
405407
cargo-pgrx_0_12_6 = pkgs.cargo-pgrx.cargo-pgrx_0_12_6;

nix/pgbouncer.nix

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
lib,
3+
stdenv,
4+
fetchurl,
5+
openssl,
6+
libevent,
7+
c-ares,
8+
pkg-config,
9+
systemd,
10+
nixosTests,
11+
}:
12+
13+
stdenv.mkDerivation rec {
14+
pname = "pgbouncer";
15+
version = "1.24.1";
16+
17+
src = fetchurl {
18+
url = "https://www.pgbouncer.org/downloads/files/${version}/${pname}-${version}.tar.gz";
19+
hash = "sha256-2nKjq6EwcodtBVo+WN1Kukpd5O1hSOcwMxhSRVmP0+A=";
20+
};
21+
22+
nativeBuildInputs = [ pkg-config ];
23+
buildInputs = [
24+
libevent
25+
openssl
26+
c-ares
27+
] ++ lib.optional stdenv.hostPlatform.isLinux systemd;
28+
enableParallelBuilding = true;
29+
configureFlags = lib.optional stdenv.hostPlatform.isLinux "--with-systemd";
30+
31+
passthru.tests = {
32+
pgbouncer = nixosTests.pgbouncer;
33+
};
34+
35+
meta = with lib; {
36+
homepage = "https://www.pgbouncer.org/";
37+
mainProgram = "pgbouncer";
38+
description = "Lightweight connection pooler for PostgreSQL";
39+
changelog = "https://github.com/pgbouncer/pgbouncer/releases/tag/pgbouncer_${
40+
replaceStrings [ "." ] [ "_" ] version
41+
}";
42+
license = licenses.isc;
43+
maintainers = with maintainers; [ _1000101 ];
44+
platforms = platforms.all;
45+
};
46+
}

0 commit comments

Comments
 (0)