You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.
Currently, https://github.com/supabase/postgres uses Packer to create AMIs, and customers get their AMIs provisioned for them when they start a project. Also, it would be nice if there was a way to "upgrade" an AMI with a different build of PostgreSQL, even after it's provisioned.
This repository doesn't do that yet, but I think there's a path to make it work. In the Nix world, I think that can be solved with a few steps: copying the closure, installing it into the default profile, and then switching it out.
Step 1: Copy the closure into the system
For any path in the Nix store /nix/store (let's call it $STORE_PATH), you can run the following to download it onto your existing machine at any time:
This will recursively download and copy all dependencies onto the machine.
Step 2: Install into the default profile (AKA root)
However, there's a problem: how do you know what $STORE_PATH to use? And how would you point systemd to it, for example? Ideally, there would be a "stable path" that would refer to a version of PostgreSQL.
Luckily, Nix does have such a feature: it's called profiles, and there is a default profile, assigned to the root user. When the root user installs something, it goes into the default profile, and is available for everyone. Let's look at that on my machine:
nix-env -q is the way of querying what's installed for the root user. By default, a profile named foobar will have a "symlink farm" located at /nix/var/nix/profiles/{foobar} with all the files within it. If you install things into a profile, they will show up there.
Here's an example of installing a variant of postgresql from this system:
You can use nix-env -i $STORE_PATH to install any path into the default profile for the root user. So we used nix-env -i to install it, then looked at the default profile. As expected, our PostgreSQL binaries are located in the /bin directory.
Thus, the only thing we need to do is install the package into the root profile, and point systemd to use binaries in /nix/var/nix/profiles/default/bin.
Once a version of the server is installed, systemctl daemon-reload; systemctl restart postgresql (or something to that effect) should bounce the service properly.
The only real change that should be needed is just pointing systemd to the right path. After that, it's typical ops stuff.
Side note: zero-downtime upgrades?
This strategy doesn't by default allow zero-downtime upgrades, because the postgresql service must be bounced. There are an array of solutions to this but I think they're probably not for me to decide. The most likely solution is probably some usage of pg_bouncer, I assume, though that has other consequences for things like prepared statements.
In the above example, just restarting the database with a new version of the server will probably take some time to bring the tables up. This is worth keeping in mind.
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Currently, https://github.com/supabase/postgres uses Packer to create AMIs, and customers get their AMIs provisioned for them when they start a project. Also, it would be nice if there was a way to "upgrade" an AMI with a different build of PostgreSQL, even after it's provisioned.
This repository doesn't do that yet, but I think there's a path to make it work. In the Nix world, I think that can be solved with a few steps: copying the closure, installing it into the
default
profile, and then switching it out.Step 1: Copy the closure into the system
For any path in the Nix store
/nix/store
(let's call it$STORE_PATH
), you can run the following to download it onto your existing machine at any time:This will recursively download and copy all dependencies onto the machine.
Step 2: Install into the default profile (AKA
root
)However, there's a problem: how do you know what
$STORE_PATH
to use? And how would you point systemd to it, for example? Ideally, there would be a "stable path" that would refer to a version of PostgreSQL.Luckily, Nix does have such a feature: it's called profiles, and there is a default profile, assigned to the root user. When the root user installs something, it goes into the default profile, and is available for everyone. Let's look at that on my machine:
nix-env -q
is the way of querying what's installed for the root user. By default, a profile namedfoobar
will have a "symlink farm" located at/nix/var/nix/profiles/{foobar}
with all the files within it. If you install things into a profile, they will show up there.Here's an example of installing a variant of
postgresql
from this system:You can use
nix-env -i $STORE_PATH
to install any path into thedefault
profile for the root user. So we usednix-env -i
to install it, then looked at the default profile. As expected, our PostgreSQL binaries are located in the/bin
directory.Thus, the only thing we need to do is install the package into the root profile, and point systemd to use binaries in
/nix/var/nix/profiles/default/bin
.Once a version of the server is installed,
systemctl daemon-reload; systemctl restart postgresql
(or something to that effect) should bounce the service properly.The only real change that should be needed is just pointing systemd to the right path. After that, it's typical ops stuff.
Side note: zero-downtime upgrades?
This strategy doesn't by default allow zero-downtime upgrades, because the postgresql service must be bounced. There are an array of solutions to this but I think they're probably not for me to decide. The most likely solution is probably some usage of
pg_bouncer
, I assume, though that has other consequences for things like prepared statements.In the above example, just restarting the database with a new version of the server will probably take some time to bring the tables up. This is worth keeping in mind.
The text was updated successfully, but these errors were encountered: