README.md in pgslice-0.1.5 vs README.md in pgslice-0.1.6

- old
+ new

@@ -44,10 +44,12 @@ pgslice fill <table> ``` Use the `--batch-size` and `--sleep` options to control the speed. + To sync data across different databases, check out [pgsync](https://github.com/ankane/pgsync). + 5. Swap the intermediate table with the original table ```sh pgslice swap <table> ``` @@ -68,10 +70,34 @@ ```sh pgslice add_partitions <table> --future 3 ``` +Add this as a cron job to create a new partition each day or month. + +``` +# day +0 0 * * * pgslice add_partitions <table> --future 3 --url ... + +# month +0 0 1 * * pgslice add_partitions <table> --future 3 --url ... +``` + +Add a monitor to ensure partitions are being created. + +```sql +SELECT 1 FROM + pg_catalog.pg_class c +INNER JOIN + pg_catalog.pg_namespace n ON n.oid = c.relnamespace +WHERE + c.relkind = 'r' AND + n.nspname = 'public' AND + c.relname = '<table>_' || to_char(NOW() + INTERVAL '3 days', 'YYYYMMDD') + -- for months, use to_char(NOW() + INTERVAL '3 months', 'YYYYMM') +``` + ## Additional Commands To undo prep (which will delete partitions), use: ```sh @@ -182,9 +208,19 @@ ALTER TABLE locations_20160426 ADD PRIMARY KEY (id); CREATE INDEX ON locations_20160426 USING btree (updated_at, shopper_id); COMMIT; +``` + +## One Off Tasks + +You can also reduce the size of a table without partitioning. + +```sh +pgslice prep <table> --no-partition +pgslice fill <table> --start 1000 # starting primary key +pgslice swap <table> ``` ## Upgrading Run: