diff --git a/README.md b/README.md index 727d4375476..01dfc96872e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -| **
The Citus database is 100% open source.

Learn what's new in the [Citus 11.3 release blog](https://www.citusdata.com/blog/2023/05/05/whats-new-in-citus-11-3-multi-tenant-saas/) and the [Citus Updates page](https://www.citusdata.com/updates/).

**| +| **
The Citus database is 100% open source.

Learn what's new in the [Citus 12.0 release blog](https://www.citusdata.com/blog/2023/07/18/citus-12-schema-based-sharding-comes-to-postgres/) and the [Citus Updates page](https://www.citusdata.com/updates/).

**| |---|
@@ -38,6 +38,7 @@ Since Citus is an extension to Postgres, you can use Citus with the latest Postg - [Why Citus?](#why-citus) - [Getting Started](#getting-started) - [Using Citus](#using-citus) +- [Schema-based sharding](#schema-based-sharding) - [Setting up with High Availability](#setting-up-with-high-availability) - [Documentation](#documentation) - [Architecture](#architecture) @@ -94,14 +95,14 @@ Install packages on Ubuntu / Debian: ```bash curl https://install.citusdata.com/community/deb.sh > add-citus-repo.sh sudo bash add-citus-repo.sh -sudo apt-get -y install postgresql-15-citus-11.3 +sudo apt-get -y install postgresql-15-citus-12.0 ``` Install packages on CentOS / Red Hat: ```bash curl https://install.citusdata.com/community/rpm.sh > add-citus-repo.sh sudo bash add-citus-repo.sh -sudo yum install -y citus113_15 +sudo yum install -y citus120_15 ``` To add Citus to your local PostgreSQL database, add the following to `postgresql.conf`: @@ -347,6 +348,45 @@ When using columnar storage, you should only load data in batch using `COPY` or To learn more about columnar storage, check out the [columnar storage README](https://github.com/citusdata/citus/blob/master/src/backend/columnar/README.md). +## Schema-based sharding + +Available since Citus 12.0, [schema-based sharding](https://docs.citusdata.com/en/stable/get_started/concepts.html#schema-based-sharding) is the shared database, separate schema model, the schema becomes the logical shard within the database. Multi-tenant apps can a use a schema per tenant to easily shard along the tenant dimension. Query changes are not required and the application usually only needs a small modification to set the proper search_path when switching tenants. Schema-based sharding is an ideal solution for microservices, and for ISVs deploying applications that cannot undergo the changes required to onboard row-based sharding. + +### Creating distributed schemas + +You can turn an existing schema into a distriubuted schema by calling `citus_schema_distribute`: + +```sql +SELECT citus_schema_distribute('user_service'); +``` + +Alternatively, you can set `citus.enable_schema_based_sharding` to have all newly created schemas be automatically converted into distributed schemas: + +```sql +SET citus.enable_schema_based_sharding TO ON; + +CREATE SCHEMA AUTHORIZATION user_service; +CREATE SCHEMA AUTHORIZATION time_service; +CREATE SCHEMA AUTHORIZATION ping_service; +``` + +### Running queries + +Queries will be properly routed to schemas based on `search_path` or by explicitly using the schema name in the query. + +For [microservices](https://docs.citusdata.com/en/stable/get_started/tutorial_microservices.html) you would create a USER per service matching the schema name, hence the default `search_path` would contain the schema name. When connected the user queries would be automatically routed and no changes to the microservice would be required. + +```sql +CREATE USER user_service; +CREATE SCHEMA AUTHORIZATION user_service; +``` + +For typical multi-tenant applications, you would set the search path to the tenant schema name in your application: + +```sql +SET search_path = tenant_name, public; +``` + ## Setting up with High Availability One of the most popular high availability solutions for PostgreSQL, [Patroni 3.0](https://github.com/zalando/patroni), has [first class support for Citus 10.0 and above](https://patroni.readthedocs.io/en/latest/citus.html#citus), additionally since Citus 11.2 ships with improvements for smoother node switchover in Patroni. @@ -414,6 +454,8 @@ Citus is uniquely capable of scaling both analytical and transactional workloads Example multi-tenant SaaS users: [Copper](https://www.citusdata.com/customers/copper), [Salesloft](https://fivetran.com/case-studies/replicating-sharded-databases-a-case-study-of-salesloft-citus-data-and-fivetran), [ConvertFlow](https://www.citusdata.com/customers/convertflow) +- **[Microservices](https://docs.citusdata.com/en/stable/get_started/tutorial_microservices.html)**: Citus supports schema based sharding, which allows distributing regular database schemas across many machines. This sharding methodology fits nicely with typical Microservices architecture, where storage is fully owned by the service hence can’t share the same schema definition with other tenants. Citus allows distributing horizontally scalable state across services, solving one of the [main problems](https://stackoverflow.blog/2020/11/23/the-macro-problem-with-microservices/) of microservices. + - **Geospatial**: Because of the powerful [PostGIS](https://postgis.net/) extension to Postgres that adds support for geographic objects into Postgres, many people run spatial/GIS applications on top of Postgres. And since spatial location information has become part of our daily life, well, there are more geospatial applications than ever. When your Postgres database needs to scale out to handle an increased workload, Citus is a good fit.