All Projects → ostinelli → Pgpool

ostinelli / Pgpool

Licence: mit
A PosgreSQL client that automatically uses connection pools and handles reconnections in case of errors.

Programming Languages

erlang
1774 projects

Projects that are alternatives of or similar to Pgpool

Polyel-Framework
⚡️ Voltis Core: A PHP framework based on Swoole from the ground up
Stars: ✭ 22 (-42.11%)
Mutual labels:  connection-pool
tk-pool
A connection pool implementation for tokio
Stars: ✭ 20 (-47.37%)
Mutual labels:  connection-pool
Redis Plus Plus
Redis client written in C++
Stars: ✭ 428 (+1026.32%)
Mutual labels:  connection-pool
conn
netpoll事件驱动,goroutine协程池化,降低无效协程的资源占用,适用于高连接数(对于低频数据传输的场景,可以大幅降低协程数,提升资源利用率)
Stars: ✭ 28 (-26.32%)
Mutual labels:  connection-pool
swoole-postgresql-doctrine-driver
🔌 A Doctrine DBAL Driver implementation on top of Swoole Coroutine PostgreSQL client
Stars: ✭ 15 (-60.53%)
Mutual labels:  connection-pool
Xredis
Redis C++ client, support the data slice storage, support redis cluster, thread-safe,multi-platform,connection pool, read/write separation.
Stars: ✭ 285 (+650%)
Mutual labels:  connection-pool
honeycomb
A database connection pool that no one dares to use
Stars: ✭ 35 (-7.89%)
Mutual labels:  connection-pool
Nexer
Content based network multiplexer or redirector made with love and Go
Stars: ✭ 7 (-81.58%)
Mutual labels:  connection-pool
lighthouse
Easy clojure relational database queries, migrations and connection pooling
Stars: ✭ 19 (-50%)
Mutual labels:  connection-pool
Apnotic
A Ruby APNs HTTP/2 gem able to provide instant feedback.
Stars: ✭ 360 (+847.37%)
Mutual labels:  connection-pool
vertica-swoole-adapter
Provides a DB layer for Swoole-based applications to communicate to HP Vertica databases.
Stars: ✭ 14 (-63.16%)
Mutual labels:  connection-pool
grpcp
grpcp is a Grpc Persistent Connection Pool.
Stars: ✭ 96 (+152.63%)
Mutual labels:  connection-pool
Spring Boot Data Source Decorator
Spring Boot integration with p6spy, datasource-proxy, flexy-pool and spring-cloud-sleuth
Stars: ✭ 295 (+676.32%)
Mutual labels:  connection-pool
pool
Go library that wraps http.Client to provide seamless higher-level connection pooling features
Stars: ✭ 39 (+2.63%)
Mutual labels:  connection-pool
Hibernate Springboot
Collection of best practices for Java persistence performance in Spring Boot applications
Stars: ✭ 589 (+1450%)
Mutual labels:  connection-pool
PyMySQLPool
PyMySQL-based database connection pool.
Stars: ✭ 52 (+36.84%)
Mutual labels:  connection-pool
Stormpot
A fast object pool for the JVM
Stars: ✭ 267 (+602.63%)
Mutual labels:  connection-pool
Flexy Pool
FlexyPool adds metrics and failover strategies to a given Connection Pool, allowing it to resize on demand.
Stars: ✭ 856 (+2152.63%)
Mutual labels:  connection-pool
Libfastcommon
c common functions library extracted from my open source project FastDFS. this library is very simple and stable. functions including: string, logger, chain, hash, socket, ini file reader, base64 encode / decode, url encode / decode, fast timer, skiplist, object pool etc. detail info please see the c header files.
Stars: ✭ 739 (+1844.74%)
Mutual labels:  connection-pool
Hikari Cp
A Clojure wrapper to HikariCP JDBC connection pool
Stars: ✭ 334 (+778.95%)
Mutual labels:  connection-pool

Build Status Hex pm

PGPool

PGPool 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.

It uses:

Install

For Elixir

Add it to your deps:

defp deps do
  [{:pgpool, "~> 2.1"}]
end

Ensure that pgpool is started with your application, for example by adding it to the list of your application's extra_applications:

def application do
  [
    extra_applications: [:logger, :pgpool]
  ]
end

For Erlang

