Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Updated docs. Converted to postgresql extension format.

  • Loading branch information...
commit 86dd6826f08a5f9a1cc4e3cc92b6722fb4e60557 1 parent 39b936d
@keithf4 authored
View
22 README.md
@@ -1,9 +1,23 @@
INSTALLATION
-----------
-Still in early development, so not actually in extension format yet. Run install.sql located in root directory with psql from the pg_partman top level folder.
+Recommended: pg_jobmon (>0.3.0). PG Job Monitor will automatically be used if it is installed.
- cd pg_partman
- psql < install.sql
+In directory where you downloaded mimeo to run
+
+ make
+ make install
+
+Log into PostgreSQL and run the following commands. Schema can be whatever you wish, but it cannot be changed after installation.
+
+ CREATE SCHEMA partman;
+ CREATE EXTENSION pg_partman SCHEMA partman;
+
+UPGRADE
+-------
+
+Make sure all the upgrade scripts for the version you have installed up to the most recent version are in the $BASEDIR/share/extension folder.
+
+ ALTER EXTENSION pg_partman UPDATE TO '<latest version>';
EXAMPLE
-------
@@ -19,7 +33,7 @@ If you're looking to do time-based partitioning, and will only be inserting new
This will turn your table into a parent table and premake 3 future partitions. To make new partitions for time-based partitioning, run the run_maintenance() function. Ideally, you'd run this as a cronjob to keep new partitions premade in preparation of new data.
-This should be enough to get you started. Please see the partman.md file in the doc folder for more information on the types of partitioning supported and what the parameters in the create_parent() function mean.
+This should be enough to get you started. Please see the pg_partman.md file in the doc folder for more information on the types of partitioning supported and what the parameters in the create_parent() function mean.
LICENSE AND COPYRIGHT
-------------------
View
18 doc/pg_partman.md
@@ -36,4 +36,20 @@ For this extension, the attributes of the child partitions are all obtained from
* Will automatically pre-create the new partition, keeping ahead by the number set as the **premake**.
* Will automatically update the function for **time-static** partitioning to keep the parent table pointing at the correct partitions. When using time-static, run this function more often than the partitioning interval to keep the function running its most efficient. For example, if using quarter-hour, run every 5 minutes; if using daily, run hourly, etc.
-
+*create_prev_time_partition(p_parent_table text, p_batch int DEFAULT 1) RETURNS bigint*
+ * This function is used to partition data that may have existed prior to setting up the parent table as a time-based partition set.
+ * If you are partitioning a large amount of previous data, it's recommended to run this function with an external script with small batch amounts. This will prevent a failure from causing an extensive rollback.
+ * First parameter (p_parent_table) is the existing parent table.
+ * Second parameter is how many partitions will be made in a single run of the function. Default value is 1.
+ * Returns the number of rows that were moved from the parent table to partitions. Returns zero when parent table is empty.
+
+*create_prev_id_partition(p_parent_table text, p_batch int DEFAULT 1) RETURNS bigint*
+ * This function is used to partition data that may have existed prior to setting up the parent table as a serial id partition set.
+ * If you are partitioning a large amount of previous data, it's recommended to run this function with an external script with small batch amounts. This will prevent a failure from causing an extensive rollback.
+ * First parameter (p_parent_table) is the existing parent table.
+ * Second parameter is how many partitions will be made in a single run of the function. Default value is 1.
+ * Returns the number of rows that were moved from the parent table to partitions. Returns zero when parent table is empty.
+
+*check_parent() RETURNS SETOF (parent table, count)*
+ * Run this function to monitor that the parent tables of the partition sets that pg_partmon manages do not get rows inserted to them.
+ * Returns a row for each parent table along with the number of rows it contains. Returns zero rows if none found.
View
19 install.sql
@@ -1,19 +0,0 @@
--- Run this script from the pg_partman top folder with psql command line tool to install pg_partman.
-
-DROP SCHEMA IF EXISTS part CASCADE;
-CREATE SCHEMA part;
-
-\i sql/types/types.sql
-\i sql/tables/tables.sql
-\i sql/functions/create_id_function.sql
-\i sql/functions/create_id_partition.sql
-\i sql/functions/create_next_time_partition.sql
-\i sql/functions/create_parent.sql
-\i sql/functions/create_time_function.sql
-\i sql/functions/create_time_partition.sql
-\i sql/functions/create_trigger.sql
-\i sql/functions/run_maintenance.sql
-\i sql/functions/create_prev_time_partition.sql
-\i sql/functions/create_prev_id_partition.sql
-\i sql/functions/check_parents.sql
-
View
6 sql/functions/check_parent.sql
@@ -1,4 +1,4 @@
-CREATE FUNCTION part.check_parent() RETURNS SETOF part.check_parent_table
+CREATE FUNCTION check_parent() RETURNS SETOF @extschema@.check_parent_table
LANGUAGE plpgsql SECURITY DEFINER
AS $$
DECLARE
@@ -6,12 +6,12 @@ DECLARE
v_count bigint = 0;
v_sql text;
v_tables record;
-v_trouble part.check_parent_table%rowtype;
+v_trouble @extschema@.check_parent_table%rowtype;
BEGIN
FOR v_tables IN
- SELECT DISTINCT parent_table FROM part.part_config
+ SELECT DISTINCT parent_table FROM @extschema@.part_config
LOOP
v_sql := 'SELECT count(1) AS n FROM ONLY '||v_tables.parent_table;
View
16 sql/functions/create_id_function.sql
@@ -1,4 +1,4 @@
-CREATE FUNCTION part.create_id_function(p_parent_table text, p_current_id bigint) RETURNS void
+CREATE FUNCTION create_id_function(p_parent_table text, p_current_id bigint) RETURNS void
LANGUAGE plpgsql SECURITY DEFINER
AS $$
DECLARE
@@ -43,7 +43,7 @@ SELECT type
, control
, premake
, last_partition
-FROM part.part_config
+FROM @extschema@.part_config
WHERE parent_table = p_parent_table
AND (type = 'id-static' OR type = 'id-dynamic')
INTO v_type, v_part_interval, v_control, v_premake, v_last_partition;
@@ -92,10 +92,10 @@ IF v_type = 'id-static' THEN
IF (NEW.'||v_control||' % '||v_part_interval||') > ('||v_part_interval||' / 2) THEN
v_next_partition_id := (substring(v_last_partition from char_length('||quote_literal(p_parent_table||'_p')||')+1)::bigint) + '||v_part_interval||';
IF ((v_next_partition_id - v_current_partition_id) / '||v_part_interval||') <= '||v_premake||' THEN
- v_next_partition_name := part.create_id_partition('||quote_literal(p_parent_table)||', '||quote_literal(v_control)||','
+ v_next_partition_name := @extschema@.create_id_partition('||quote_literal(p_parent_table)||', '||quote_literal(v_control)||','
||v_part_interval||', ARRAY[v_next_partition_id]);
- UPDATE part.part_config SET last_partition = v_next_partition_name WHERE parent_table = '||quote_literal(p_parent_table)||';
- PERFORM part.create_id_function('||quote_literal(p_parent_table)||', NEW.'||v_control||');
+ UPDATE @extschema@.part_config SET last_partition = v_next_partition_name WHERE parent_table = '||quote_literal(p_parent_table)||';
+ PERFORM @extschema@.create_id_function('||quote_literal(p_parent_table)||', NEW.'||v_control||');
END IF;
END IF;
END IF;
@@ -128,11 +128,11 @@ ELSIF v_type = 'id-dynamic' THEN
v_last_partition_id = substring(v_last_partition from char_length('||quote_literal(p_parent_table||'_p')||')+1)::bigint;
v_next_partition_id := v_last_partition_id + '||v_part_interval||';
IF ((v_next_partition_id - v_current_partition_id) / '||quote_literal(v_part_interval)||') <= '||quote_literal(v_premake)||' THEN
- v_next_partition_name := part.create_id_partition('||quote_literal(p_parent_table)||', '||quote_literal(v_control)||','
+ v_next_partition_name := @extschema@.create_id_partition('||quote_literal(p_parent_table)||', '||quote_literal(v_control)||','
||quote_literal(v_part_interval)||', ARRAY[v_next_partition_id]);
IF v_next_partition_name IS NOT NULL THEN
- UPDATE part.part_config SET last_partition = v_next_partition_name WHERE parent_table = '||quote_literal(p_parent_table)||';
- PERFORM part.create_id_function('||quote_literal(p_parent_table)||', NEW.'||v_control||');
+ UPDATE @extschema@.part_config SET last_partition = v_next_partition_name WHERE parent_table = '||quote_literal(p_parent_table)||';
+ PERFORM @extschema@.create_id_function('||quote_literal(p_parent_table)||', NEW.'||v_control||');
END IF;
END IF;
END IF;
View
2  sql/functions/create_id_partition.sql
@@ -1,4 +1,4 @@
-CREATE FUNCTION part.create_id_partition (p_parent_table text, p_control text, p_interval bigint, p_partition_ids bigint[]) RETURNS text
+CREATE FUNCTION create_id_partition (p_parent_table text, p_control text, p_interval bigint, p_partition_ids bigint[]) RETURNS text
LANGUAGE plpgsql SECURITY DEFINER
AS $$
DECLARE
View
10 sql/functions/create_next_time_partition.sql
@@ -1,4 +1,4 @@
-CREATE FUNCTION part.create_next_time_partition (p_parent_table text) RETURNS void
+CREATE FUNCTION create_next_time_partition (p_parent_table text) RETURNS void
LANGUAGE plpgsql
AS $$
DECLARE
@@ -9,7 +9,7 @@ v_last_partition text;
v_next_partition_timestamp timestamp;
v_part_interval interval;
v_tablename text;
-v_type part.partition_type;
+v_type @extschema@.partition_type;
BEGIN
@@ -19,7 +19,7 @@ SELECT type
, control
, datetime_string
, last_partition
-FROM part.part_config
+FROM @extschema@.part_config
WHERE parent_table = p_parent_table
AND (type = 'time-static' OR type = 'time-dynamic')
INTO v_type, v_part_interval, v_control, v_datetime_string, v_last_partition;
@@ -38,11 +38,11 @@ END IF;
-- pull out datetime portion of last partition's tablename
v_next_partition_timestamp := to_timestamp(substring(v_last_partition from char_length(p_parent_table||'_p')+1), v_datetime_string) + v_part_interval;
-EXECUTE 'SELECT part.create_time_partition('||quote_literal(p_parent_table)||','||quote_literal(v_control)||','||quote_literal(v_part_interval)||','
+EXECUTE 'SELECT @extschema@.create_time_partition('||quote_literal(p_parent_table)||','||quote_literal(v_control)||','||quote_literal(v_part_interval)||','
||quote_literal(v_datetime_string)||','||quote_literal(ARRAY[v_next_partition_timestamp])||')' INTO v_last_partition;
IF v_last_partition IS NOT NULL THEN
- UPDATE part.part_config SET last_partition = v_last_partition WHERE parent_table = p_parent_table;
+ UPDATE @extschema@.part_config SET last_partition = v_last_partition WHERE parent_table = p_parent_table;
END IF;
END
View
16 sql/functions/create_parent.sql
@@ -1,4 +1,4 @@
-CREATE FUNCTION part.create_parent(p_parent_table text, p_control text, p_type part.partition_type, p_interval text, p_premake int DEFAULT 3, p_debug boolean DEFAULT false) RETURNS void
+CREATE FUNCTION create_parent(p_parent_table text, p_control text, p_type @extschema@.partition_type, p_interval text, p_premake int DEFAULT 3, p_debug boolean DEFAULT false) RETURNS void
LANGUAGE plpgsql SECURITY DEFINER
AS $$
DECLARE
@@ -73,10 +73,10 @@ IF p_type = 'time-static' OR p_type = 'time-dynamic' THEN
v_partition_time := array_append(v_partition_time, quote_literal(CURRENT_TIMESTAMP + (v_time_interval*i))::timestamp);
END LOOP;
- EXECUTE 'SELECT part.create_time_partition('||quote_literal(p_parent_table)||','||quote_literal(p_control)||','
+ EXECUTE 'SELECT @extschema@.create_time_partition('||quote_literal(p_parent_table)||','||quote_literal(p_control)||','
||quote_literal(v_time_interval)||','||quote_literal(v_datetime_string)||','||quote_literal(v_partition_time)||')' INTO v_last_partition_name;
- INSERT INTO part.part_config (parent_table, type, part_interval, control, premake, datetime_string, last_partition) VALUES
+ INSERT INTO @extschema@.part_config (parent_table, type, part_interval, control, premake, datetime_string, last_partition) VALUES
(p_parent_table, p_type, v_time_interval, p_control, p_premake, v_datetime_string, v_last_partition_name);
IF v_jobmon_schema IS NOT NULL THEN
@@ -92,10 +92,10 @@ IF p_type = 'id-static' OR p_type = 'id-dynamic' THEN
v_partition_id = array_append(v_partition_id, (v_id_interval*i)+v_starting_partition_id);
END LOOP;
- EXECUTE 'SELECT part.create_id_partition('||quote_literal(p_parent_table)||','||quote_literal(p_control)||','
+ EXECUTE 'SELECT @extschema@.create_id_partition('||quote_literal(p_parent_table)||','||quote_literal(p_control)||','
||v_id_interval||','||quote_literal(v_partition_id)||')' INTO v_last_partition_name;
- INSERT INTO part.part_config (parent_table, type, part_interval, control, premake, last_partition) VALUES
+ INSERT INTO @extschema@.part_config (parent_table, type, part_interval, control, premake, last_partition) VALUES
(p_parent_table, p_type, v_id_interval, p_control, p_premake, v_last_partition_name);
IF v_jobmon_schema IS NOT NULL THEN
@@ -109,13 +109,13 @@ IF v_jobmon_schema IS NOT NULL THEN
END IF;
IF p_type = 'time-static' OR p_type = 'time-dynamic' THEN
- EXECUTE 'SELECT part.create_time_function('||quote_literal(p_parent_table)||')';
+ EXECUTE 'SELECT @extschema@.create_time_function('||quote_literal(p_parent_table)||')';
IF v_jobmon_schema IS NOT NULL THEN
PERFORM update_step(v_step_id, 'OK', 'Time function created');
END IF;
ELSIF p_type = 'id-static' OR p_type = 'id-dynamic' THEN
v_current_id := COALESCE(v_max, 0);
- EXECUTE 'SELECT part.create_id_function('||quote_literal(p_parent_table)||','||v_current_id||')';
+ EXECUTE 'SELECT @extschema@.create_id_function('||quote_literal(p_parent_table)||','||v_current_id||')';
IF v_jobmon_schema IS NOT NULL THEN
PERFORM update_step(v_step_id, 'OK', 'ID function created');
END IF;
@@ -125,7 +125,7 @@ IF v_jobmon_schema IS NOT NULL THEN
v_step_id := add_step(v_job_id, 'Creating partition trigger');
END IF;
-EXECUTE 'SELECT part.create_trigger('||quote_literal(p_parent_table)||')';
+EXECUTE 'SELECT @extschema@.create_trigger('||quote_literal(p_parent_table)||')';
IF v_jobmon_schema IS NOT NULL THEN
PERFORM update_step(v_step_id, 'OK', 'Done');
View
6 sql/functions/create_prev_id_partition.sql
@@ -1,4 +1,4 @@
-CREATE FUNCTION part.create_prev_id_partition(p_parent_table text, p_batch int DEFAULT 1) RETURNS bigint
+CREATE FUNCTION create_prev_id_partition(p_parent_table text, p_batch int DEFAULT 1) RETURNS bigint
LANGUAGE plpgsql SECURITY DEFINER
AS $$
DECLARE
@@ -20,7 +20,7 @@ BEGIN
SELECT type
, part_interval::bigint
, control
-FROM part.part_config
+FROM @extschema@.part_config
WHERE parent_table = p_parent_table
AND (type = 'id-static' OR type = 'id-dynamic')
INTO v_type, v_part_interval, v_control;
@@ -42,7 +42,7 @@ RAISE NOTICE 'v_partition_id: %',v_partition_id;
v_max_partition_id := v_min_partition_id + (v_part_interval*(i+1));
RAISE NOTICE 'v_max_partition_id: %',v_max_partition_id;
- v_sql := 'SELECT part.create_id_partition('||quote_literal(p_parent_table)||','||quote_literal(v_control)||','
+ v_sql := 'SELECT @extschema@.create_id_partition('||quote_literal(p_parent_table)||','||quote_literal(v_control)||','
||v_part_interval||','||quote_literal(v_partition_id)||')';
RAISE NOTICE 'v_sql: %', v_sql;
EXECUTE v_sql INTO v_last_partition_name;
View
6 sql/functions/create_prev_time_partition.sql
@@ -1,4 +1,4 @@
-CREATE FUNCTION part.create_prev_time_partition(p_parent_table text, p_batch int DEFAULT 1) RETURNS bigint
+CREATE FUNCTION create_prev_time_partition(p_parent_table text, p_batch int DEFAULT 1) RETURNS bigint
LANGUAGE plpgsql SECURITY DEFINER
AS $$
DECLARE
@@ -22,7 +22,7 @@ SELECT type
, part_interval::interval
, control
, datetime_string
-FROM part.part_config
+FROM @extschema@.part_config
WHERE parent_table = p_parent_table
AND (type = 'time-static' OR type = 'time-dynamic')
INTO v_type, v_part_interval, v_control, v_datetime_string;
@@ -61,7 +61,7 @@ RAISE NOTICE 'v_partition_timestamp: %',v_partition_timestamp;
v_max_partition_timestamp := v_min_partition_timestamp + (v_part_interval*(i+1));
RAISE NOTICE 'v_max_partition_timestamp: %',v_max_partition_timestamp;
- v_sql := 'SELECT part.create_time_partition('||quote_literal(p_parent_table)||','||quote_literal(v_control)||','
+ v_sql := 'SELECT @extschema@.create_time_partition('||quote_literal(p_parent_table)||','||quote_literal(v_control)||','
||quote_literal(v_part_interval)||','||quote_literal(v_datetime_string)||','||quote_literal(v_partition_timestamp)||')';
RAISE NOTICE 'v_sql: %', v_sql;
EXECUTE v_sql INTO v_last_partition_name;
View
4 sql/functions/create_time_function.sql
@@ -1,4 +1,4 @@
-CREATE FUNCTION part.create_time_function(p_parent_table text) RETURNS void
+CREATE FUNCTION create_time_function(p_parent_table text) RETURNS void
LANGUAGE plpgsql SECURITY DEFINER
AS $$
DECLARE
@@ -40,7 +40,7 @@ SELECT type
, part_interval::interval
, control
, datetime_string
-FROM part.part_config
+FROM @extschema@.part_config
WHERE parent_table = p_parent_table
AND (type = 'time-static' OR type = 'time-dynamic')
INTO v_type, v_part_interval, v_control, v_datetime_string;
View
2  sql/functions/create_time_partition.sql
@@ -1,4 +1,4 @@
-CREATE FUNCTION part.create_time_partition (p_parent_table text, p_control text, p_interval interval, p_datetime_string text, p_partition_times timestamp[]) RETURNS text
+CREATE FUNCTION create_time_partition (p_parent_table text, p_control text, p_interval interval, p_datetime_string text, p_partition_times timestamp[]) RETURNS text
LANGUAGE plpgsql SECURITY DEFINER
AS $$
DECLARE
View
2  sql/functions/create_trigger.sql
@@ -1,4 +1,4 @@
-CREATE FUNCTION part.create_trigger(p_parent_table text) RETURNS void
+CREATE FUNCTION create_trigger(p_parent_table text) RETURNS void
LANGUAGE plpgsql SECURITY DEFINER
AS $$
DECLARE
View
10 sql/functions/run_maintenance.sql
@@ -1,4 +1,4 @@
-CREATE FUNCTION part.run_maintenance() RETURNS void
+CREATE FUNCTION run_maintenance() RETURNS void
LANGUAGE plpgsql SECURITY DEFINER
AS $$
DECLARE
@@ -17,7 +17,7 @@ v_sql := 'SELECT parent_table
, part_interval::interval
, control
, last_partition
-FROM part.part_config where type = ''time-static'' or type = ''time-dynamic''';
+FROM @extschema@.part_config where type = ''time-static'' or type = ''time-dynamic''';
FOR v_row IN
SELECT parent_table
@@ -27,7 +27,7 @@ SELECT parent_table
, premake
, datetime_string
, last_partition
-FROM part.part_config WHERE type = 'time-static' OR type = 'time-dynamic'
+FROM @extschema@.part_config WHERE type = 'time-static' OR type = 'time-dynamic'
LOOP
CASE
@@ -56,11 +56,11 @@ LOOP
IF v_premade_count < v_row.premake THEN
RAISE NOTICE 'Creating next partition';
- EXECUTE 'SELECT part.create_next_time_partition('||quote_literal(v_row.parent_table)||')';
+ EXECUTE 'SELECT @extschema@.create_next_time_partition('||quote_literal(v_row.parent_table)||')';
END IF;
IF v_row.type = 'time-static' THEN
- EXECUTE 'SELECT part.create_time_function('||quote_literal(v_row.parent_table)||')';
+ EXECUTE 'SELECT @extschema@.create_time_function('||quote_literal(v_row.parent_table)||')';
END IF;
END LOOP; -- end of main loop
View
6 sql/tables/tables.sql
@@ -1,4 +1,4 @@
-CREATE TABLE part.part_config (
+CREATE TABLE part_config (
parent_table text NOT NULL,
type part.partition_type NOT NULL,
part_interval text NOT NULL,
@@ -9,5 +9,5 @@ CREATE TABLE part.part_config (
last_partition text,
CONSTRAINT part_config_parent_table_pkey PRIMARY KEY (parent_table)
);
-CREATE INDEX part_config_type_idx ON part.part_config (type);
---SELECT pg_catalog.pg_extension_config_dump('part_config', '');
+CREATE INDEX part_config_type_idx ON @extschema@.part_config (type);
+SELECT pg_catalog.pg_extension_config_dump('part_config', '');
View
4 sql/types/types.sql
@@ -1,2 +1,2 @@
-CREATE TYPE part.partition_type AS ENUM ('time-static', 'time-dynamic', 'id-static', 'id-dynamic');
-CREATE TYPE part.check_parent_table AS (parent_table text, count bigint);
+CREATE TYPE partition_type AS ENUM ('time-static', 'time-dynamic', 'id-static', 'id-dynamic');
+CREATE TYPE check_parent_table AS (parent_table text, count bigint);
Please sign in to comment.
Something went wrong with that request. Please try again.