graph-node instance. When a graph-node instance outgrows a single Postgres database, you can split storage across multiple Postgres databases.
Overview
All databases together form the store of thegraph-node instance. Each individual database is called a shard.
Multiple databases are configured through the TOML configuration file in the
[store] section. See the Configuration File documentation for general setup.Primary Shard
The[store] section must always have a primary shard configured, which must be called primary.
- System-wide metadata
- Mapping of subgraph names to IPFS hashes
- Directory of all subgraphs and their storage shards
- List of configured chains
- Metadata that rarely changes
Frequently changing metadata (like subgraph head pointers) is stored in individual shards, not the primary.
Read Replicas
Each shard can have additional read replicas used for responding to queries. Only queries are processed by read replicas - indexing and block ingestion always use the main database.Basic Replica Configuration
Query Traffic Distribution
Query traffic is split between the main database and replicas according to their weights.How Weight Distribution Works
How Weight Distribution Works
Weights are proportional:
- Weight
0= receives no traffic - Weight
1= receives equal share - Weight
2= receives twice as much as weight1
main: weight=1, repl1: weight=1, repl2: weight=2:- Total weight = 4
- Main gets 25% (1/4)
- Repl1 gets 25% (1/4)
- Repl2 gets 50% (2/4)
Multiple Shards Configuration
Add any number of additional shards with their own read replicas:Connection Pool Size
Each shard must indicate how many database connections eachgraph-node instance should keep in its connection pool.
Fixed Pool Size
Set a single value for all nodes:Replica Pool Size
For replicas, pool size defaults to the main database’s pool size but can be set explicitly:Rule-Based Pool Size
Use different pool sizes for differentgraph-node instances based on their node_id:
Rules are checked in order, and the first matching rule is used. If no rule matches, configuration loading fails.
Verifying Connection Pools
Always verify connection pool configuration after changes:- Connections per
graph-nodeinstance - Total database connections across all instances
- Which rules matched for each node
Connection String Format
Theconnection string must be a valid libpq connection string.
Environment Variable Expansion
Environment variables embedded in connection strings are expanded before passing to Postgres:Supported Formats
Directing Data to Shards
Control which shard stores data using:- Deployment rules - Route subgraph data to specific shards
- Chain configuration - Store block cache for chains in specific shards
Deployment Rules Example
Chain Shard Example
Use Cases
High-Traffic Separation
Dedicate a shard with high resources to a few high-traffic subgraphs while other subgraphs share a separate shard.
Customer Tiers
Separate VIP/production subgraphs onto premium hardware while community subgraphs use standard resources.
Network Isolation
Store different blockchain networks in separate shards for independent scaling and maintenance.
Read Scaling
Add read replicas to high-query shards without affecting indexing performance.
Complete Example
Production Multi-Database Setup
Production Multi-Database Setup
Best Practices
Start Simple, Scale Later
Start Simple, Scale Later
Begin with a single database. Add shards only when you hit resource limits. Existing subgraphs can remain in the primary shard after adding new shards.
Isolate High-Traffic Subgraphs
Isolate High-Traffic Subgraphs
Put high-traffic subgraphs in dedicated shards with more resources. This prevents them from affecting other subgraphs.
Use Replicas for Read Scaling
Use Replicas for Read Scaling
Add read replicas before adding new shards. Replicas are simpler to manage and often solve query performance issues.
Monitor Connection Pools
Monitor Connection Pools
Regularly verify connection pool sizes with
graphman config pools. Adjust based on actual database connection usage.Set Primary Weight to Zero
Set Primary Weight to Zero
In production, set primary shard main database weight to
0 and use replicas for queries. This isolates indexing from query load.Plan for Growth
Plan for Growth
Use deployment rules with
shards (array) instead of shard (single) for the default rule. This allows automatic distribution as you add shards.Migration from Single Database
When migrating from a single database to multiple databases:- The original database becomes the
primaryshard - Existing subgraphs and block caches remain in primary
- Configure new shards in the configuration file
- New deployments route to appropriate shards via deployment rules
- Optionally move existing deployments with
graphman copy(see Sharding)
No downtime is required when adding new shards. The system continues operating on existing shards while new shards are initialized.

