Skip to content

Commit 9a2d617

Browse files
authored
Merge branch 'develop' into sam/oriole17
2 parents d29bd9c + ffa1052 commit 9a2d617

File tree

17 files changed

+212
-105
lines changed

17 files changed

+212
-105
lines changed

.github/workflows/nix-build.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ jobs:
2424
arch: arm64
2525
- runner: macos-latest
2626
arch: arm64
27+
- runner: macos-13
28+
arch: amd64
2729
runs-on: ${{ matrix.runner }}
28-
30+
timeout-minutes: 180
2931
steps:
3032

3133
- name: Check out code
@@ -48,23 +50,23 @@ jobs:
4850
env:
4951
NIX_SIGN_SECRET_KEY: ${{ secrets.NIX_SIGN_SECRET_KEY }}
5052
- name: Log in to Docker Hub
51-
if: matrix.runner != 'macos-latest'
53+
if: matrix.runner != 'macos-latest' && matrix.runner != 'macos-13'
5254
uses: docker/login-action@v2
5355
with:
5456
username: ${{ secrets.DOCKER_USERNAME }}
5557
password: ${{ secrets.DOCKER_PASSWORD }}
5658
- name: Build psql bundle with nix
57-
if: matrix.runner != 'macos-latest'
59+
if: matrix.runner != 'macos-latest' && matrix.runner != 'macos-13'
5860
run: docker build -t base_nix -f docker/nix/Dockerfile .
5961
- name: Run build psql bundle
60-
if: matrix.runner != 'macos-latest'
62+
if: matrix.runner != 'macos-latest' && matrix.runner != 'macos-13'
6163
run: |
6264
docker run -e AWS_ACCESS_KEY_ID=${{ env.AWS_ACCESS_KEY_ID }} \
6365
-e AWS_SECRET_ACCESS_KEY=${{ env.AWS_SECRET_ACCESS_KEY }} \
6466
-e AWS_SESSION_TOKEN=${{ env.AWS_SESSION_TOKEN }} \
6567
base_nix bash -c "./workspace/docker/nix/build_nix.sh"
6668
- name: Build psql bundle on macos
67-
if: matrix.runner == 'macos-latest'
69+
if: matrix.runner == 'macos-latest' || matrix.runner == 'macos-13'
6870
run: |
6971
curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install --no-confirm \
7072
--extra-conf "substituters = https://cache.nixos.org https://nix-postgres-artifacts.s3.amazonaws.com" \

