{"id":15605210,"url":"https://github.com/ostinelli/pgpool","last_synced_at":"2025-04-15T11:52:44.617Z","repository":{"id":53557373,"uuid":"47022635","full_name":"ostinelli/pgpool","owner":"ostinelli","description":"A PosgreSQL client that automatically uses connection pools and handles reconnections in case of errors.","archived":false,"fork":false,"pushed_at":"2020-12-06T00:32:11.000Z","size":275,"stargazers_count":42,"open_issues_count":3,"forks_count":18,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-08T11:05:30.530Z","etag":null,"topics":["connection-pool","posgresql"],"latest_commit_sha":null,"homepage":null,"language":"Erlang","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/ostinelli.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-11-28T12:29:24.000Z","updated_at":"2024-01-19T10:23:52.000Z","dependencies_parsed_at":"2022-09-07T11:10:27.303Z","dependency_job_id":null,"html_url":"https://github.com/ostinelli/pgpool","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ostinelli%2Fpgpool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ostinelli%2Fpgpool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ostinelli%2Fpgpool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ostinelli%2Fpgpool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ostinelli","download_url":"https://codeload.github.com/ostinelli/pgpool/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249067755,"owners_count":21207395,"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":["connection-pool","posgresql"],"created_at":"2024-10-03T04:03:08.536Z","updated_at":"2025-04-15T11:52:44.585Z","avatar_url":"https://github.com/ostinelli.png","language":"Erlang","readme":"\n[![Build Status](https://travis-ci.org/ostinelli/pgpool.svg?branch=master)](https://travis-ci.org/ostinelli/pgpool)\n[![Hex pm](https://img.shields.io/hexpm/v/pgpool.svg)](https://hex.pm/packages/pgpool)\n\n# PGPool\nPGPool is a PosgreSQL client that automatically uses connection pools and handles reconnections in case of errors.  PGPool also optimizes all of your statements, by preparing them and caching them for you under the hood.\n\nIt uses:\n\n * [epgsql](https://github.com/epgsql/epgsql) as the PostgreSQL driver.\n * [poolboy](https://github.com/devinus/poolboy) as pooling library.\n\n\n## Install\n\n### For Elixir\nAdd it to your deps:\n\n```elixir\ndefp deps do\n  [{:pgpool, \"~\u003e 2.1\"}]\nend\n```\n\nEnsure that `pgpool` is started with your application, for example by adding it to the list of your application's `extra_applications`:\n\n```elixir\ndef application do\n  [\n    extra_applications: [:logger, :pgpool]\n  ]\nend\n```\n\n### For Erlang\nIf you're using [rebar3](https://github.com/erlang/rebar3), add `pgpool` as a dependency in your project's `rebar.config` file:\n\n```erlang\n{pgpool, {git, \"git://github.com/ostinelli/pgpool.git\", {tag, \"2.1.0\"}}}\n```\n\nOr, if you're using [Hex.pm](https://hex.pm/) as package manager (with the [rebar3_hex](https://github.com/hexpm/rebar3_hex) plugin):\n\n```erlang\n{pgpool, \"2.1.0\"}\n```\n\nEnsure that `pgpool` is started with your application, for example by adding it in your `.app` file to the list of `applications`:\n\n```erlang\n{application, my_app, [\n    %% ...\n    {applications, [\n        kernel,\n        stdlib,\n        sasl,\n        pgpool,\n        %% ...\n    ]},\n    %% ...\n]}.\n```\n\n## Usage\nSince `pgpool` is written in Erlang, the example code here below is in Erlang. Thanks to Elixir interoperability, the equivalent code in Elixir is straightforward.\n\n\n### Specify Databases\nDatabases can be set in the environment variable `pgpool`. You're probably best off using an application configuration file (in releases, `sys.config`):\n\n```erlang\n{pgpool, [\n  {databases, [\n    {db1_name, [\n      {pool, [\n        %% poolboy options \u003chttps://github.com/devinus/poolboy\u003e\n        %% The `name` and `worker_module` options here will be ignored.\n        {size, 10},        %% maximum pool size\n        {max_overflow, 5}, %% maximum number of additional workers created if pool is empty\n        {strategy, lifo}   %% can be lifo or fifo (default is lifo)\n      ]},\n      {connection, [\n        {host, \"localhost\"},\n        {user, \"postgres\"},\n        {pass, \"\"},\n        {options, [\n          %% epgsql connect_options() \u003chttps://github.com/epgsql/epgsql\u003e\n          {port, 5432},\n          {ssl, false},\n          {database, \"db1\"}\n        ]}\n      ]}\n    ]},\n\n    {db2_name, [\n      {pool, [\n        {size, 10},\n        {max_overflow, 20},\n        {strategy, lifo}\n      ]},\n      {connection, [\n        {host, \"localhost\"},\n        {user, \"postgres\"},\n        {pass, \"\"},\n        {options, [\n          {port, 5432},\n          {ssl, false},\n          {database, \"db2\"}\n        ]}\n      ]}\n    ]}\n  ]}\n]}\n```\n\n### Custom types\n\n```erlang\n-type pgpool_query_option() :: no_wait.\n```\n\n`no_wait` makes the query call return immediately if there are no available connections in the pool. This allows you to improve your application's flow control by rejecting external calls if your database is unable to handle the load, thus preventing a system overflow.\n\n### Queries\nPlease refer to [epgsql 3.4 README](https://github.com/epgsql/epgsql/blob/3.4.0/README.md) for how to perform queries. Currently, PGPool supports the following.\n\n#### Simple Query\n\n```erlang\npgpool:squery(DatabaseName, Sql) -\u003e\n  pgpool:squery(DatabaseName, Sql, []).\n```\n\n```erlang\npgpool:squery(DatabaseName, Sql) -\u003e\n  Result\n\nTypes:\n  DatabaseName = atom()\n  Sql = string() | iodata()\n  Options = [pgpool_query_option()]\n  Result = {ok, Count} | {ok, Count, Rows} | {error, no_connection | no_available_connections}\n  Count = non_neg_integer()\n  Rows = (see epgsql for more details)\n```\n\nFor example:\n\n```erlang\npgpool:squery(db1_name, \"SELECT * FROM users;\").\n```\n\n\u003e Simple queries cannot be optimized by PGPool since they cannot be prepared. If you want to optimize and cache your queries, consider using `equery/3,4` or `batch/2` instead.\n\n#### Extended Query\n\n```erlang\npgpool:equery(DatabaseName, Statement, Params) -\u003e\n  pgpool:equery(DatabaseName, Statement, Params, []).\n```\n\n```erlang\npgpool:equery(DatabaseName, Statement, Params, Options) -\u003e\n  Result\n\nTypes:\n  DatabaseName = atom()\n  Statement = string()\n  Params = list()\n  Options = [pgpool_query_option()]\n  Result = {ok, Count} | {ok, Count, Rows} | {error, no_connection | no_available_connections}\n  Count = non_neg_integer()\n  Rows = (see epgsql for more details)\n```\n\nFor example:\n\n```erlang\npgpool:equery(db1_name, \"SELECT * FROM users WHERE id = $1;\", [3]).\n```\n\n\u003e PGPool will prepare your statements and cache them for you, which results in considerable speed improvements. If you use a lot of different statements, consider memory usage because the statements are not garbage collected.\n\n#### Batch Queries\nTo execute a batch:\n\n```erlang\npgpool:batch(DatabaseName, StatementsWithParams) -\u003e\n  pgpool:batch(DatabaseName, StatementsWithParams, Options).\n```\n\n```erlang\npgpool:batch(DatabaseName, StatementsWithParams) -\u003e\n  Result\n\nTypes:\n  DatabaseName = atom()\n  StatementsWithParams = [{Statement, Params}]\n  Statement = string()\n  Params = list()\n  Options = [pgpool_query_option()]\n  Result = [{ok, Count} | {ok, Count, Rows}] | {error, no_connection | no_available_connections}\n  Count = non_neg_integer()\n  Rows = (see epgsql for more details)\n```\n\nFor example:\n\n```erlang\nS = \"INSERT INTO users (name) VALUES ($1);\",\n\n[{ok, 1}, {ok, 1}] = pgpool:batch(db1_name, [\n  {S, [\"Hedy\"]},\n  {S, [\"Roberto\"]}\n]).\n```\n\n\u003e PGPool will prepare your statements and cache them for you, which results in considerable speed improvements. If you use a lot of different statements, consider memory usage because the statements are not garbage collected.\n\n\n## Contributing\nSo you want to contribute? That's great! Please follow the guidelines below. It will make it easier to get merged in.\n\nBefore implementing a new feature, please submit a ticket to discuss what you intend to do. Your feature might already be in the works, or an alternative implementation might have already been discussed.\n\nDo not commit to master in your fork. Provide a clean branch without merge commits. Every pull request should have its own topic branch. In this way, every additional adjustments to the original pull request might be done easily, and squashed with `git rebase -i`. The updated branch will be visible in the same pull request, so there will be no need to open new pull requests when there are changes to be applied.\n\nEnsure that proper testing is included. To run PGPool tests, you need to create the database `pgpool_test` for user `postgres` with no password, and then simply run from the project's root directory:\n\n```\n$ make test\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fostinelli%2Fpgpool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fostinelli%2Fpgpool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fostinelli%2Fpgpool/lists"}