{"id":20697951,"url":"https://github.com/fly-apps/postgres-ha","last_synced_at":"2025-04-05T08:06:39.374Z","repository":{"id":37800588,"uuid":"325363745","full_name":"fly-apps/postgres-ha","owner":"fly-apps","description":"Postgres + Stolon for HA clusters as Fly apps.","archived":false,"fork":false,"pushed_at":"2023-05-19T00:02:34.000Z","size":2171,"stargazers_count":325,"open_issues_count":22,"forks_count":129,"subscribers_count":11,"default_branch":"main","last_synced_at":"2025-03-29T07:06:26.592Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fly-apps.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-12-29T18:52:21.000Z","updated_at":"2025-03-21T01:43:56.000Z","dependencies_parsed_at":"2024-06-20T06:45:26.521Z","dependency_job_id":"60cab88c-8b78-48ca-9c5a-cb000ff4c7d5","html_url":"https://github.com/fly-apps/postgres-ha","commit_stats":null,"previous_names":["fly-examples/postgres-ha"],"tags_count":41,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fly-apps%2Fpostgres-ha","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fly-apps%2Fpostgres-ha/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fly-apps%2Fpostgres-ha/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fly-apps%2Fpostgres-ha/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fly-apps","download_url":"https://codeload.github.com/fly-apps/postgres-ha/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247305934,"owners_count":20917208,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-17T00:20:52.453Z","updated_at":"2025-04-05T08:06:39.356Z","avatar_url":"https://github.com/fly-apps.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# High Availability Postgres on Fly.io\n\nThis repo contains all the code and configuration necessary to run a [highly available Postgres cluster](https://fly.io/docs/postgres/) in a Fly.io organization's private network. This source is packaged into [Docker images](https://hub.docker.com/r/flyio/postgres-ha/tags) which allow you to track and upgrade versions cleanly as new features are added.\n\nIf you just want to get a standard Postgres standalone or highly-available setup on Fly, [check out the docs](https://fly.io/docs/postgres/).\n## Customizing cluster behavior\n\nFly Postgres clusters are just regular Fly applications. If you need to customize Postgres in any way, you may fork this repo and deploy using normal Fly deployment procedures. You won't be able to use `fly postgres` commands with custom clusters. But it's a great way to experiment and potentially contribute back useful features!\n\nFollow the rest of this README to run a customized setup.\n## Prepare a new application\n\nYou'll need a fresh Fly application in your preferred region to get started. Run these commands within the fork of this repository.\n### `fly launch --no-deploy`\nThis gets you started with a Fly application and an associated config file.\nChoose `yes` when asked whether to copy the existing configuration to the newly generated app.\n\n### Set secrets\nThis app requires a few secret environment variables. Generate a secure string for each, and save them.\n\n`SU_PASSWORD` is the PostgreSQL super user password. The username is `flypgadmin`. Use these credentials to run high privilege administration tasks.\n\n`REPL_PASSWORD` is used to replicate between instances.\n\n`OPERATOR_PASSWORD` is the password for the standard user `postgres`. Use these credentials for connecting from your application.\n\n\u003e `fly secrets set SU_PASSWORD=\u003cPASSWORD\u003e REPL_PASSWORD=\u003cPASSWORD\u003e OPERATOR_PASSWORD=\u003cPASSWORD\u003e`\n\n### Set the PRIMARY_REGION environment variable within your fly.toml \nThe PRIMARY_REGION value lets Stolon know which Postgres instances are eligible for election in the event of a failover.  If this value is not set to the correct region, your cluster may not boot properly.   \n\n## Deploy one instance\n\nFirst, get one instance deployed in your preferred start region.\n\n1. `fly volumes create pg_data --region ord --size 10`\n2. `fly deploy`\n3. `fly status`\n\n## Add a replica\n\nScaling up will automatically setup a replica for you. Do that now in the same region.\n\n1. `fly volumes create pg_data --region ord --size 10`\n2. `fly scale count 2`\n3. `fly status`\n\n## Add a replica in another region\n\nScale to another region by creating a volume there. Now you should have a primary/replica pair in `ord` and a replica in `syd`.\n\n1. `fly volumes create pg_data --region syd --size 10`\n2. `fly scale count 3`\n3. `fly status`\n\n## Connecting\n\nFly apps within the same organization can connect to your Postgres using the following URI:\n\n```\npostgres://postgres:\u003coperator_password\u003e@\u003cpostgres-app-name\u003e.internal:5432/\u003cdatabase-name\u003e\n```\n\n### Connecting to Postgres from your local machine\n\n1. Forward the server port to your local system with [`flyctl proxy`](https://fly.io/docs/flyctl/proxy/):\n\n```\nflyctl proxy 5432 -a \u003cpostgres-app-name\u003e\n```\n\n2. Postgres needs to be installed on your local machine.\n\n3. Use psql to connect to your Postgres instance on the forwarded port.\n\n```\npsql postgres://postgres:\u003coperator_password\u003e@localhost:5432\n```\n\n## Enabling TimescaleDB\n\nThis app includes the [TimescaleDB extension](https://timescale.com/).  To enable TimescaleDB, take the following steps:\n\n\n1. Ensure your Postgres app is running `\u003e= v0.0.28`.\n\n```\n# View your image details\nfly image show --app \u003capp-name\u003e\n\n# Update to the latest ( Nomad-based apps )\nfly image update --app \u003capp-name\u003e\n```\n\n2. Configure Postgres to preload the TimescaleDB library\n\n```\nfly pg config update --shared-preload-libraries timescaledb --app \u003capp-name\u003e\n```\n\n3. Restart Postgres\n\n```\nfly postgres restart --app \u003capp-name\u003e\n```\n\n4. Create the extension\n\n```\n# Connect to your target database\nfly pg connect --app \u003capp-name\u003e --database \u003cdb-name\u003e\n\n# Create the extension\nCREATE EXTENSION IF NOT EXISTS timescaledb;\n```\n\n## Having trouble?\n\nCreate an issue or ask a question here: https://community.fly.io/\n\n\n## Contributing\nIf you're looking to get involved, fork the project and send pull requests.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffly-apps%2Fpostgres-ha","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffly-apps%2Fpostgres-ha","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffly-apps%2Fpostgres-ha/lists"}