pgpartman / pg_partman

Partition management extension for PostgreSQL

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Different Index Name on Child Table

aakashmuthuramalingam opened this issue · comments

Hi, I am having a table partitioned on daily basis. Got issue while moving the table to backup because of index name size of 64 characters. Now changed the index name on the parent table, but the new child tables are still having the older names. Even checked the template table, it does not have any details of indexes. Please let me know how to fix it

-[ RECORD 1 ]--------------+---------------------------------------------------
parent_table               | public.tbl1
control                    | c_date
partition_type             | native
partition_interval         | 1 day
constraint_cols            |
premake                    | 3
optimize_trigger           | 4
optimize_constraint        | 30
epoch                      | none
inherit_fk                 | t
retention                  | 15 days
retention_schema           | backup
retention_keep_table       | t
retention_keep_index       | t
infinite_time_partitions   | t
datetime_string            | YYYY_MM_DD
automatic_maintenance      | on
jobmon                     | t
sub_partition_set_full     | f
undo_in_progress           | f
trigger_exception_handling | f
upsert                     |
trigger_return_null        | t
template_table             | partman.template_tbl1
publications               |
inherit_privileges         | f
constraint_valid           | t
subscription_refresh       |
drop_cascade_fk            | f

It doesn't appear that the index name on the parent table has any bearing on the name chosen for the index on the child tables. The child tables just use the automatically generated name that PostgreSQL gives it. Not quite sure what to do here without seeing more about the issue you're running into.

create index new_index_name on partman_test.time_taptest_table (col1);

keith=# \d partman_test.time_taptest_table
                                   Partitioned table "partman_test.time_taptest_table"
 Column |           Type           | Collation | Nullable |                            Default                            
--------+--------------------------+-----------+----------+---------------------------------------------------------------
 col1   | integer                  |           | not null | nextval('partman_test.time_taptest_table_col1_seq'::regclass)
 col2   | text                     |           |          | 
 col3   | timestamp with time zone |           | not null | now()
Partition key: RANGE (col3)
Indexes:
    "new_index_name" btree (col1)
Number of partitions: 23 (Use \d+ to list them.)
keith=# \d+ partman_test.time_taptest_table_p20231210
                                                               Table "partman_test.time_taptest_table_p20231210"
 Column |           Type           | Collation | Nullable |                            Default                            | Storage  | Compression | Stats target | Descri
ption 
--------+--------------------------+-----------+----------+---------------------------------------------------------------+----------+-------------+--------------+-------
------
 col1   | integer                  |           | not null | nextval('partman_test.time_taptest_table_col1_seq'::regclass) | plain    |             |              | 
 col2   | text                     |           |          |                                                               | extended |             |              | 
 col3   | timestamp with time zone |           | not null | now()                                                         | plain    |             |              | 
Partition of: partman_test.time_taptest_table FOR VALUES FROM ('2023-12-10 00:00:00-05') TO ('2023-12-11 00:00:00-05')
Partition constraint: ((col3 IS NOT NULL) AND (col3 >= '2023-12-10 00:00:00-05'::timestamp with time zone) AND (col3 < '2023-12-11 00:00:00-05'::timestamp with time zone)
)
Indexes:
    "time_taptest_table_p20231210_col1_idx" btree (col1)
Access method: heap

As I said, I don't think there's any way to influence the names of the indexes on the child tables at this time. Do you still have any questions related to this issue?

Will be closing this issue unless you have further questions. Please feel free to reopen

Hi @keithf4 , Thanks for your detailed response. It really helps. Actual issue is

My Index name is getting truncated as it crosses more than 64 characters. It is getting truncated in the middle while pgpartman creates the new child table.

Example:

tbl_tryp_aka_bidding_opurt_**p2024_0_**tablesss_id_campaign_type_idx

As it is getting truncated in the middle, while moving to the backup schema, it exists already because of the previous move and my current backup to the backup schema getting failed because of index already exists.

if it truncates at the end, it won't have this issue. Truncating at partition number part makes it to happen like this. Any idea to resolve this ?

Number of columns in my index is high, so it is crossing 64 character limitation.

Apologies because I really don't know how to help fix this. Partman truncates the table name itself on the child tables otherwise it would truncate the suffix and potentially cause the same sort of naming collisions on the new child tables (Ex cuts off the day from p20240108 and p20240109 so it tries to create two p202401 tables.

As I said, there really is no control over the index names when inheriting the indexes from the parent table. It is highly recommended to keep table names shorter for partitioned tables due to these sorts of truncation issues. The only other thing I could recommend would be to have something that renames indexes as part of your migration to the backup schema. Or maybe have a process that renames the indexes after the partition maintenance process to shorten them when a new child table is made.