Jira (PDB-3526) Add online index rebuild capability to PuppetDB

3 views
Skip to first unread message

Nick Walker (JIRA)

unread,
May 23, 2017, 8:12:02 PM5/23/17
to puppe...@googlegroups.com
Nick Walker created an issue
 
PuppetDB / New Feature PDB-3526
Add online index rebuild capability to PuppetDB
Issue Type: New Feature New Feature
Assignee: Unassigned
Attachments: online_index_rebuild_script.sql, online_rebuild_unique_constraints.sql
Created: 2017/05/23 5:11 PM
Priority: Normal Normal
Reporter: Nick Walker

Background

Rebuilding indexes is a common maintenance recommendation for PostgreSQL databases. However, rebuilding an index is a blocking activity so customers that require little to no downtime don't like to rebuild indexes and are likely giving up performance because of it.

This is one of the main reasons that pg_repack exists in addition to it's ability to reduce table bloat.

PuppetDB suggestion

Since rebuilding indexes is a good idea but we don't want downtime the internet generally recommends creating a new index with the CONCURRENTLY flag which is non-blocking then dropping the existing index and renaming the new one to match the existing name.

We should have a facility for accomplishing the above task and I have two queries that produce that for the indexes in any postgresql database.

Assuming you place the attachments in /tmp you can run them and execute their output as follows.

su - postgres -s /bin/bash -c "psql -d pe-puppetdb -f /tmp/online_rebuild_index_script -qt" > /tmp/rebuild_indexes.sql
su - postgres -s /bin/bash -c "psql -d pe-puppetdb -f /tmp/rebuild_indexes.sql -q"
su - postgres -s /bin/bash -c "psql -d pe-puppetdb -f /tmp/online_rebuild_unique_constraints.sql -qt" > /tmp/rebuild_unique_constraints.sql
su - postgres -s /bin/bash -c "psql -d pe-puppetdb -f /tmp/rebuild_unique_constraints.sql -q"

Caveats

The first script rebuilds all indexes that don't enforce constraints.
The second script rebuilds all unique constraints that don't have further dependencies.

In my counting that currently leaves the certnames_transform_certname_key unique index out because numerous FKs depend on it to make sure that certname is unique. Otherwise all indexes are rebuilt by the combination of the two scripts.

Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v6.4.14#64029-sha1:ae256fe)
Atlassian logo

Nick Walker (JIRA)

unread,
May 23, 2017, 8:26:03 PM5/23/17
to puppe...@googlegroups.com
Nick Walker updated an issue
Change By: Nick Walker
h1.  Background


Rebuilding indexes is a common maintenance recommendation for PostgreSQL databases.  However, rebuilding an index is a blocking activity so customers that require little to no downtime don't like to rebuild indexes and are likely giving up performance because of it.  

This is one of the main reasons that pg_repack exists in addition to it's ability to reduce table bloat.  

h1.  PuppetDB suggestion


Since rebuilding indexes is a good idea but we don't want downtime the internet generally recommends creating a new index with the CONCURRENTLY flag which is non-blocking then dropping the existing index and renaming the new one to match the existing name.  

For example: the alter constraint page in the postgresql docs recommends exactly what I do in the script.  Scroll to the very bottom of this page https://www.postgresql.org/docs/9.4/static/sql-altertable.html

We should have a facility for accomplishing the above task and I have two queries that produce that for the indexes in any postgresql database. 

Assuming you place the attachments in /tmp you can run them and execute their output as follows.  

{code}

su - postgres -s /bin/bash -c "psql -d pe-puppetdb -f /tmp/online_rebuild_index_script -qt" > /tmp/rebuild_indexes.sql
su - postgres -s /bin/bash -c "psql -d pe-puppetdb -f /tmp/rebuild_indexes.sql -q"
su - postgres -s /bin/bash -c "psql -d pe-puppetdb -f /tmp/online_rebuild_unique_constraints.sql -qt" > /tmp/rebuild_unique_constraints.sql
su - postgres -s /bin/bash -c "psql -d pe-puppetdb -f /tmp/rebuild_unique_constraints.sql -q"
{code}

h1.  Caveats 


The first script rebuilds all indexes that don't enforce constraints. 
The second script rebuilds all unique constraints that don't have further dependencies.  

In my counting that currently leaves the certnames_transform_certname_key unique index out because numerous FKs depend on it to make sure that certname is unique.  Otherwise all indexes are rebuilt by the combination of the two scripts.  

Nick Walker (JIRA)

unread,
May 24, 2017, 11:46:05 AM5/24/17
to puppe...@googlegroups.com
Nick Walker updated an issue
h1.  Background

Rebuilding indexes is a common maintenance recommendation for PostgreSQL databases.  However, rebuilding an index is a blocking activity so customers that require little to no downtime don't like to rebuild indexes and are likely giving up performance because of it.  

This is one of the main reasons that pg_repack exists in addition to it's ability to reduce table bloat.  

h1.  PuppetDB suggestion

Since rebuilding indexes is a good idea but we don't want downtime the internet generally recommends creating a new index with the CONCURRENTLY flag which is non-blocking then dropping the existing index and renaming the new one to match the existing name.  

For example: the alter constraint page in the postgresql docs recommends exactly what I do in the script.  Scroll to the very bottom of this page https://www.postgresql.org/docs/9.4/static/sql-altertable.html

We should have a facility for accomplishing the above task and I have two queries that produce that for the indexes in any postgresql database. 

