{"id":21929207,"url":"https://github.com/achetronic/pg-selector","last_synced_at":"2025-06-13T00:05:53.395Z","repository":{"id":236395324,"uuid":"792431830","full_name":"achetronic/pg-selector","owner":"achetronic","description":"Companion for Postgres HA deployment on Kubernetes that labels its pods with the current replication role ","archived":false,"fork":false,"pushed_at":"2025-03-12T16:24:03.000Z","size":9877,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-19T19:51:00.840Z","etag":null,"topics":["cli","golang","ha","kubernetes","postgres"],"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/achetronic.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,"zenodo":null}},"created_at":"2024-04-26T16:51:27.000Z","updated_at":"2025-03-12T16:23:23.000Z","dependencies_parsed_at":"2025-03-11T17:25:24.330Z","dependency_job_id":"e1c6c190-db6e-4e3b-bd60-76a8aa442360","html_url":"https://github.com/achetronic/pg-selector","commit_stats":null,"previous_names":["achetronic/pg-selector"],"tags_count":17,"template":false,"template_full_name":null,"purl":"pkg:github/achetronic/pg-selector","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/achetronic%2Fpg-selector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/achetronic%2Fpg-selector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/achetronic%2Fpg-selector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/achetronic%2Fpg-selector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/achetronic","download_url":"https://codeload.github.com/achetronic/pg-selector/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/achetronic%2Fpg-selector/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259553131,"owners_count":22875609,"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":["cli","golang","ha","kubernetes","postgres"],"created_at":"2024-11-28T22:30:07.821Z","updated_at":"2025-06-13T00:05:53.341Z","avatar_url":"https://github.com/achetronic.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PG Selector\n\n![GitHub go.mod Go version (subdirectory of monorepo)](https://img.shields.io/github/go-mod/go-version/achetronic/pg-selector)\n![GitHub](https://img.shields.io/github/license/achetronic/pg-selector)\n\n![YouTube Channel Subscribers](https://img.shields.io/youtube/channel/subscribers/UCeSb3yfsPNNVr13YsYNvCAw?label=achetronic\u0026link=http%3A%2F%2Fyoutube.com%2Fachetronic)\n![GitHub followers](https://img.shields.io/github/followers/achetronic?label=achetronic\u0026link=http%3A%2F%2Fgithub.com%2Fachetronic)\n![X (formerly Twitter) Follow](https://img.shields.io/twitter/follow/achetronic?style=flat\u0026logo=twitter\u0026link=https%3A%2F%2Ftwitter.com%2Fachetronic)\n\nA little companion for your Postgres HA deployment on Kubernetes that labels its pods\nwith the current replication role\n\n## Motivation\n\nIf you have played with Postgres in HA, having several primary servers, you probably know Replication Manager.\nThis tool keeps 'primary' and 'standby' nodes synchronized and promotes 'standby' to 'primary' on failures.\n\nThis commonly implies having a proxy in front of all Postgres nodes to route writing operations to 'primary',\nbalance reading operations to the rest of nodes, and other advantages.\n\nThis proxy-pattern helps to mask failures in a way the client application commonly doesn't notice,\nbeing super useful in huge productive customer-facing systems.\n\nBut what happens if you require HA on smaller systems?\nIs the overhead of configuring perfect proxy worth?\nThe answer is NO.\n\nReplication Manager is taking care of your Postgres, so you always have a 'primary' available.\nBut Kubernetes cannot distinguish the role of your nodes, or it can?\n\nThis application is a little CLI that checks the roles of your Postgres Pods from time to time,\nand labels them with the role.\n\nThis way you can create a Kubernetes Service that points always to the 'primary'\ndeleting the need of a complicated proxy on small HA deployments\n\n## Diagram\n\n\u003c!-- markdownlint-disable MD033 --\u003e\n\u003cimg src=\"https://raw.githubusercontent.com/achetronic/pg-selector/master/docs/img/pg-selector.png\" alt=\"PG Selector diagram\" width=\"600\" /\u003e\n\n## Flags\n\nEvery configuration parameter can be defined by flags that can be passed to the CLI.\nThey are described in the following table:\n\n| Name                  | Description                         | Default | Example                         |\n|:----------------------|:------------------------------------|:-------:|---------------------------------|\n| `--log-level`         | Define the verbosity of the logs    | `info`  | `--log-level info`              |\n| `--kubeconfig`        | Path to kubeconfig                  |   `-`   | `--kubeconfig=\"~/.kube/config\"` |\n| `--services-creation` | Enable the creation of the services | `true`  | `--services-creation=false`     |\n| `--sync-time`         | Synchronization time in seconds     |  `5s`   | `--sync-time=2m`                |\n\n## Environment Variables\n\nSecurity-critical parameters are managed by environment variables.\nThey are described in the following table:\n\n| Name                   | Description                   | Default | Example                                                         |\n|:-----------------------|:------------------------------|:-------:|-----------------------------------------------------------------|\n| `PG_CONNECTION_STRING` | OBDC styled connection string |   `-`   | `postgresql://username:password@postgres.namespace.svc:5432/db` |\n\n## Examples\n\nHere you have a complete example to use this command.\n\n\u003e Output is thrown always in JSON as it is more suitable for automations\n\n```console\nexport PG_CONNECTION_STRING=\"postgresql://username:password@postgres.namespace.svc:5432/db\"\n\npgs run \\\n    --log-level=info\n    --kubeconfig=\"./path\"\n```\n\n\u003e ATTENTION:\n\u003e If you detect some mistake on the examples, open an issue to fix it.\n\u003e This way we all will benefit\n\n## How to use\n\nThis project provides binary files and Docker images to make it easy to use wherever wanted\n\n### Binaries\n\nBinary files for the most popular platforms will be added to the [releases](https://github.com/achetronic/pg-selector/releases)\n\n### Docker\n\nDocker images can be found in GitHub's [packages](https://github.com/achetronic/pg-selector/pkgs/container/pg-selector)\nrelated to this repository\n\n\u003e Do you need it in a different container registry? We think this is not needed, but if we're wrong, please, let's discuss\n\u003e it in the best place for that: an issue\n\n## How to contribute\n\nWe are open to external collaborations for this project: improvements, bugfixes, whatever.\n\nFor doing it, open an issue to discuss the need of the changes, then:\n\n- Fork the repository\n- Make your changes to the code\n- Open a PR and wait for review\n\nThe code will be reviewed and tested (always)\n\n\u003e We are developers and hate bad code. For that reason, we ask you the highest quality\n\u003e on each line of code to improve this project on each iteration.\n\n## License\n\u003c!-- markdownlint-disable MD046 --\u003e\n\nCopyright 2022.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n\n## Special mention\n\nThis project was done using IDEs from JetBrains. They helped us to develop faster, so we recommend them a lot! 🤓\n\n\u003cimg src=\"https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.png\" alt=\"JetBrains Logo (Main) logo.\" width=\"150\"\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fachetronic%2Fpg-selector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fachetronic%2Fpg-selector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fachetronic%2Fpg-selector/lists"}