Skip to content

Commit 60d976f

Browse files
committed
look at all that
1 parent b0b082c commit 60d976f

5 files changed

Lines changed: 24 additions & 11 deletions

File tree

docs/features/sharding/manual-routing.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ The PostgreSQL query language supports adding inline comments to queries. They a
3030
The following query will be sent to shard number zero:
3131

3232
```postgresql
33-
/* pgdog_shard: 0 */ CREATE INDEX CONCURRENTLY users_id_idx USING btree(id);
33+
/* pgdog_shard: 0 */ CREATE INDEX CONCURRENTLY users_id_idx ON users USING btree(id);
3434
```
3535
=== "Sharding key"
3636
This query will be sent to whichever shard maps to the key `"us-east-1"`:
@@ -70,7 +70,7 @@ The `SET` command comes from the PostgreSQL query language and is used to change
7070
```postgresql
7171
BEGIN;
7272
SET LOCAL pgdog.shard TO 0;
73-
CREATE INDEX users_id_idx USING btree(id);
73+
CREATE INDEX users_id_idx ON users USING btree(id);
7474
COMMIT;
7575
```
7676
=== "Sharding key"

docs/features/sharding/sequences.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,16 @@ Sharded sequences combine two Postgres primitives:
2727
The two are called inside a PL/pgSQL function that fetches numbers from a sequence until `satisfies_hash_partition` returns `true`, for the total number of shards in the cluster and the shard number it's being executed on:
2828

2929
```postgresql
30-
LOOP
31-
SELECT nextval('normal_seq'::regclass) INTO val;
30+
DO $$
31+
BEGIN
32+
LOOP
33+
SELECT nextval('normal_seq'::regclass) INTO val;
3234
33-
IF satisfies_hash_partition(/* ... */, val) THEN
35+
IF satisfies_hash_partition(/* ... */, val) THEN
3436
RETURN val;
35-
END IF;
36-
37-
END;
37+
END IF;
38+
END LOOP;
39+
END $$;
3840
```
3941

4042
Since fetching values from a sequence is very quick, we are able to find the correct number without introducing significant latency to row creation. The Postgres hash function is also good at producing uniform outputs, so all shards will have similar, small gaps between generated numbers.

docs/features/sharding/sharding-functions.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,27 @@ All queries referencing the `user_id` column will be automatically sent to the m
5151
Different integer types are treated the same by the query router. If you're using `BIGINT`, `INTEGER` or `SMALLINT` as your sharding key, you can specify `bigint` in the configuration:
5252

5353
```toml
54+
[[sharded_tables]]
55+
database = "prod"
56+
column = "user_id"
5457
data_type = "bigint"
5558
```
5659
=== "Text"
5760
!!! note "Text types"
5861
`VARCHAR`, `VARCHAR(n)`, and `TEXT` use the same encoding and are treated the same by the query router. For either one, you can specify `varchar` in the configuration:
5962
```toml
63+
[[sharded_tables]]
64+
database = "prod"
65+
column = "serial_number"
6066
data_type = "varchar"
6167
```
6268
=== "UUID"
6369
!!! note "UUID types"
6470
Only UUIDv4 is currently supported for sharding in the query router.
6571
```toml
72+
[[sharded_tables]]
73+
database = "prod"
74+
column = "unique_id"
6675
data_type = "uuid"
6776
```
6877

docs/migrating-to-pgdog/from-pgbouncer.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ Both PgBouncer and PgDog can override the user's password used to connect to Pos
5858
name = "prod"
5959
host = "10.0.0.1"
6060
port = 5432
61-
server_user = "postgres"
62-
server_password = "hunter2"
61+
user = "postgres"
62+
password = "hunter2"
6363
pooler_mode = "transaction"
6464
```
6565

tests/test_code_blocks.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def verify(binary):
3030
info = m.group("info").strip().lower()
3131
indent = m.group("indent")
3232
code = m.group("code")
33+
original = code
3334
if indent:
3435
# Dedent the code body so configcheck/pglast see clean text.
3536
stripped_lines = []
@@ -56,7 +57,8 @@ def verify(binary):
5657
if cmd in code:
5758
found = True
5859
if not found:
59-
print(code)
60+
print(f"Error in {file}:")
61+
print(original)
6062
raise e
6163

6264
def check_file(binary, kind, content):

0 commit comments

Comments
 (0)