pgslice 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/LICENSE.txt +1 -1
- data/README.md +25 -22
- data/lib/pgslice/cli/prep.rb +1 -1
- data/lib/pgslice/helpers.rb +2 -2
- data/lib/pgslice/table.rb +1 -1
- data/lib/pgslice/version.rb +1 -1
- data/lib/pgslice.rb +1 -0
- metadata +4 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 325b5cd0c6ec6dfa7a98db88a06bb47ed4f8ee327c6c21dddfd897ec13f54533
|
4
|
+
data.tar.gz: aabbfee0e2bced3b7e93f4d9f0db218db060779a3b75b14ac7056867901bae26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba7310102950041d8247779282b6b252d40d7c824bd03b07d08ed7e400534cbf44eb31161595004ff782ccdaa9eacd0d6698797068ea06109ef974eebab8439b
|
7
|
+
data.tar.gz: 50faa245fb1ac68b6b685af8529277f23a46146477fd37e9ec52a6984222daa3392ca49e9d5276f03177f755ccec5c94989d4f6f25e182f3013ed9b24a8a7250
|
data/CHANGELOG.md
CHANGED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -4,7 +4,7 @@ Postgres partitioning as easy as pie. Works great for both new and existing tabl
|
|
4
4
|
|
5
5
|
:tangerine: Battle-tested at [Instacart](https://www.instacart.com/opensource)
|
6
6
|
|
7
|
-
[](https://github.com/ankane/pgslice/actions)
|
8
8
|
|
9
9
|
## Install
|
10
10
|
|
@@ -92,11 +92,11 @@ pgslice prep visits created_at month
|
|
92
92
|
```sql
|
93
93
|
BEGIN;
|
94
94
|
|
95
|
-
CREATE TABLE "public"."visits_intermediate" (LIKE "public"."visits" INCLUDING DEFAULTS INCLUDING CONSTRAINTS INCLUDING STORAGE INCLUDING COMMENTS) PARTITION BY RANGE ("created_at");
|
95
|
+
CREATE TABLE "public"."visits_intermediate" (LIKE "public"."visits" INCLUDING DEFAULTS INCLUDING CONSTRAINTS INCLUDING STORAGE INCLUDING COMMENTS INCLUDING STATISTICS INCLUDING GENERATED INCLUDING COMPRESSION) PARTITION BY RANGE ("created_at");
|
96
96
|
|
97
97
|
CREATE INDEX ON "public"."visits_intermediate" USING btree ("created_at");
|
98
98
|
|
99
|
-
COMMENT ON TABLE "public"."visits_intermediate" is 'column:
|
99
|
+
COMMENT ON TABLE "public"."visits_intermediate" is 'column:created_at,period:month,cast:date,version:3';
|
100
100
|
|
101
101
|
COMMIT;
|
102
102
|
```
|
@@ -108,17 +108,17 @@ pgslice add_partitions visits --intermediate --past 1 --future 1
|
|
108
108
|
```sql
|
109
109
|
BEGIN;
|
110
110
|
|
111
|
-
CREATE TABLE "public"."
|
111
|
+
CREATE TABLE "public"."visits_202408" PARTITION OF "public"."visits_intermediate" FOR VALUES FROM ('2024-08-01') TO ('2024-09-01');
|
112
112
|
|
113
|
-
ALTER TABLE "public"."
|
113
|
+
ALTER TABLE "public"."visits_202408" ADD PRIMARY KEY ("id");
|
114
114
|
|
115
|
-
CREATE TABLE "public"."
|
115
|
+
CREATE TABLE "public"."visits_202409" PARTITION OF "public"."visits_intermediate" FOR VALUES FROM ('2024-09-01') TO ('2024-10-01');
|
116
116
|
|
117
|
-
ALTER TABLE "public"."
|
117
|
+
ALTER TABLE "public"."visits_202409" ADD PRIMARY KEY ("id");
|
118
118
|
|
119
|
-
CREATE TABLE "public"."
|
119
|
+
CREATE TABLE "public"."visits_202410" PARTITION OF "public"."visits_intermediate" FOR VALUES FROM ('2024-10-01') TO ('2024-11-01');
|
120
120
|
|
121
|
-
ALTER TABLE "public"."
|
121
|
+
ALTER TABLE "public"."visits_202410" ADD PRIMARY KEY ("id");
|
122
122
|
|
123
123
|
COMMIT;
|
124
124
|
```
|
@@ -131,17 +131,17 @@ pgslice fill visits
|
|
131
131
|
/* 1 of 3 */
|
132
132
|
INSERT INTO "public"."visits_intermediate" ("id", "user_id", "ip", "created_at")
|
133
133
|
SELECT "id", "user_id", "ip", "created_at" FROM "public"."visits"
|
134
|
-
WHERE "id" > 0 AND "id" <= 10000 AND "created_at" >= '
|
134
|
+
WHERE "id" > 0 AND "id" <= 10000 AND "created_at" >= '2024-08-01'::date AND "created_at" < '2024-11-01'::date
|
135
135
|
|
136
136
|
/* 2 of 3 */
|
137
137
|
INSERT INTO "public"."visits_intermediate" ("id", "user_id", "ip", "created_at")
|
138
138
|
SELECT "id", "user_id", "ip", "created_at" FROM "public"."visits"
|
139
|
-
WHERE "id" > 10000 AND "id" <= 20000 AND "created_at" >= '
|
139
|
+
WHERE "id" > 10000 AND "id" <= 20000 AND "created_at" >= '2024-08-01'::date AND "created_at" < '2024-11-01'::date
|
140
140
|
|
141
141
|
/* 3 of 3 */
|
142
142
|
INSERT INTO "public"."visits_intermediate" ("id", "user_id", "ip", "created_at")
|
143
143
|
SELECT "id", "user_id", "ip", "created_at" FROM "public"."visits"
|
144
|
-
WHERE "id" > 20000 AND "id" <= 30000 AND "created_at" >= '
|
144
|
+
WHERE "id" > 20000 AND "id" <= 30000 AND "created_at" >= '2024-08-01'::date AND "created_at" < '2024-11-01'::date
|
145
145
|
```
|
146
146
|
|
147
147
|
```sh
|
@@ -149,11 +149,11 @@ pgslice analyze visits
|
|
149
149
|
```
|
150
150
|
|
151
151
|
```sql
|
152
|
-
ANALYZE VERBOSE "public"."
|
152
|
+
ANALYZE VERBOSE "public"."visits_202408";
|
153
153
|
|
154
|
-
ANALYZE VERBOSE "public"."
|
154
|
+
ANALYZE VERBOSE "public"."visits_202409";
|
155
155
|
|
156
|
-
ANALYZE VERBOSE "public"."
|
156
|
+
ANALYZE VERBOSE "public"."visits_202410";
|
157
157
|
|
158
158
|
ANALYZE VERBOSE "public"."visits_intermediate";
|
159
159
|
```
|
@@ -217,14 +217,14 @@ WHERE
|
|
217
217
|
Back up and drop older partitions each day, month, or year.
|
218
218
|
|
219
219
|
```sh
|
220
|
-
pg_dump -c -Fc -t <table>
|
221
|
-
psql -c "DROP TABLE <table>
|
220
|
+
pg_dump -c -Fc -t <table>_202409 $PGSLICE_URL > <table>_202409.dump
|
221
|
+
psql -c "DROP TABLE <table>_202409" $PGSLICE_URL
|
222
222
|
```
|
223
223
|
|
224
224
|
If you use [Amazon S3](https://aws.amazon.com/s3/) for backups, [s3cmd](https://github.com/s3tools/s3cmd) is a nice tool.
|
225
225
|
|
226
226
|
```sh
|
227
|
-
s3cmd put <table>
|
227
|
+
s3cmd put <table>_202409.dump s3://<s3-bucket>/<table>_202409.dump
|
228
228
|
```
|
229
229
|
|
230
230
|
## Schema Updates
|
@@ -267,7 +267,7 @@ SELECT * FROM
|
|
267
267
|
WHERE
|
268
268
|
user_id = 123 AND
|
269
269
|
-- for performance
|
270
|
-
created_at >= '
|
270
|
+
created_at >= '2024-09-01' AND created_at < '2024-09-02'
|
271
271
|
```
|
272
272
|
|
273
273
|
For this to be effective, ensure `constraint_exclusion` is set to `partition` (the default value) or `on`.
|
@@ -365,7 +365,6 @@ gem specific_install https://github.com/ankane/pgslice.git
|
|
365
365
|
## Reference
|
366
366
|
|
367
367
|
- [PostgreSQL Manual](https://www.postgresql.org/docs/current/static/ddl-partitioning.html)
|
368
|
-
- [PostgreSQL Wiki](https://wiki.postgresql.org/wiki/Table_partitioning)
|
369
368
|
|
370
369
|
## Related Projects
|
371
370
|
|
@@ -375,6 +374,10 @@ Also check out:
|
|
375
374
|
- [PgHero](https://github.com/ankane/pghero) - A performance dashboard for Postgres
|
376
375
|
- [pgsync](https://github.com/ankane/pgsync) - Sync Postgres data to your local machine
|
377
376
|
|
377
|
+
## History
|
378
|
+
|
379
|
+
View the [changelog](https://github.com/ankane/pgslice/blob/master/CHANGELOG.md)
|
380
|
+
|
378
381
|
## Contributing
|
379
382
|
|
380
383
|
Everyone is encouraged to help improve this project. Here are a few ways you can help:
|
@@ -397,8 +400,8 @@ bundle exec rake test
|
|
397
400
|
To test against different versions of Postgres with Docker, use:
|
398
401
|
|
399
402
|
```sh
|
400
|
-
docker run -p=8000:5432 postgres:
|
403
|
+
docker run -p=8000:5432 postgres:16
|
401
404
|
TZ=Etc/UTC PGSLICE_URL=postgres://postgres@localhost:8000/postgres bundle exec rake
|
402
405
|
```
|
403
406
|
|
404
|
-
On Mac, you must use [Docker
|
407
|
+
On Mac, you must use [Docker Desktop](https://www.docker.com/products/docker-desktop/) for the port mapping to localhost to work.
|
data/lib/pgslice/cli/prep.rb
CHANGED
@@ -4,7 +4,7 @@ module PgSlice
|
|
4
4
|
option :partition, type: :boolean, default: true, desc: "Partition the table"
|
5
5
|
option :trigger_based, type: :boolean, default: false, desc: "Use trigger-based partitioning"
|
6
6
|
option :test_version, type: :numeric, hide: true
|
7
|
-
def prep(table, column=nil, period=nil)
|
7
|
+
def prep(table, column = nil, period = nil)
|
8
8
|
table = create_table(table)
|
9
9
|
intermediate_table = table.intermediate_table
|
10
10
|
trigger_name = table.trigger_name
|
data/lib/pgslice/helpers.rb
CHANGED
@@ -41,8 +41,8 @@ module PgSlice
|
|
41
41
|
say message
|
42
42
|
end
|
43
43
|
@server_version_num = conn.exec("SHOW server_version_num")[0]["server_version_num"].to_i
|
44
|
-
if @server_version_num <
|
45
|
-
abort "This version of pgslice requires Postgres
|
44
|
+
if @server_version_num < 130000
|
45
|
+
abort "This version of pgslice requires Postgres 13+"
|
46
46
|
end
|
47
47
|
conn
|
48
48
|
end
|
data/lib/pgslice/table.rb
CHANGED
@@ -16,7 +16,7 @@ module PgSlice
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def columns
|
19
|
-
execute("SELECT column_name FROM information_schema.columns WHERE table_schema = $1 AND table_name = $2 AND is_generated = 'NEVER'", [schema, name]).map{ |r| r["column_name"] }
|
19
|
+
execute("SELECT column_name FROM information_schema.columns WHERE table_schema = $1 AND table_name = $2 AND is_generated = 'NEVER'", [schema, name]).map { |r| r["column_name"] }
|
20
20
|
end
|
21
21
|
|
22
22
|
# http://www.dbforums.com/showthread.php?1667561-How-to-list-sequences-and-the-columns-by-SQL
|
data/lib/pgslice/version.rb
CHANGED
data/lib/pgslice.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pgslice
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
|
-
autorequire:
|
9
8
|
bindir: exe
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: pg
|
@@ -38,7 +37,6 @@ dependencies:
|
|
38
37
|
- - ">="
|
39
38
|
- !ruby/object:Gem::Version
|
40
39
|
version: '0'
|
41
|
-
description:
|
42
40
|
email: andrew@ankane.org
|
43
41
|
executables:
|
44
42
|
- pgslice
|
@@ -65,7 +63,6 @@ homepage: https://github.com/ankane/pgslice
|
|
65
63
|
licenses:
|
66
64
|
- MIT
|
67
65
|
metadata: {}
|
68
|
-
post_install_message:
|
69
66
|
rdoc_options: []
|
70
67
|
require_paths:
|
71
68
|
- lib
|
@@ -73,15 +70,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
73
70
|
requirements:
|
74
71
|
- - ">="
|
75
72
|
- !ruby/object:Gem::Version
|
76
|
-
version: '
|
73
|
+
version: '3'
|
77
74
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
75
|
requirements:
|
79
76
|
- - ">="
|
80
77
|
- !ruby/object:Gem::Version
|
81
78
|
version: '0'
|
82
79
|
requirements: []
|
83
|
-
rubygems_version: 3.
|
84
|
-
signing_key:
|
80
|
+
rubygems_version: 3.6.7
|
85
81
|
specification_version: 4
|
86
82
|
summary: Postgres partitioning as easy as pie
|
87
83
|
test_files: []
|