Assuming you place the attachments in /tmp you can run them and execute their output as follows.  

{code}
su - postgres -s /bin/bash -c "psql -d pe-puppetdb -f /tmp/online_rebuild_index_script -qt" > /tmp/rebuild_indexes.sql
su - postgres -s /bin/bash -c "psql -d pe-puppetdb -f /tmp/rebuild_indexes.sql -q"
su - postgres -s /bin/bash -c "psql -d pe-puppetdb -f /tmp/online_rebuild_unique_constraints.sql -qt" > /tmp/rebuild_unique_constraints.sql
su - postgres -s /bin/bash -c "psql -d pe-puppetdb -f /tmp/rebuild_unique_constraints.sql -q"
{code}

h1.  Caveats 

The first script rebuilds all indexes that don't enforce constraints. 
The second script rebuilds all unique constraints that don't have further dependencies.  

In my counting that currently leaves the certnames_transform_certname_key unique index out because numerous FKs depend on it to make sure that certname is unique.  Otherwise all indexes are rebuilt by the combination of the two scripts.  

Nick Walker (JIRA)

unread,
Sep 18, 2017, 5:59:03 PM9/18/17
to puppe...@googlegroups.com
Nick Walker updated an issue
h1.  Background

Rebuilding indexes is a common maintenance recommendation for PostgreSQL databases.  However, rebuilding an index is a blocking activity so customers that require little to no downtime don't like to rebuild indexes and are likely giving up performance because of it.  

This is one of the main reasons that pg_repack exists in addition to it's ability to reduce table bloat.  

h1.  PuppetDB suggestion

Since rebuilding indexes is a good idea but we don't want downtime the internet generally recommends creating a new index with the CONCURRENTLY flag which is non-blocking then dropping the existing index and renaming the new one to match the existing name.  

For example: the alter constraint page in the postgresql docs recommends exactly what I do in the script.  Scroll to the very bottom of this page https://www.postgresql.org/docs/9.4/static/sql-altertable.html

Another example:  https://www.keithf4.com/cleaning-up-postgresql-bloat/

We should have a facility for accomplishing the above task and I have two queries that produce that for the indexes in any postgresql database. 

Assuming you place the attachments in /tmp you can run them and execute their output as follows.  

{code}
su -  pe-  postgres -s /bin/bash -c " /opt/puppetlabs/server/bin/ psql -d pe-puppetdb -f /tmp/online_rebuild_index_script -qt" > /tmp/rebuild_indexes.sql
su -
 pe-  postgres -s /bin/bash -c " /opt/puppetlabs/server/bin/ psql -d pe-puppetdb -f /tmp/rebuild_indexes.sql -q"
su -
 pe-  postgres -s /bin/bash -c " /opt/puppetlabs/server/bin/ psql -d pe-puppetdb -f /tmp/online_rebuild_unique_constraints.sql -qt" > /tmp/rebuild_unique_constraints.sql
su -
 pe-  postgres -s /bin/bash -c " /opt/puppetlabs/server/bin/ psql -d pe-puppetdb -f /tmp/rebuild_unique_constraints.sql -q"

{code}

h1.  Caveats 

The first script rebuilds all indexes that don't enforce constraints. 
The second script rebuilds all unique constraints that don't have further dependencies.  

In my counting that currently leaves the certnames_transform_certname_key unique index out because numerous FKs depend on it to make sure that certname is unique.  Otherwise all indexes are rebuilt by the combination of the two scripts.  

Owen Rodabaugh (JIRA)

unread,
Nov 14, 2017, 11:47:04 AM11/14/17
to puppe...@googlegroups.com
Owen Rodabaugh updated an issue
Change By: Owen Rodabaugh
CS Priority: Major
CS Impact: Maintenance of Postgresql is one of the most common solutions to performance issue at large scale customers. Having this capability built into the product would increase customer satisfaction and reduce the support burden.
CS Severity: 4 - Major
CS Business Value: 5 - $$$$$$
CS Frequency: 2 - 5-25% of Customers
This message was sent by Atlassian JIRA (v7.0.2#70111-sha1:88534db)
Atlassian logo

Adam Bottchen (JIRA)

unread,
Dec 6, 2018, 2:46:03 PM12/6/18
to puppe...@googlegroups.com
Adam Bottchen updated an issue
Change By: Adam Bottchen
Labels: cstop10
This message was sent by Atlassian JIRA (v7.7.1#77002-sha1:e75ca93)
Atlassian logo

Nick Walker (JIRA)

unread,
Jan 16, 2019, 6:52:04 PM1/16/19
to puppe...@googlegroups.com

Nick Walker (JIRA)

unread,
Jan 16, 2019, 6:54:05 PM1/16/19
to puppe...@googlegroups.com
Nick Walker commented on New Feature PDB-3526
 
Re: Add online index rebuild capability to PuppetDB

While not native to PuppetDB, we will have pg_repack in Puppet Enterprise with 2018.1.7 and 2019.02 which provides the ability to rebuild indexes online.

Closing this as won't fix since we can use a 3rd party tool to solve the issue.

Claudia Petty (Jira)

unread,
Jun 21, 2023, 11:00:02 AM6/21/23
to puppe...@googlegroups.com
Claudia Petty updated an issue
 
Change By: Claudia Petty
Labels: new-feature
This message was sent by Atlassian Jira (v8.20.21#820021-sha1:38274c8)
Atlassian logo
Reply all
Reply to author
Forward
0 new messages