GithubHelp home page GithubHelp logo

sharding on schema about pgcat HOT 3 CLOSED

DeoLeung avatar DeoLeung commented on July 28, 2024 1
sharding on schema

from pgcat.

Comments (3)

levkk avatar levkk commented on July 28, 2024

Hey @DeoLeung , give #79 a try and let me know if it works for you. Each shard now has a search_path configuration parameter, to which you can add the schema you're using in each shard; see example in CircleCI config.

That schema will be automatically findable when that shard is queried, e.g.

SET SHARD TO 1;
SELECT * FROM some_table; 
-- This will automatically look in
-- $user.some_table,
-- public.some_table,
-- and finally in shard_1.some_table

from pgcat.

DeoLeung avatar DeoLeung commented on July 28, 2024

I patch it and did a demo, which works

-- in pg 1
CREATE SCHEMA dm_1;


CREATE TABLE dm_1.test (
id INT
);

INSERT INTO dm_1.test VALUES (1), (3);

SELECT * FROM dm_1.test;

-- in pg2
CREATE SCHEMA dm_2;


CREATE TABLE dm_2.test (
id INT
);

INSERT INTO dm_2.test VALUES (2), (4);

SELECT * FROM dm_2.test;
  • connect to pgcat
postgres@cb1fed2d6844:/$ psql -h pgcat -p 6432
Password for user postgres:
psql (13.7 (Debian 13.7-1.pgdg110+1))
Type "help" for help.
postgres=# show databases;
ERROR:  unrecognized configuration parameter "databases"
postgres=# SHOW DATABASES;
ERROR:  unrecognized configuration parameter "databases"
postgres=# SET SHARD TO '1';
SET SHARD
postgres=# select * from test;
 id
----
  2
  4
(2 rows)

postgres=# SET SHARD TO '0';
SET SHARD
postgres=# select * from test;
 id
----
  1
  3
(2 rows)

postgres=# select * from dm_2.test;
ERROR:  relation "dm_2.test" does not exist
LINE 1: select * from dm_2.test;
                      ^
postgres=# select * from dm_1.test;
 id
----
  1
  3
(2 rows)

postgres=# SET SHARD TO '1';
SET SHARD
postgres=# select * from dm_1.test;
ERROR:  relation "dm_1.test" does not exist
LINE 1: select * from dm_1.test;
                      ^
postgres=# select * from dm_2.test;
 id
----
  2
  4
(2 rows)

postgres=#

will start to deploy pgcat to our test cluster for some real work. further feedback may take quite a while though.
we use to dispatch our sql with full identifier(including schema), so I think we don't really need the search_path setting.
having SET SHARD to force following queries route to a specific db is enough for our scenario at the moment.

from pgcat.

levkk avatar levkk commented on July 28, 2024

Great, thanks for your feedback and good luck with your test!

from pgcat.

Related Issues (20)

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.