{"id":37193743,"url":"https://github.com/quasoft/pgconf","last_synced_at":"2026-01-14T22:29:52.845Z","repository":{"id":57691030,"uuid":"141004925","full_name":"quasoft/pgconf","owner":"quasoft","description":"Simple Go package for reading/writing to PostgreSQL config files","archived":false,"fork":false,"pushed_at":"2018-07-29T15:31:06.000Z","size":33,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-06-20T11:48:17.904Z","etag":null,"topics":["configuration-files","hba","pgconf","pghba","postgresql","postgresql-conf"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/quasoft.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}},"created_at":"2018-07-15T06:45:59.000Z","updated_at":"2022-04-11T15:50:20.000Z","dependencies_parsed_at":"2022-08-27T18:52:37.333Z","dependency_job_id":null,"html_url":"https://github.com/quasoft/pgconf","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/quasoft/pgconf","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quasoft%2Fpgconf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quasoft%2Fpgconf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quasoft%2Fpgconf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quasoft%2Fpgconf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/quasoft","download_url":"https://codeload.github.com/quasoft/pgconf/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quasoft%2Fpgconf/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28436432,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T21:32:52.117Z","status":"ssl_error","status_checked_at":"2026-01-14T21:32:33.442Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["configuration-files","hba","pgconf","pghba","postgresql","postgresql-conf"],"created_at":"2026-01-14T22:29:52.269Z","updated_at":"2026-01-14T22:29:52.839Z","avatar_url":"https://github.com/quasoft.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pgconf\n\n`pgconf` is a simple Go package for reading/writing to PostgreSQL config file (`postgresql.conf`) that:\n\n* Preseves existing whitespace and comments\n* Supports single quoted and backslash-quoted values (eg. `search_path = '''$user'', \\'public\\''`)\n* Supports values with optional equal sign (eg. `logconnections yes`)\n* Works with ASCII and UTF-8 `.conf` files\n\n## How to use\n\n### postgresql.conf:\n\nTo read or update `postgresql.conf` files use the `pgconf/conf` package:\n\n```go\nimport (\n\t\"fmt\"\n\n\t\"github.com/quasoft/pgconf/conf\"\n)\n\nfunc main() {\n\tc, err := conf.Open(\"/data/postgresql.conf\")\n\tif err != nil {\n\t\tpanic(\"Could not open conf file: \" + err.Error())\n\t}\n\n\t// StringK automatically dequotes values\n\tdest, err := c.StringK(\"log_destination\")\n\tif err != nil || dest != \"syslog\" {\n\t\t// If key was not set or has the wrong value\n\t\tfmt.Println(\"log_destination value is not what we want, changing it now\")\n\t\tc.SetStringK(\"log_destination\", \"syslog\") // SetStringK automatically quotes values if necessary\n\t}\n\n\terr = c.WriteFile(\"/data/postgresql.conf\", 0644)\n\tif err != nil {\n\t\tpanic(\"Could not save file: \" + err.Error())\n\t}\n}\n```\n\n### pg_hba.conf\n\nTo read or update `pg_hba.conf` files use the `pgconf/hba` package:\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/quasoft/pgconf/hba\"\n)\n\nfunc main() {\n\tconf, err := hba.Open(\"../../hba/testdata/sample.conf\") // pg_hba.conf\n\tif err != nil {\n\t\tpanic(fmt.Errorf(\"Failed opening file pg_hba.conf: %s\", err))\n\t}\n\n\t// Find all rows for replication host-based authentication\n\trows, err := conf.LookupAll(hba.Database, \"replication\")\n\tif err != nil {\n\t\tpanic(fmt.Errorf(\"Failed looking up for replication rows: %s\", err))\n\t}\n\n\tfmt.Printf(\"Found %d replication rows with addresses as follows:\\n\", len(rows))\n\tfor _, row := range rows {\n\t\t// Get and print value for ADDRESS column\n\t\taddress, err := conf.String(row, hba.Address)\n\t\tif err != nil {\n\t\t\tpanic(fmt.Errorf(\"Could not read address value: %s\", err))\n\t\t}\n\t\tfmt.Println(\" - \" + address)\n\t}\n}\n```\n\noutputs:\n\n```bash\nFound 3 replication rows with addresses as follows:\n - 127.0.0.1/32\n - ::1/128\n - 10.0.0.3/32\n```\n\n\n## Hint\n\nUsually it's safer to write changes to a temp file and once that writing is over to rename\nthe temp file to the actual configuration file:\n\n```go\n\t...\n\terr = c.WriteFile(\"/data/postgresql.conf.tmp\", 0644)\n\tif err != nil {\n\t\tpanic(\"Could not save file: \" + err.Error())\n\t}\n\n\terr = os.Rename(\"/data/postgresql.conf.tmp\", \"/data/postgresql.conf\")\n\tif err != nil {\n\t\tpanic(\"Could not rename tmp file to conf: \" + err.Error())\n\t}\n\t...\n}\n```\n\nIf you use this approach make sure to store the temp file in a secure location (eg. the data\ndir) with restricted permissions and not inside the `/tmp` directory.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquasoft%2Fpgconf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fquasoft%2Fpgconf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquasoft%2Fpgconf/lists"}