pgpartman / pg_partman

Partition management extension for PostgreSQL
Other
2.09k stars 281 forks source link

Default partition is not included in publication #401

Closed james-johnston-thumbtack closed 2 years ago

james-johnston-thumbtack commented 2 years ago

When calling create_parent with a publication name, the default partition is not included in the publication. Example:

CREATE TABLE test_table (row_time TIMESTAMP NOT NULL) PARTITION BY RANGE (row_time);
CREATE PUBLICATION test_pub;
SELECT partman.create_parent(
    p_parent_table => 'public.test_table',
    p_control => 'row_time',
    p_type => 'native',
    p_interval => 'daily',
    p_publications => ARRAY['test_pub']
);

then run the following in psql to print publications:

testdb=# \dRp+
                      Publication test_pub
  Owner   | All tables | Inserts | Updates | Deletes | Truncates
----------+------------+---------+---------+---------+-----------
 postgres | f          | t       | t       | t       | t
Tables:
    "public.test_table_p2021_11_13"
    "public.test_table_p2021_11_14"
    "public.test_table_p2021_11_15"
    "public.test_table_p2021_11_16"
    "public.test_table_p2021_11_17"
    "public.test_table_p2021_11_18"
    "public.test_table_p2021_11_19"
    "public.test_table_p2021_11_20"
    "public.test_table_p2021_11_21"

Notably absent from the publication: the default test_table_default partition. I was expecting it to be there...

keithf4 commented 2 years ago

Confirming this is missing. Will try to account for this in the next update.

FYI, in PG14 publications are automatically handled within PostgreSQL itself for native partitioning so if you add the parent table to the publication before you run create_parent() it should automatically add all children. You can see in the example below I didn't use the p_publication flag to the create function and all child tables still are in publication.

keith@keith=# CREATE PUBLICATION partman_test_publication;
CREATE PUBLICATION

keith@keith=# create schema partman_test;
CREATE SCHEMA

keith@keith=# CREATE TABLE partman_test.time_taptest_table (col1 int, col2 text default 'stuff', col3 timestamptz NOT NULL DEFAULT now()) PARTITION BY RANGE (col3);
CREATE TABLE

keith@keith=# ALTER PUBLICATION partman_test_publication ADD TABLE partman_test.time_taptest_table ;
ALTER PUBLICATION

keith@keith=# SELECT partman.create_parent('partman_test.time_taptest_table', 'col3', 'native', 'daily');
 create_parent 
---------------
 t
(1 row)

keith@keith=# select * from pg_publication_tables where pubname = 'partman_test_publication';
         pubname          |  schemaname  |           tablename            
--------------------------+--------------+--------------------------------
 partman_test_publication | partman_test | time_taptest_table_p2021_11_22
 partman_test_publication | partman_test | time_taptest_table_p2021_11_23
 partman_test_publication | partman_test | time_taptest_table_p2021_11_24
 partman_test_publication | partman_test | time_taptest_table_p2021_11_25
 partman_test_publication | partman_test | time_taptest_table_p2021_11_26
 partman_test_publication | partman_test | time_taptest_table_p2021_11_27
 partman_test_publication | partman_test | time_taptest_table_p2021_11_28
 partman_test_publication | partman_test | time_taptest_table_p2021_11_29
 partman_test_publication | partman_test | time_taptest_table_p2021_11_30
 partman_test_publication | partman_test | time_taptest_table_default
(10 rows)
keithf4 commented 2 years ago

Version 4.6.1 has been released with a fix for this. Apologies for the delay on the release.