pgslice 0.4.8 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/LICENSE.txt +1 -1
- data/README.md +33 -29
- data/lib/pgslice/cli/add_partitions.rb +1 -1
- data/lib/pgslice/cli/prep.rb +2 -2
- data/lib/pgslice/version.rb +1 -1
- data/lib/pgslice.rb +11 -11
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38dff970617c4a96ee7b9234d345e841e0c496d02abbc1900a028a7f0cb46b87
|
4
|
+
data.tar.gz: 24aa5b2b515991c0310fc3dc8cf54c6a7f322b4ee8743bc5e745ca85a1831cec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f63af4550ae70f3fe03e3e4104a43652529d0da576f909c23512ea4a3fa12e2b7f3dd9c526821c69f4b01ec685c5f72d9c8988e5ff4ae74f391e846540c068f4
|
7
|
+
data.tar.gz: 405bb97384272d35e85fb0395e8ec367d1db62bdd7120cb0c9f03c9faa728c804256949fbc78eaf8c048b21aefe93106b3da60f8f9741e83dbb47aec23e64008
|
data/CHANGELOG.md
CHANGED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -14,7 +14,7 @@ pgslice is a command line tool. To install, run:
|
|
14
14
|
gem install pgslice
|
15
15
|
```
|
16
16
|
|
17
|
-
This will give you the `pgslice` command. You can also install it with [Homebrew](#homebrew). If installation fails, you may need to install [dependencies](#dependencies).
|
17
|
+
This will give you the `pgslice` command. You can also install it with [Homebrew](#homebrew) or [Docker](#docker). If installation fails, you may need to install [dependencies](#dependencies).
|
18
18
|
|
19
19
|
## Steps
|
20
20
|
|
@@ -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_202108" PARTITION OF "public"."visits_intermediate" FOR VALUES FROM ('2021-08-01') TO ('2021-09-01');
|
112
112
|
|
113
|
-
ALTER TABLE "public"."
|
113
|
+
ALTER TABLE "public"."visits_202108" ADD PRIMARY KEY ("id");
|
114
114
|
|
115
|
-
CREATE TABLE "public"."
|
115
|
+
CREATE TABLE "public"."visits_202109" PARTITION OF "public"."visits_intermediate" FOR VALUES FROM ('2021-09-01') TO ('2021-10-01');
|
116
116
|
|
117
|
-
ALTER TABLE "public"."
|
117
|
+
ALTER TABLE "public"."visits_202109" ADD PRIMARY KEY ("id");
|
118
118
|
|
119
|
-
CREATE TABLE "public"."
|
119
|
+
CREATE TABLE "public"."visits_202110" PARTITION OF "public"."visits_intermediate" FOR VALUES FROM ('2021-10-01') TO ('2021-11-01');
|
120
120
|
|
121
|
-
ALTER TABLE "public"."
|
121
|
+
ALTER TABLE "public"."visits_202110" 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" >= '2021-08-01'::date AND "created_at" < '2021-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" >= '2021-08-01'::date AND "created_at" < '2021-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" >= '2021-08-01'::date AND "created_at" < '2021-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_202108";
|
153
153
|
|
154
|
-
ANALYZE VERBOSE "public"."
|
154
|
+
ANALYZE VERBOSE "public"."visits_202109";
|
155
155
|
|
156
|
-
ANALYZE VERBOSE "public"."
|
156
|
+
ANALYZE VERBOSE "public"."visits_202110";
|
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>_202109 $PGSLICE_URL > <table>_202109.dump
|
221
|
+
psql -c "DROP TABLE <table>_202109" $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>_202109.dump s3://<s3-bucket>/<table>_202109.dump
|
228
228
|
```
|
229
229
|
|
230
230
|
## Schema Updates
|
@@ -272,7 +272,7 @@ SELECT * FROM
|
|
272
272
|
WHERE
|
273
273
|
user_id = 123 AND
|
274
274
|
-- for performance
|
275
|
-
created_at >= '
|
275
|
+
created_at >= '2021-09-01' AND created_at < '2021-09-02'
|
276
276
|
```
|
277
277
|
|
278
278
|
For this to be effective, ensure `constraint_exclusion` is set to `partition` (default value) or `on`.
|
@@ -336,14 +336,27 @@ Postgres 10 introduces [declarative partitioning](https://www.postgresql.org/doc
|
|
336
336
|
|
337
337
|
Always make sure your [connection is secure](https://ankane.org/postgres-sslmode-explained) when connecting to a database over a network you don’t fully trust. Your best option is to connect over SSH or a VPN. Another option is to use `sslmode=verify-full`. If you don’t do this, your database credentials can be compromised.
|
338
338
|
|
339
|
-
##
|
339
|
+
## Additional Installation Methods
|
340
340
|
|
341
|
-
|
341
|
+
### Homebrew
|
342
|
+
|
343
|
+
With Homebrew, you can use:
|
342
344
|
|
343
345
|
```sh
|
344
346
|
brew install ankane/brew/pgslice
|
345
347
|
```
|
346
348
|
|
349
|
+
### Docker
|
350
|
+
|
351
|
+
Get the [Docker image](https://hub.docker.com/r/ankane/pgslice) with:
|
352
|
+
|
353
|
+
```sh
|
354
|
+
docker pull ankane/pgslice
|
355
|
+
alias pgslice="docker run --rm -e PGSLICE_URL ankane/pgslice"
|
356
|
+
```
|
357
|
+
|
358
|
+
This will give you the `pgslice` command.
|
359
|
+
|
347
360
|
## Dependencies
|
348
361
|
|
349
362
|
If installation fails, your system may be missing Ruby or libpq.
|
@@ -351,7 +364,7 @@ If installation fails, your system may be missing Ruby or libpq.
|
|
351
364
|
On Mac, run:
|
352
365
|
|
353
366
|
```sh
|
354
|
-
brew install
|
367
|
+
brew install libpq
|
355
368
|
```
|
356
369
|
|
357
370
|
On Ubuntu, run:
|
@@ -375,15 +388,6 @@ gem install specific_install
|
|
375
388
|
gem specific_install https://github.com/ankane/pgslice.git
|
376
389
|
```
|
377
390
|
|
378
|
-
## Docker
|
379
|
-
|
380
|
-
```sh
|
381
|
-
docker build -t pgslice .
|
382
|
-
alias pgslice="docker run --rm -e PGSLICE_URL pgslice"
|
383
|
-
```
|
384
|
-
|
385
|
-
This will give you the `pgslice` command.
|
386
|
-
|
387
391
|
## Reference
|
388
392
|
|
389
393
|
- [PostgreSQL Manual](https://www.postgresql.org/docs/current/static/ddl-partitioning.html)
|
@@ -27,7 +27,7 @@ module PgSlice
|
|
27
27
|
queries = []
|
28
28
|
|
29
29
|
if needs_comment
|
30
|
-
queries << "COMMENT ON TRIGGER #{quote_ident(trigger_name)} ON #{quote_table(table)}
|
30
|
+
queries << "COMMENT ON TRIGGER #{quote_ident(trigger_name)} ON #{quote_table(table)} IS 'column:#{field},period:#{period},cast:#{cast}';"
|
31
31
|
end
|
32
32
|
|
33
33
|
# today = utc date
|
data/lib/pgslice/cli/prep.rb
CHANGED
@@ -57,7 +57,7 @@ CREATE TABLE #{quote_table(intermediate_table)} (LIKE #{quote_table(table)} INCL
|
|
57
57
|
# add comment
|
58
58
|
cast = table.column_cast(column)
|
59
59
|
queries << <<-SQL
|
60
|
-
COMMENT ON TABLE #{quote_table(intermediate_table)}
|
60
|
+
COMMENT ON TABLE #{quote_table(intermediate_table)} IS 'column:#{column},period:#{period},cast:#{cast},version:#{version}';
|
61
61
|
SQL
|
62
62
|
else
|
63
63
|
queries << <<-SQL
|
@@ -87,7 +87,7 @@ CREATE TRIGGER #{quote_ident(trigger_name)}
|
|
87
87
|
|
88
88
|
cast = table.column_cast(column)
|
89
89
|
queries << <<-SQL
|
90
|
-
COMMENT ON TRIGGER #{quote_ident(trigger_name)} ON #{quote_table(intermediate_table)}
|
90
|
+
COMMENT ON TRIGGER #{quote_ident(trigger_name)} ON #{quote_table(intermediate_table)} IS 'column:#{column},period:#{period},cast:#{cast}';
|
91
91
|
SQL
|
92
92
|
end
|
93
93
|
|
data/lib/pgslice/version.rb
CHANGED
data/lib/pgslice.rb
CHANGED
@@ -7,16 +7,16 @@ require "cgi"
|
|
7
7
|
require "time"
|
8
8
|
|
9
9
|
# modules
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
require_relative "pgslice/helpers"
|
11
|
+
require_relative "pgslice/table"
|
12
|
+
require_relative "pgslice/version"
|
13
13
|
|
14
14
|
# commands
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
15
|
+
require_relative "pgslice/cli"
|
16
|
+
require_relative "pgslice/cli/add_partitions"
|
17
|
+
require_relative "pgslice/cli/analyze"
|
18
|
+
require_relative "pgslice/cli/fill"
|
19
|
+
require_relative "pgslice/cli/prep"
|
20
|
+
require_relative "pgslice/cli/swap"
|
21
|
+
require_relative "pgslice/cli/unprep"
|
22
|
+
require_relative "pgslice/cli/unswap"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pgslice
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -73,14 +73,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
73
73
|
requirements:
|
74
74
|
- - ">="
|
75
75
|
- !ruby/object:Gem::Version
|
76
|
-
version: '2.
|
76
|
+
version: '2.5'
|
77
77
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
78
|
requirements:
|
79
79
|
- - ">="
|
80
80
|
- !ruby/object:Gem::Version
|
81
81
|
version: '0'
|
82
82
|
requirements: []
|
83
|
-
rubygems_version: 3.
|
83
|
+
rubygems_version: 3.4.1
|
84
84
|
signing_key:
|
85
85
|
specification_version: 4
|
86
86
|
summary: Postgres partitioning as easy as pie
|