Giter VIP home page Giter VIP logo

pg-sharding's Introduction

@clickup/pg-sharding: micro-shards support for PostgreSQL

See also TS API documentation.

CI run

Each micro-shard is a PG schema with numeric suffix. Micro-shards have the same set of tables with same names; it's up to the higher-level tools to keep the schemas of all those tables in sync (e.g. see pg-mig tool).

Micro-shards can be moved from one PG master to another. There is no need to stop writes while moving micro-shards: the tool uses PG logical replication to stream each micro-shard table's data, and in the very end, acquires a quick exclusive lock to finalize the move.

 pg-sharding move
   --shard=N --from=DSN --to=DSN
   [--activate-on-destination]
   [--deactivate-script='SQL $1 SQL']

Each micro-shard can either be "active" or "inactive".

The library exposes low-level API for other higher-level tools as PG functions:

  • sharding_list_active_shards(): returns the list of "active" shards
  • sharding_ensure_exist(): allocates a new range micro-shard
  • sharding_ensure_active(): activates a range of micro-shards
  • sharding_ensure_inactive(): deactivates a range of micro-shards
  • sharding_ensure_absent(): drops a range of micro-shards
  • sharding_do_on_each(): a helper function to run an SQL query on all shards
  • sharding_debug_fdw_create(): creates "debug foreign shards schemas" for each host in the list.
  • sharding_debug_fds_drop(): drops all debug foreign shards schemas previously created.
  • sharding_debug_views_create(): creates "debug views" for tables in all micro-shards which unions SELECTs from the same-named tables in all shards (not used in production, only for debugging purposes)
  • sharding_debug_views_drop(): drops all of the debug views

pg-sharding's People

Contributors

dimikot avatar

Stargazers

Elliot V Pourmand avatar Taras Zubyk avatar

Watchers

 avatar Alex Yurkowski avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.