This is a just-deployed elixir/phoenix project, and I want to restore the db with some seed data. the db is clustered over three instances and when I do
flyctl proxy 5454:5433 -a tyndale-app-db
then
pg_restore -p 5454 -h localhost -U postgres -d tyndale_app seeded.sql in another terminal I get:
pg_restore: error: could not execute query: ERROR: cannot execute CREATE EXTENSION in a read-only transaction
How do I write to the clustered db? I tried
ALTER DATABASE tyndale_app SET default_transaction_only TO off;
Hi… Probably you just got randomly connected to one of the read replicas. By default, flyctl proxy uses the .internal address, which doesn’t distinguish among the three.
You actually want to remove the -a, since this is an address now rather than an app name.
(I’m assuming that you’re running this from within the directory that has the fly.toml for your Phoenix application, in which case it shouldn’t need any extra hints to find the right network.)
Also, be sure to use port 5432 instead of 5433; the former is what guarantees you a writable connection (which is why it’s in the Connection string provided above).
The addressing setup with Fly Postgres is a little complicated, , in part because there are two layers of proxying and in part because it accumulated over time—and not all of the messages were subsequently re-optimized, etc.