{"id":24739290,"url":"https://github.com/carapacik/postresql-sharding-example","last_synced_at":"2026-04-19T19:06:25.287Z","repository":{"id":235663242,"uuid":"694588531","full_name":"Carapacik/postresql-sharding-example","owner":"Carapacik","description":"PostgreSQL sharding example","archived":false,"fork":false,"pushed_at":"2023-09-21T12:25:20.000Z","size":3,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-22T18:46:08.642Z","etag":null,"topics":["docker","example","postgresql","sharding"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Carapacik.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-09-21T09:49:27.000Z","updated_at":"2023-10-03T09:24:03.000Z","dependencies_parsed_at":"2024-04-24T07:01:48.439Z","dependency_job_id":"23cf643e-ef0a-46cc-bea2-167e690746ce","html_url":"https://github.com/Carapacik/postresql-sharding-example","commit_stats":null,"previous_names":["carapacik/postresql-sharding-example"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Carapacik/postresql-sharding-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Carapacik%2Fpostresql-sharding-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Carapacik%2Fpostresql-sharding-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Carapacik%2Fpostresql-sharding-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Carapacik%2Fpostresql-sharding-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Carapacik","download_url":"https://codeload.github.com/Carapacik/postresql-sharding-example/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Carapacik%2Fpostresql-sharding-example/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32018774,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-18T20:23:30.271Z","status":"online","status_checked_at":"2026-04-19T02:00:07.110Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["docker","example","postgresql","sharding"],"created_at":"2025-01-27T22:57:31.146Z","updated_at":"2026-04-19T19:06:25.250Z","avatar_url":"https://github.com/Carapacik.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"PostgreSQL sharding example\n\n### Setup the first shard\n```shell\ndocker-compose up -d postgres_db1\ndocker exec -it postgres_db1 psql -U postgres -d clients -f /scripts/shards.sql -a\n```\n\n### Setup the second shard\n```shell\ndocker-compose up -d postgres_db2\ndocker exec -it postgres_db2 psql -U postgres -d clients -f /scripts/shards.sql -a\n```\n\n### Setup the main server\n```shell\ndocker-compose up -d postgres_db\ndocker exec -it postgres_db psql -U postgres -d clients -f /scripts/shards.sql -a\n```\n\n### Test insert performance with sharding(MacBook Pro M1 Pro)\n\n\n```shell\ndocker exec -it postgres_db psql -U postgres -d clients -c '\\timing' -f /scripts/seed.sql\n```\nAdd 5 000 000 rows\n```shell\nTime: 40321.847 ms (00:40.322)\n\nTime: 9845.150 ms (00:09.845)\n```\n\n### Test insert performance without sharding(MacBook Pro M1 Pro)\n\n\n```shell\ndocker exec -it postgres_db psql -U postgres -d clients -f /scripts/without_shards.sql -a\ndocker exec -it postgres_db psql -U postgres -d clients -c '\\timing' -f /scripts/seed_without_shards.sql\n```\nAdd 5 000 000 rows\n```shell\nTime: 1407.495 ms (00:01.407)\n\nTime: 2355.717 ms (00:02.356)\n```\n### Test select performance\n#### From single table\nShard 1 with constraint `id % 2 = 0`\n```shell\ndocker exec -it postgres_db1 psql -U postgres -d clients -c '\\timing' -c \"select count(*) from clients\"\ndocker exec -it postgres_db psql -U postgres -d clients -c '\\timing' -c \"select count(*) from clients where id % 2 = 0\"\n```\n\nShard 2 with constraint `id % 2 = 1`\n```shell\ndocker exec -it postgres_db2 psql -U postgres -d clients -c '\\timing' -c \"select count(*) from clients\"\ndocker exec -it postgres_db psql -U postgres -d clients -c '\\timing' -c \"select count(*) from clients where id % 2 = 1\"\n```\n\nWithout sharding\n```shell\ndocker exec -it postgres_db psql -U postgres -d clients -c '\\timing' -c \"select count(*) from clients_without_sharding\"\ndocker exec -it postgres_db psql -U postgres -d clients -c '\\timing' -c \"select count(*) from clients_without_sharding where id % 2 = 1\"\n```\n\n#### With join\nWith sharding\n```shell\ndocker exec -it postgres_db psql -U postgres -d clients -c '\\timing' -c \"select count(*) from leads left join clients on leads.client_id = clients.id where leads.summ \u003e 50000 and leads.client_id % 2 = 1\"\n```\n\nWithout sharding\n```shell\ndocker exec -it postgres_db psql -U postgres -d clients -c '\\timing' -c \"select count(*) from leads_without_sharding left join clients_without_sharding on leads_without_sharding.client_id = clients_without_sharding.id where leads_without_sharding.summ \u003e 50000 and leads_without_sharding.client_id % 2 = 1\"\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcarapacik%2Fpostresql-sharding-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcarapacik%2Fpostresql-sharding-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcarapacik%2Fpostresql-sharding-example/lists"}