If you're using rebar3, add pgpool as a dependency in your project's rebar.config file:

{pgpool, {git, "git://github.com/ostinelli/pgpool.git", {tag, "2.1.0"}}}

Or, if you're using Hex.pm as package manager (with the rebar3_hex plugin):

{pgpool, "2.1.0"}

Ensure that pgpool is started with your application, for example by adding it in your .app file to the list of applications:

{application, my_app, [
    %% ...
    {applications, [
        kernel,
        stdlib,
        sasl,
        pgpool,
        %% ...
    ]},
    %% ...
]}.

Usage

Since pgpool is written in Erlang, the example code here below is in Erlang. Thanks to Elixir interoperability, the equivalent code in Elixir is straightforward.

Specify Databases

Databases can be set in the environment variable pgpool. You're probably best off using an application configuration file (in releases, sys.config):

{pgpool, [
  {databases, [
    {db1_name, [
      {pool, [
        %% poolboy options <https://github.com/devinus/poolboy>
        %% The `name` and `worker_module` options here will be ignored.
        {size, 10},        %% maximum pool size
        {max_overflow, 5}, %% maximum number of additional workers created if pool is empty
        {strategy, lifo}   %% can be lifo or fifo (default is lifo)
      ]},
      {connection, [
        {host, "localhost"},
        {user, "postgres"},
        {pass, ""},
        {options, [
          %% epgsql connect_options() <https://github.com/epgsql/epgsql>
          {port, 5432},
          {ssl, false},
          {database, "db1"}
        ]}
      ]}
    ]},

    {db2_name, [
      {pool, [
        {size, 10},
        {max_overflow, 20},
        {strategy, lifo}
      ]},
      {connection, [
        {host, "localhost"},
        {user, "postgres"},
        {pass, ""},
        {options, [
          {port, 5432},
          {ssl, false},
          {database, "db2"}
        ]}
      ]}
    ]}
  ]}
]}

Custom types

-type pgpool_query_option() :: no_wait.

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.

Queries

Please refer to epgsql 3.4 README for how to perform queries. Currently, PGPool supports the following.

Simple Query

pgpool:squery(DatabaseName, Sql) ->
  pgpool:squery(DatabaseName, Sql, []).
pgpool:squery(DatabaseName, Sql) ->
  Result

Types:
  DatabaseName = atom()
  Sql = string() | iodata()
  Options = [pgpool_query_option()]
  Result = {ok, Count} | {ok, Count, Rows} | {error, no_connection | no_available_connections}
  Count = non_neg_integer()
  Rows = (see epgsql for more details)

For example:

pgpool:squery(db1_name, "SELECT * FROM users;").

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.

Extended Query

pgpool:equery(DatabaseName, Statement, Params) ->
  pgpool:equery(DatabaseName, Statement, Params, []).
pgpool:equery(DatabaseName, Statement, Params, Options) ->
  Result

Types:
  DatabaseName = atom()
  Statement = string()
  Params = list()
  Options = [pgpool_query_option()]
  Result = {ok, Count} | {ok, Count, Rows} | {error, no_connection | no_available_connections}
  Count = non_neg_integer()
  Rows = (see epgsql for more details)

For example:

pgpool:equery(db1_name, "SELECT * FROM users WHERE id = $1;", [3]).

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.

Batch Queries

To execute a batch:

pgpool:batch(DatabaseName, StatementsWithParams) ->
  pgpool:batch(DatabaseName, StatementsWithParams, Options).
pgpool:batch(DatabaseName, StatementsWithParams) ->
  Result

Types:
  DatabaseName = atom()
  StatementsWithParams = [{Statement, Params}]
  Statement = string()
  Params = list()
  Options = [pgpool_query_option()]
  Result = [{ok, Count} | {ok, Count, Rows}] | {error, no_connection | no_available_connections}
  Count = non_neg_integer()
  Rows = (see epgsql for more details)

For example:

S = "INSERT INTO users (name) VALUES ($1);",

[{ok, 1}, {ok, 1}] = pgpool:batch(db1_name, [
  {S, ["Hedy"]},
  {S, ["Roberto"]}
]).

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.

Contributing

So you want to contribute? That's great! Please follow the guidelines below. It will make it easier to get merged in.

Before 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.

Do 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.

Ensure 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:

$ make test
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].