.github/workflows/publish-nix-pgupgrade-scripts.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ jobs:
101101
run: |
102102
VERSION=$(sudo nix run nixpkgs#yq -- '.postgres_release["postgres'${{ matrix.postgres_version }}'"]' ansible/vars.yml)
103103
VERSION=$(echo $PG_VERSION | tr -d '"') # Remove any surrounding quotes
104+
if [[ "${{ inputs.postgresVersion }}" != "" ]]; then
105+
VERSION=${{ inputs.postgresVersion }}
106+
fi
104107
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
105108
106109
- name: Create a tarball containing pg_upgrade scripts

ansible/files/admin_api_scripts/pg_upgrade_scripts/common.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,24 @@ swap_postgres_and_supabase_admin() {
9191
alter database postgres connection limit 0;
9292
select pg_terminate_backend(pid) from pg_stat_activity where backend_type = 'client backend' and pid != pg_backend_pid();
9393
EOSQL
94+
95+
if [ -z "$IS_CI" ]; then
96+
retry 5 systemctl restart postgresql
97+
else
98+
CI_start_postgres ""
99+
fi
100+
101+
retry 8 pg_isready -h localhost -U supabase_admin
102+
94103
run_sql <<'EOSQL'
95104
set statement_timeout = '600s';
96105
begin;
97106
create role supabase_tmp superuser;
98107
set session authorization supabase_tmp;
99108
109+
-- to handle snowflakes that happened in the past
110+
revoke supabase_admin from authenticator;
111+
100112
do $$
101113
begin
102114
if exists (select from pg_extension where extname = 'timescaledb') then

ansible/files/admin_api_scripts/pg_upgrade_scripts/complete.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ EOF
7878

7979
run_sql -c "$RECREATE_PG_CRON_QUERY"
8080
fi
81+
82+
# #incident-2024-09-12-project-upgrades-are-temporarily-disabled
83+
run_sql -c "grant pg_read_all_data, pg_signal_backend to postgres"
8184
}
8285

8386
function complete_pg_upgrade {

ansible/files/admin_api_scripts/pg_upgrade_scripts/initiate.sh

Lines changed: 26 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ MOUNT_POINT="/data_migration"
3939
LOG_FILE="/var/log/pg-upgrade-initiate.log"
4040

4141
POST_UPGRADE_EXTENSION_SCRIPT="/tmp/pg_upgrade/pg_upgrade_extensions.sql"
42+
POST_UPGRADE_POSTGRES_PERMS_SCRIPT="/tmp/pg_upgrade/pg_upgrade_postgres_perms.sql"
4243
OLD_PGVERSION=$(run_sql -A -t -c "SHOW server_version;")
4344

4445
SERVER_LC_COLLATE=$(run_sql -A -t -c "SHOW lc_collate;")
@@ -47,7 +48,6 @@ SERVER_ENCODING=$(run_sql -A -t -c "SHOW server_encoding;")
4748

4849
POSTGRES_CONFIG_PATH="/etc/postgresql/postgresql.conf"
4950
PGBINOLD="/usr/lib/postgresql/bin"
50-
PGLIBOLD="/usr/lib/postgresql/lib"
5151

5252
PG_UPGRADE_BIN_DIR="/tmp/pg_upgrade_bin/$PGVERSION"
5353
NIX_INSTALLER_PATH="/tmp/persistent/nix-installer"
@@ -133,6 +133,22 @@ cleanup() {
133133
echo "Resetting postgres database connection limit"
134134
retry 5 run_sql -c "ALTER DATABASE postgres CONNECTION LIMIT -1;"
135135

136+
echo "Making sure postgres still has access to pg_shadow"
137+
cat << EOF >> $POST_UPGRADE_POSTGRES_PERMS_SCRIPT
138+
DO \$\$
139+
begin
140+
if exists (select from pg_authid where rolname = 'pg_read_all_data') then
141+
execute('grant pg_read_all_data to postgres');
142+
end if;
143+
end
144+
\$\$;
145+
grant pg_signal_backend to postgres;
146+
EOF
147+
148+
if [ -f $POST_UPGRADE_POSTGRES_PERMS_SCRIPT ]; then
149+
retry 5 run_sql -f $POST_UPGRADE_POSTGRES_PERMS_SCRIPT
150+
fi
151+
136152
if [ -z "$IS_CI" ] && [ -z "$IS_LOCAL_UPGRADE" ]; then
137153
echo "Unmounting data disk from ${MOUNT_POINT}"
138154
retry 3 umount $MOUNT_POINT
@@ -148,6 +164,14 @@ cleanup() {
148164
}
149165

150166
function handle_extensions {
167+
if [ -z "$IS_CI" ]; then
168+
retry 5 systemctl restart postgresql
169+
else
170+
CI_start_postgres
171+
fi
172+
173+
retry 8 pg_isready -h localhost -U supabase_admin
174+
151175
rm -f $POST_UPGRADE_EXTENSION_SCRIPT
152176
touch $POST_UPGRADE_EXTENSION_SCRIPT
153177

@@ -181,58 +205,6 @@ EOF
181205
done
182206
}
183207

184-
function patch_wrappers {
185-
local IS_NIX_UPGRADE=$1
186-
187-
WRAPPERS_ENABLED=$(run_sql -A -t -c "SELECT EXISTS(SELECT 1 FROM pg_extension WHERE extname = 'wrappers');")
188-
if [ "$WRAPPERS_ENABLED" = "f" ]; then
189-
echo "Wrappers extension not enabled. Skipping."
190-
return
191-
fi
192-
193-
# This is a workaround for older versions of wrappers which don't have the expected
194-
# naming scheme, containing the version in their library's file name
195-
# e.g. wrappers-0.1.16.so, rather than wrappers.so
196-
# pg_upgrade errors out when it doesn't find an equivalent file in the new PG version's
197-
# library directory, so we're making sure the new version has the expected (old version's)
198-
# file name.
199-
# After the upgrade completes, the new version's library file is used.
200-
# i.e.
201-
# - old version: wrappers-0.1.16.so
202-
# - new version: wrappers-0.1.18.so
203-
# - workaround to make pg_upgrade happy: copy wrappers-0.1.18.so to wrappers-0.1.16.so
204-
if [ "$IS_NIX_UPGRADE" = "true" ]; then
205-
if [ -d "$PGLIBOLD" ]; then
206-
OLD_WRAPPER_LIB_PATH=$(find "$PGLIBOLD" -name "wrappers*so" -print -quit)
207-
OLD_LIB_FILE_NAME=$(basename "$OLD_WRAPPER_LIB_PATH")
208-
209-
find /nix/store/ -name "wrappers*so" -print0 | while read -r -d $'\0' WRAPPERS_LIB_PATH; do
210-
if [ -f "$WRAPPERS_LIB_PATH" ]; then
211-
WRAPPERS_LIB_PATH_DIR=$(dirname "$WRAPPERS_LIB_PATH")
212-
if [ "$WRAPPERS_LIB_PATH" != "$WRAPPERS_LIB_PATH_DIR/${OLD_LIB_FILE_NAME}" ]; then
213-
echo "Copying $WRAPPERS_LIB_PATH to $WRAPPERS_LIB_PATH_DIR/${OLD_LIB_FILE_NAME}"
214-
cp "$WRAPPERS_LIB_PATH" "$WRAPPERS_LIB_PATH_DIR/${OLD_LIB_FILE_NAME}" || true
215-
fi
216-
fi
217-
done
218-
fi
219-
else
220-
if [ -d "$PGLIBOLD" ]; then
221-
WRAPPERS_LIB_PATH=$(find "$PGLIBNEW" -name "wrappers*so" -print -quit)
222-
if [ -f "$WRAPPERS_LIB_PATH" ]; then
223-
OLD_WRAPPER_LIB_PATH=$(find "$PGLIBOLD" -name "wrappers*so" -print -quit)
224-
if [ -f "$OLD_WRAPPER_LIB_PATH" ]; then
225-
LIB_FILE_NAME=$(basename "$OLD_WRAPPER_LIB_PATH")
226-
if [ "$WRAPPERS_LIB_PATH" != "$PGLIBNEW/${LIB_FILE_NAME}" ]; then
227-
echo "Copying $WRAPPERS_LIB_PATH to $PGLIBNEW/${LIB_FILE_NAME}"
228-
cp "$WRAPPERS_LIB_PATH" "$PGLIBNEW/${LIB_FILE_NAME}" || true
229-
fi
230-
fi
231-
fi
232-
fi
233-
fi
234-
}
235-
236208
function initiate_upgrade {
237209
mkdir -p "$MOUNT_POINT"
238210
SHARED_PRELOAD_LIBRARIES=$(cat "$POSTGRES_CONFIG_PATH" | grep shared_preload_libraries | sed "s/shared_preload_libraries =\s\{0,1\}'\(.*\)'.*/\1/")
@@ -409,8 +381,6 @@ function initiate_upgrade {
409381
export LD_LIBRARY_PATH="${PGLIBNEW}"
410382
fi
411383

412-
patch_wrappers "$IS_NIX_UPGRADE"
413-
414384
echo "9. Creating new data directory, initializing database"
415385
chown -R postgres:postgres "$MOUNT_POINT/"
416386
rm -rf "${PGDATANEW:?}/"
@@ -473,6 +443,7 @@ EOF
473443
cp -R /etc/postgresql-custom/* "$MOUNT_POINT/conf/"
474444
# removing supautils config as to allow the latest one provided by the latest image to be used
475445
rm -f "$MOUNT_POINT/conf/supautils.conf" || true
446+
rm -rf "$MOUNT_POINT/conf/extension-custom-scripts" || true
476447

477448
# removing wal-g config as to allow it to be explicitly enabled on the new instance
478449
rm -f "$MOUNT_POINT/conf/wal-g.conf"

ansible/files/postgresql_config/supautils.conf.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ supautils.privileged_extensions_custom_scripts_path = '/etc/postgresql-custom/ex
99
supautils.privileged_extensions_superuser = 'supabase_admin'
1010
supautils.privileged_role = 'postgres'
1111
supautils.privileged_role_allowed_configs = 'auto_explain.log_min_duration, auto_explain.log_nested_statements, log_lock_waits, log_min_messages, pg_net.batch_size, pg_net.ttl, pgaudit.log, pgaudit.log_catalog, pgaudit.log_client, pgaudit.log_level, pgaudit.log_relation, pgaudit.log_rows, pgaudit.log_statement, pgaudit.log_statement_once, pgaudit.role, pgrst.*, plan_filter.*, safeupdate.enabled, session_replication_role, track_io_timing'
12-
supautils.reserved_memberships = 'pg_read_server_files, pg_write_server_files, pg_execute_server_program, authenticator'
13-
supautils.reserved_roles = 'supabase_admin, supabase_auth_admin, supabase_storage_admin, supabase_read_only_user, supabase_replication_admin, dashboard_user, pgbouncer, service_role*, authenticator*, authenticated*, anon*'
12+
supautils.reserved_memberships = 'pg_read_server_files, pg_write_server_files, pg_execute_server_program, supabase_admin, supabase_auth_admin, supabase_storage_admin, supabase_read_only_user, supabase_realtime_admin, supabase_replication_admin, dashboard_user, pgbouncer, authenticator'
13+
supautils.reserved_roles = 'supabase_admin, supabase_auth_admin, supabase_storage_admin, supabase_read_only_user, supabase_realtime_admin, supabase_replication_admin, dashboard_user, pgbouncer, service_role*, authenticator*, authenticated*, anon*'

ansible/vars.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ postgrest_release: "12.2.3"
2525
postgrest_arm_release_checksum: sha1:fbfd6613d711ce1afa25c42d5df8f1b017f396f9
2626
postgrest_x86_release_checksum: sha1:61c513f91a8931be4062587b9d4a18b42acf5c05
2727

28-
gotrue_release: 2.162.0
29-
gotrue_release_checksum: sha1:855b23bd002577290c7d42d7042ac0f5316984b1
28+
gotrue_release: 2.163.2
29+
gotrue_release_checksum: sha1:31889bc8c498b924c2cb3b6c4084ef6e57ed97c0
3030

3131
aws_cli_release: "2.2.7"
3232

@@ -149,8 +149,8 @@ hypopg_release_checksum: sha256:9afe6357fd389d8d33fad81703038ce520b09275ec00153c
149149
pg_repack_release: "1.5.0"
150150
pg_repack_release_checksum: sha256:9a14d6a95bfa29f856aa10538238622c1f351d38eb350b196c06720a878ccc52
151151

152-
pgvector_release: "0.7.4"
153-
pgvector_release_checksum: sha256:0341edf89b1924ae0d552f617e14fb7f8867c0194ed775bcc44fa40288642583
152+
pgvector_release: "0.8.0"
153+
pgvector_release_checksum: sha256:867a2c328d4928a5a9d6f052cd3bc78c7d60228a9b914ad32aa3db88e9de27b0
154154

155155
pg_tle_release: "1.3.2"
156156
pg_tle_release_checksum: sha256:d04f72d88b21b954656609743560684ac42645b64a36c800d4d2f84d1f180de1

ebssurrogate/scripts/surrogate-bootstrap-nix.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ function format_and_mount_rootfs {
110110
fi
111111

112112
mkfs.ext4 /dev/xvdh
113+
114+
# Explicitly reserving 100MiB worth of blocks for the data volume
115+
RESERVED_DATA_VOLUME_BLOCK_COUNT=$((100 * 1024 * 1024 / 4096))
116+
tune2fs -r $RESERVED_DATA_VOLUME_BLOCK_COUNT /dev/xvdh
117+
113118
mkdir -p /mnt/data
114119
mount -o defaults,discard /dev/xvdh /mnt/data
115120
}

flake.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
system.x86_64-linux
1818
system.aarch64-linux
1919
system.aarch64-darwin
20+
system.x86_64-darwin
2021
];
2122
in
2223
flake-utils.lib.eachSystem ourSystems (system:
@@ -199,7 +200,6 @@
199200
else ourExtensions;
200201
in map (path: pkgs.callPackage path { inherit postgresql; }) extensionsToUse;
201202

202-
203203
# Create an attrset that contains all the extensions included in a server.
204204
makeOurPostgresPkgsSet = version:
205205
(builtins.listToAttrs (map

nix/ext/pg_repack.nix

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111

1212
stdenv.mkDerivation (finalAttrs: {
1313
pname = "pg_repack";
14-
version = "1.5.0";
14+
version = "1.5.2";
1515

1616
buildInputs = postgresql.buildInputs ++ [ postgresql ];
1717

1818
src = fetchFromGitHub {
1919
owner = "reorg";
2020
repo = "pg_repack";
21-
rev = "ver_${finalAttrs.version}";
22-
hash = "sha256-do80phyMxwcRIkYyUt9z02z7byNQhK+pbSaCUmzG+4c=";
21+
rev = "85b64c6d4f599b2988343c4e7121acab505c9006";
22+
hash = "sha256-lAuLI+vupusvn3uTzQ9OaLqkEfUVMCAwU9R70tTbb8Y=";
2323
};
2424

2525
installPhase = ''

0 commit comments

Comments
 (0)