I’m assuming you already have a Fly app running called
example-app with a Fly Postgres database app called
If you already have data stored in your Fly Postgres instance, be warned this will delete it all! (Ask me how I know! 🙃)
If you want to maintain your existing data, you could probably use some volume forking, but that’s not included in this post.
Also, once you switch the database app to “self-managed” mode, the
flyctl postgres commands won’t work any more.
Finally, be aware this will change your database passwords, so you’ll need to update your app secrets before the new database app will work (Again, ask me how I know 😬)
The gist is that Fly Postgres instances are “just” deployed copies of the open-source postgres-ha app. So at a high level, we need to:
- Clone postgres-ha.
- Update the Dockerfile to install pgvector.
- Deploy the change overtop our existing database app.
- Reconfigure our application server to use it.
So, first let’s check it out:
git clone https://github.com/fly-apps/postgres-ha postgres-ha
This comes with a pre-written
fly.toml, but we need to update it to our app name. In the following examples, I’ll use
example-app as the name of the Fly app that we’re deploying a database for.
flyctl config save -a example-app-db
Then add this to line 45 in the Dockerfile (below the
For an example of what the Dockerfile change looks like in context, see this commit.
Then deploy the app:
Enable the extension
To connect to the database and enable the extension, we need to proxy a local connection with
flyctl proxy (since
flyctl postgres connect doesn’t work anymore):
flyctl proxy 5432
You’ll need to get the database password as well, for example with:
flyctl ssh console
# in db container
Then you can connect locally with:
And run the following commands:
-- enable pgvector extension
CREATE EXTENSION IF NOT EXISTS vector;
-- create your app DB if necessary
CREATE DATABASE db_name;
Since the password changed when we deployed over the old app, we’ll also need to remember to update our application secret to use the new one:
flyctl secrets set -a example-app \
And now we should be all set! Happy embedding!