Mise à jour de PostgreSQL 13

:warning: ATTENTION ! Si votre base de données est très volumineuse, vous aurez besoin d’un espace disque supplémentaire important (2x la taille de la base de données) et devez être extrêmement prudent avec cette mise à niveau !

Nous venons d’apporter des modifications pour mettre à niveau notre image Docker vers PostgreSQL 13. Tout administrateur de site reconstruisant Discourse en ligne de commande sera mis à niveau vers PostgreSQL 13 depuis la version précédente, PostgreSQL 12. Notez que si vous avez différé la mise à jour lors de la mise à jour de PostgreSQL 12 survenue en mai, vous pouvez sauter cette mise à jour et passer directement à PostgreSQL 13.

Si vous aviez précédemment différé la mise à jour, modifiez le modèle PostgreSQL dans app.yml de templates/postgres.10.template.yml à templates/postgres.template.yml.

Comme pour toute mise à niveau, il est fortement conseillé de faire une sauvegarde avant d’entreprendre quoi que ce soit.

Mise à jour

Guide d’installation officiel (conteneur unique)

Lors de votre prochaine reconstruction, vous verrez ce message à la fin :

-------------------------------------------------------------------------------------
MISE À NIVEAU DE POSTGRES TERMINÉE

L'ancienne base de données 12 est stockée dans /shared/postgres_data_old

Pour terminer la mise à niveau, reconstruisez à nouveau en utilisant :

./launcher rebuild app
-------------------------------------------------------------------------------------

Cela signifie que tout s’est bien passé lors de la mise à niveau ! Vous devez simplement lancer une nouvelle reconstruction pour remettre votre site en ligne.

Installation avec conteneur de données

Si vous exécutez une configuration avec un conteneur de données dédié basé sur l’exemple fourni dans notre dépôt discourse_docker, assurez-vous d’arrêter PostgreSQL de manière sûre et propre.

De nos jours, nous avons des tâches en arrière-plan exécutant des requêtes sur plusieurs minutes, donc arrêter le conteneur web aidera à arrêter le conteneur de données en toute sécurité.

./launcher stop web_only
./launcher stop data
./launcher rebuild data
./launcher rebuild data
./launcher rebuild web_only

Avant de lancer la première reconstruction du conteneur de données, vous pouvez suivre le journal PostgreSQL pour voir s’il a été arrêté correctement.

Exécuter tail -f shared/data/log/var-log/postgres/current devrait vous donner le journal suivant si l’arrêt était propre :

2020-05-13 18:33:33.457 UTC [36] LOG:  received smart shutdown request
2020-05-13 18:33:33.464 UTC [36] LOG:  worker process: logical replication launcher (PID 52) exited with exit code 1
2020-05-13 18:33:33.465 UTC [47] LOG:  shutting down
2020-05-13 18:33:33.479 UTC [36] LOG:  database system is shut down

Effectuer une mise à jour manuelle / environnements à espace contraint

:warning::warning::warning:
VOUS DEVEZ SAUVEGARDER LES DONNÉES DE POSTGRES AVANT D’ESSAYER CECI
:warning::warning::warning:

Si vous êtes dans un environnement à espace contraint sans moyen d’obtenir plus d’espace, vous pouvez essayer ce qui suit :

./launcher stop app #(ou les deux web_only et data si c'est votre cas)
mkdir -p /var/discourse/shared/standalone/postgres_data_new
docker run --rm \
	-v /var/discourse/shared/standalone/postgres_data:/var/lib/postgresql/12/data \
	-v /var/discourse/shared/standalone/postgres_data_new:/var/lib/postgresql/13/data \
	tianon/postgres-upgrade:12-to-13
mv /var/discourse/shared/standalone/postgres_data /var/discourse/shared/standalone/postgres_data_old
mv /var/discourse/shared/standalone/postgres_data_new /var/discourse/shared/standalone/postgres_data
./launcher rebuild app #(ou d'abord data puis web_only si c'est votre cas)

Selon mes tests, cette procédure nécessite moins de 1x la taille actuelle de votre base de données en espace libre.

Report de la mise à jour

Si vous devez reporter la mise à jour lors de votre prochaine reconstruction, vous pouvez remplacer le modèle PostgreSQL dans votre fichier app.yml en changeant "templates/postgres.template.yml" par "templates/postgres.12.template.yml".

Ce n’est pas recommandé, car certains administrateurs de site oublieront d’inverser le changement par la suite.

Tâches optionnelles après la mise à jour

Optimisation des statistiques PostgreSQL

Après la mise à jour, le nouveau PostgreSQL n’aura pas les statistiques de table à portée de main. Vous pouvez les générer en utilisant :

cd /var/discourse
./launcher enter app
su postgres
psql
\connect discourse
VACUUM VERBOSE ANALYZE;
\q
exit
exit

Ou cette version en une ligne de ce qui précède :

/var/discourse/launcher run app "echo 'vacuum verbose analyze;' | su postgres -c 'psql discourse'"

Recréation des index

La fonctionnalité principale de cette mise à niveau est une grande économie de fichiers dans notre plus grande table sur chaque instance, la table post_timings et ses index. Après avoir effectué une mise à jour réussie, vous devrez exécuter une commande pour reconstruire les index et en tirer parti.

cd /var/discourse
./launcher enter app
su postgres
psql
\connect discourse
REINDEX SCHEMA CONCURRENTLY public;
\q
exit
exit

Si vous pouvez vérifier la taille de post_timings avant et après le REINDEX, ce serait une statistique intéressante à partager ici !

Vous pouvez utiliser la requête ci-dessous pour vérifier les 20 plus grands objets de données, exécutez-la avant et après le reindex :

WITH RECURSIVE pg_inherit(inhrelid, inhparent) AS
    (select inhrelid, inhparent
    FROM pg_inherits
    UNION
    SELECT child.inhrelid, parent.inhparent
    FROM pg_inherit child, pg_inherits parent
    WHERE child.inhparent = parent.inhrelid),
pg_inherit_short AS (SELECT * FROM pg_inherit WHERE inhparent NOT IN (SELECT inhrelid FROM pg_inherit))
SELECT table_schema
    , TABLE_NAME
    , row_estimate
    , pg_size_pretty(total_bytes) AS total
    , pg_size_pretty(index_bytes) AS INDEX
    , pg_size_pretty(toast_bytes) AS toast
    , pg_size_pretty(table_bytes) AS TABLE
  FROM (
    SELECT *, total_bytes-index_bytes-COALESCE(toast_bytes,0) AS table_bytes
    FROM (
         SELECT c.oid
              , nspname AS table_schema
              , relname AS TABLE_NAME
              , SUM(c.reltuples) OVER (partition BY parent) AS row_estimate
              , SUM(pg_total_relation_size(c.oid)) OVER (partition BY parent) AS total_bytes
              , SUM(pg_indexes_size(c.oid)) OVER (partition BY parent) AS index_bytes
              , SUM(pg_total_relation_size(reltoastrelid)) OVER (partition BY parent) AS toast_bytes
              , parent
          FROM (
                SELECT pg_class.oid
                    , reltuples
                    , relname
                    , relnamespace
                    , pg_class.reltoastrelid
                    , COALESCE(inhparent, pg_class.oid) parent
                FROM pg_class
                    LEFT JOIN pg_inherit_short ON inhrelid = oid
                WHERE relkind IN ('r', 'p')
             ) c
             LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
  ) a
  WHERE oid = parent
) a
ORDER BY total_bytes DESC LIMIT 20;

Nettoyage des anciennes données

Pour une installation standard, vous pouvez supprimer les anciennes données au format PG12 avec la commande suivante :

cd /var/discourse
./launcher cleanup

Si vous avez un conteneur de données séparé, vous devrez supprimer la copie de sauvegarde comme ceci :

rm -fr /var/discourse/shared/data/postgres_data_old/

FAQ

Le cluster source n’a pas été arrêté proprement

Si vous obtenez un échec de mise à niveau avec le message ci-dessus, vous pouvez essayer une approche plus simple pour le remettre dans un meilleur état.

Redémarrez l’ancien conteneur avec ./launcher start app. Attendez quelques minutes jusqu’à ce qu’il soit de nouveau opérationnel.

Maintenant, arrêtez-le à nouveau avec ./launcher stop app. Ensuite, suivez les journaux pour voir si c’était propre :

tail -f shared/data/log/var-log/postgres/current
2020-05-13 18:33:33.457 UTC [36] LOG:  received smart shutdown request
2020-05-13 18:33:33.464 UTC [36] LOG:  worker process: logical replication launcher (PID 52) exited with exit code 1
2020-05-13 18:33:33.465 UTC [47] LOG:  shutting down
2020-05-13 18:33:33.479 UTC [36] LOG:  database system is shut down

Si les journaux ressemblent à ce qui précède, vous pouvez maintenant essayer de mettre à niveau à nouveau en utilisant ./launcher rebuild app.

Les valeurs lc_collate pour la base de données “postgres” ne correspondent pas

Cette erreur se produit si vous utilisez des paramètres régionaux non par défaut pour votre base de données. Il a été rapporté que vous avez besoin de 3 variables pour que cela réussisse. Assurez-vous que la section env: de votre fichier app.yml contient les 3 lignes :

  LC_ALL: en_US.UTF-8
  LANG: en_US.UTF-8
  LANGUAGE: en_US.UTF-8

En changeant en_US.UTF-8 par votre paramètre régional.

Chaque reconstruction effectue à nouveau la mise à niveau, c’est-à-dire une boucle de mise à niveau

Lorsque cela se produit, vos journaux de mise à niveau contiendront :

mv: cannot move '/shared/postgres_data' to '/shared/postgres_data_old/postgres_data': Directory not empty
mv: cannot move '/shared/postgres_data_new' to '/shared/postgres_data/postgres_data_new': Directory not empty

Cela signifie qu’il reste encore des fichiers de la dernière mise à niveau. Déplacez-les ailleurs avant de continuer.

Scripts de suggestion “Mise à niveau terminée” - dois-je faire quelque chose ?

Une fois la mise à niveau terminée, vous verrez une sortie du message pg_upgrade indiquant :

Upgrade Complete
----------------
Optimizer statistics are not transferred by pg_upgrade so,
once you start the new server, consider running:
    ./analyze_new_cluster.sh

Running this script will delete the old cluster's data files:
    ./delete_old_cluster.sh

Vous pouvez ignorer en toute sécurité ce message.

J’ai sauté la mise à jour PostgreSQL 12, que faire maintenant ?

Vous pouvez suivre les instructions standard en haut de ce guide et elles mettront à niveau votre version vers 13 sans problème.

Si vous suivez les instructions pour les environnements à espace contraint, adaptez les numéros de version en conséquence.

38 « J'aime »
PostgreSQL Details
Discourse 2.7.0.beta2 Release Notes
Forum offline due to failed rebuilds on Tests-Pass
Nginx upstream timed out (110: Connection timed out)
Firewall issue with running multiple containers after upgrade
Help! Problem with firewall/permissions and postgre?
PostgreSQL 13 update from PostgreSQL 10 fails
PostgreSQL 13 update from PostgreSQL 10 fails
Unrecognized error type (ActiveRecord::StatementInvalid: PG::ProgramLimitExceeded
Recover from filesystem backup: can't rebuild nor start
Rebuild error: Errno::ENOENT: No such file or directory @ rb_sysopen - /e tc/postgresql/13/main/pg_hba.conf
Discourse broken after upgrade
Upgrade Failed from 2.7.0.beta1 to 2.7.0.beta3
Invalid location error after update
Upgrade failed!
Upgrade failed: PostgreSQL version 13 ... not compatible with ... version 10.12
Improved Bookmarks with Reminders
Importing old database to latest version
Errors encountered when uploading images
What else do I need to take care of when self hosting?
Rebuild freezing when attempting to stop container
Backup failed due to PG/SQL errors
Restore Failing - Check Free Disk Space
Supported postgresql versions
Wrong Error Message for too short replies for Reply-by-Email
Upgrade Postgres with REALLY limited space
Upgrade Postgres with REALLY limited space
Postgres has 100% CPU for large databases, Discourse 2.7.7
Upgrade failing with FAILED TO BOOTSTRAP
Stuck in an update loop after PostgreSQL 13 update
Problem with rebuild Discourse at Docker
After Rebuild got error: postgres:10/main, Causes CPU to go high
Call AdminDashboardGeneralData.refresh_stats at boot?
ERROR: You are running an old version of the Discourse image
Failed to upgrade to v2.9.0beta3
Failed to upgrade to v2.9.0beta3
SMTP Settings in app.yml reset?
Upgrade container - keeping config and data
Site down after failed update: permission denied to create extension "unaccent"
Rebuild fails on db:migrate w/PG12
Update from 2.9.0 beta2 to beta4 failed (my site is down)
Performance optimisation tips
Upgrading from 2.4 to 2.9. Need slight assistance on what order to run the final commands & reboot in
Problem when updating Discourse Forum
Troubleshooting severe performance issues with latest Discourse?
Slow Profile Loads with 100GB+ database
Use Nginx Proxy Manager to manage multiple sites with Discourse
Horizontal loading slider
Upgrading Discourse from 2.6.0.beta2
PostgreSQL 15 update
Got a lot of "Failed to backfill 'Reader' badge" errors
Trouble updating discourse after some time - UPGRADE OF POSTGRES FAILED
Database size/maintenance
Upgrade gone sideways [deprecated Guest Gate plugin]
Upgrade Issues: Failed Upgrade due to Duplicate Key, Failed Snapshot Restore
2.7.0.beta2 upgrade failed with ERROR: duplicate key
Problem, rebuild to latest version
Urgent, upgraded build failed UniqueViolation

This is a bit older already but I was just doing a Reindex as I feel it was needed with indexes growing far too big.

For one I got the message that these two indexes couldn’t be reindexed in concurrent mode…

WARNING:  cannot reindex invalid index "public.index_post_timings_on_user_id_ccnew" concurrently, skipping
WARNING:  cannot reindex invalid index "public.post_timings_unique_ccnew" concurrently, skipping

I’m not sure if it would be necessary to reindex them anyways… but apart from that I went from this

table_name                           | row_estimate | table_size | index_size | total_size
-----------------------------------------------------------------------------------
post_timings                         | 838056320    | 39 GB      | 91 GB      | 131 GB
user_auth_token_logs                 | 55448312     | 13 GB      | 2753 MB    | 16 GB
user_visits                          | 6297707      | 364 MB     | 13 GB      | 14 GB
topic_views                          | 68461928     | 3154 MB    | 10 GB      | 13 GB
posts                                | 3709657      | 4994 MB    | 1014 MB    | 6008 MB
user_actions                         | 12126485     | 902 MB     | 3212 MB    | 4114 MB
post_search_data                     | 3655090      | 3250 MB    | 838 MB     | 4088 MB
topic_users                          | 19241922     | 1758 MB    | 1765 MB    | 3523 MB
incoming_links                       | 17313212     | 1108 MB    | 1027 MB    | 2135 MB
notifications                        | 3412445      | 1248 MB    | 461 MB     | 1709 MB
topic_links                          | 1040165      | 219 MB     | 592 MB     | 811 MB
user_profile_views                   | 4272621      | 234 MB     | 552 MB     | 786 MB
users                                | 58888        | 45 MB      | 734 MB     | 780 MB
email_logs                           | 1647494      | 470 MB     | 155 MB     | 625 MB
top_topics                           | 80524        | 69 MB      | 497 MB     | 566 MB
topic_link_clicks                    | 4687408      | 285 MB     | 243 MB     | 528 MB
post_actions                         | 3304748      | 244 MB     | 278 MB     | 522 MB
optimized_images                     | 1214201      | 361 MB     | 146 MB     | 506 MB
unsubscribe_keys                     | 1116854      | 191 MB     | 283 MB     | 474 MB
post_stats                           | 3703477      | 242 MB     | 159 MB     | 400 MB
post_revisions                       | 211684       | 376 MB     | 15 MB      | 391 MB
uploads                              | 321893       | 113 MB     | 224 MB     | 337 MB
topics                               | 301795       | 198 MB     | 71 MB      | 268 MB
post_custom_fields                   | 1175950      | 134 MB     | 107 MB     | 240 MB
topic_search_data                    | 294171       | 171 MB     | 64 MB      | 236 MB
search_logs                          | 711491       | 78 MB      | 104 MB     | 182 MB
post_replies                         | 1445383      | 84 MB      | 62 MB      | 146 MB
upload_references                    | 618769       | 47 MB      | 98 MB      | 145 MB
permalinks                           | 1003118      | 81 MB      | 60 MB      | 141 MB
sidebar_section_links                | 957929       | 71 MB      | 66 MB      | 137 MB
skipped_email_logs                   | 182522       | 32 MB      | 96 MB      | 128 MB
user_stats                           | 58888        | 110 MB     | 8648 kB    | 118 MB
post_uploads                         | 407543       | 26 MB      | 92 MB      | 118 MB
user_badges                          | 371916       | 39 MB      | 65 MB      | 105 MB
user_histories                       | 196073       | 62 MB      | 41 MB      | 102 MB
draft_sequences                      | 728706       | 46 MB      | 42 MB      | 88 MB
post_hotlinked_media                 | 413007       | 52 MB      | 35 MB      | 87 MB
directory_items                      | 350825       | 32 MB      | 54 MB      | 86 MB
given_daily_likes                    | 935113       | 42 MB      | 27 MB      | 69 MB
user_auth_tokens                     | 49808        | 27 MB      | 34 MB      | 60 MB
quoted_posts                         | 380076       | 23 MB      | 33 MB      | 57 MB
topic_allowed_users                  | 416505       | 25 MB      | 30 MB      | 56 MB
scheduler_stats                      | 263695       | 40 MB      | 9448 kB    | 49 MB
user_uploads                         | 337637       | 19 MB      | 28 MB      | 47 MB
user_options                         | 87346        | 27 MB      | 6152 kB    | 33 MB
email_tokens                         | 77848        | 13 MB      | 10 MB      | 24 MB
reviewables                          | 31052        | 6368 kB    | 17 MB      | 23 MB
topic_custom_fields                  | 130005       | 10008 kB   | 13 MB      | 22 MB
poll_votes                           | 173402       | 12 MB      | 11 MB      | 22 MB
group_users                          | 133293       | 12 MB      | 8888 kB    | 21 MB
user_emails                          | 58330        | 6136 kB    | 14 MB      | 20 MB
dismissed_topic_users                | 168660       | 11 MB      | 8240 kB    | 19 MB
shelved_notifications                | 212444       | 9360 kB    | 9392 kB    | 18 MB
user_custom_fields                   | 105860       | 8848 kB    | 6784 kB    | 15 MB
bookmarks                            | 42609        | 5192 kB    | 9872 kB    | 15 MB
user_avatars                         | 58646        | 3864 kB    | 7504 kB    | 11 MB
user_search_data                     | 58873        | 5704 kB    | 5216 kB    | 11 MB
plugin_store_rows                    | 40561        | 7792 kB    | 2904 kB    | 10 MB
reviewable_histories                 | 61304        | 4768 kB    | 5400 kB    | 10168 kB
user_profiles                        | 58882        | 6224 kB    | 3320 kB    | 9544 kB
reviewable_scores                    | 34792        | 4352 kB    | 2888 kB    | 7240 kB
user_archived_messages               | 57104        | 3464 kB    | 2648 kB    | 6112 kB
stylesheet_cache                     | 98           | 5304 kB    | 192 kB     | 5496 kB
topic_thumbnails                     | 23356        | 1424 kB    | 3096 kB    | 4520 kB
web_crawler_requests                 | 3888         | 648 kB     | 3224 kB    | 3872 kB
incoming_referers                    | 12252        | 1656 kB    | 1896 kB    | 3552 kB
drafts                               | 2574         | 2720 kB    | 216 kB     | 2936 kB
poll_options                         | 11424        | 1600 kB    | 1224 kB    | 2824 kB
application_requests                 | 12631        | 896 kB     | 744 kB     | 1640 kB
group_histories                      | 7844         | 632 kB     | 600 kB     | 1232 kB
user_api_keys                        | 321          | 904 kB     | 312 kB     | 1216 kB
ignored_users                        | 5121         | 424 kB     | 384 kB     | 808 kB
topic_groups                         | 5745         | 448 kB     | 288 kB     | 736 kB
topic_allowed_groups                 | 5728         | 296 kB     | 440 kB     | 736 kB
polls                                | 3505         | 408 kB     | 320 kB     | 728 kB
push_subscriptions                   | 1359         | 664 kB     | 56 kB      | 720 kB
group_archived_messages              | 5698         | 376 kB     | 288 kB     | 664 kB
category_users                       | 3958         | 256 kB     | 392 kB     | 648 kB
categories                           | 101          | 536 kB     | 112 kB     | 648 kB
incoming_domains                     | 3109         | 216 kB     | 240 kB     | 456 kB
group_mentions                       | 2817         | 208 kB     | 240 kB     | 448 kB
topic_timers                         | 1714         | 224 kB     | 176 kB     | 400 kB
user_second_factors                  | 1062         | 240 kB     | 144 kB     | 384 kB
category_featured_topics             | 748          | 104 kB     | 272 kB     | 376 kB
schema_migration_details             | 1415         | 264 kB     | 112 kB     | 376 kB
user_notification_schedules          | 1055         | 144 kB     | 96 kB      | 240 kB
user_api_key_scopes                  | 933          | 112 kB     | 80 kB      | 192 kB
javascript_caches                    | 8            | 128 kB     | 64 kB      | 192 kB
theme_fields                         | 17           | 152 kB     | 32 kB      | 184 kB
user_security_keys                   | 40           | 56 kB      | 112 kB     | 168 kB
schema_migrations                    | 1413         | 104 kB     | 64 kB      | 168 kB
user_warnings                        | 431          | 64 kB      | 96 kB      | 160 kB
muted_users                          | 432          | 64 kB      | 96 kB      | 160 kB
badges                               | 54           | 104 kB     | 48 kB      | 152 kB
chat_channels                        | 1            | 48 kB      | 96 kB      | 144 kB
invites                              | 126          | 64 kB      | 80 kB      | 144 kB
do_not_disturb_timings               | 312          | 56 kB      | 80 kB      | 136 kB
groups                               | 12           | 64 kB      | 48 kB      | 112 kB
data_explorer_query_groups           | 6            | 40 kB      | 64 kB      | 104 kB
site_settings                        | 161          | 64 kB      | 32 kB      | 96 kB
screened_urls                        | 2            | 48 kB      | 48 kB      | 96 kB
screened_emails                      | 10           | 48 kB      | 48 kB      | 96 kB
email_change_requests                | 22           | 48 kB      | 48 kB      | 96 kB
data_explorer_queries                | 19           | 80 kB      | 16 kB      | 96 kB
linked_topics                        | 183          | 48 kB      | 48 kB      | 96 kB
screened_ip_addresses                | 16           | 48 kB      | 48 kB      | 96 kB
user_chat_channel_memberships        | 18           | 40 kB      | 48 kB      | 88 kB
invited_users                        | 34           | 40 kB      | 48 kB      | 88 kB
child_themes                         | 2            | 40 kB      | 48 kB      | 88 kB
category_search_data                 | 101          | 56 kB      | 32 kB      | 88 kB
topic_invites                        | 17           | 40 kB      | 48 kB      | 88 kB
sitemaps                             | 10           | 48 kB      | 32 kB      | 80 kB
category_groups                      | 142          | 48 kB      | 32 kB      | 80 kB
directory_columns                    | 10           | 48 kB      | 32 kB      | 80 kB
translation_overrides                | 27           | 48 kB      | 32 kB      | 80 kB
theme_modifier_sets                  | 6            | 48 kB      | 32 kB      | 80 kB
onceoff_logs                         | 36           | 48 kB      | 32 kB      | 80 kB
color_scheme_colors                  | 40           | 48 kB      | 32 kB      | 80 kB
badge_types                          | 3            | 48 kB      | 32 kB      | 80 kB
themes                               | 6            | 48 kB      | 32 kB      | 80 kB
category_custom_fields               | 78           | 48 kB      | 32 kB      | 80 kB
incoming_emails                      | 0            | 8192 bytes | 64 kB      | 72 kB
ar_internal_metadata                 | 1            | 48 kB      | 16 kB      | 64 kB
backup_metadata                      | 6            | 48 kB      | 16 kB      | 64 kB
badge_groupings                      | 5            | 48 kB      | 16 kB      | 64 kB
color_schemes                        | 4            | 48 kB      | 16 kB      | 64 kB
web_hook_event_types                 | 14           | 48 kB      | 16 kB      | 64 kB
user_fields                          | 2            | 48 kB      | 16 kB      | 64 kB
theme_settings                       | 10           | 48 kB      | 16 kB      | 64 kB
user_field_options                   | 11           | 48 kB      | 16 kB      | 64 kB
user_exports                         | 61           | 48 kB      | 16 kB      | 64 kB
remote_themes                        | 4            | 48 kB      | 16 kB      | 64 kB
chat_threads                         | 0            | 8192 bytes | 48 kB      | 56 kB
watched_words                        | 0            | 24 kB      | 32 kB      | 56 kB
post_action_types                    | 7            | 40 kB      | 16 kB      | 56 kB
chat_messages                        | 0            | 8192 bytes | 48 kB      | 56 kB
external_upload_stubs                | 0            | 8192 bytes | 40 kB      | 48 kB
group_requests                       | 0            | 8192 bytes | 32 kB      | 40 kB
category_tag_stats                   | 0            | 0 bytes    | 40 kB      | 40 kB
user_associated_accounts             | 0            | 8192 bytes | 24 kB      | 32 kB
published_pages                      | 0            | 8192 bytes | 24 kB      | 32 kB
single_sign_on_records               | 0            | 8192 bytes | 24 kB      | 32 kB
tag_search_data                      | 0            | 8192 bytes | 24 kB      | 32 kB
tags                                 | 0            | 8192 bytes | 24 kB      | 32 kB
theme_translation_overrides          | 0            | 8192 bytes | 24 kB      | 32 kB
oauth2_user_infos                    | 0            | 8192 bytes | 24 kB      | 32 kB
api_keys                             | 0            | 8192 bytes | 24 kB      | 32 kB
backup_draft_posts                   | 0            | 8192 bytes | 24 kB      | 32 kB
group_associated_groups              | 0            | 0 bytes    | 32 kB      | 32 kB
user_associated_groups               | 0            | 0 bytes    | 32 kB      | 32 kB
imap_sync_logs                       | 0            | 8192 bytes | 24 kB      | 32 kB
chat_message_revisions               | 0            | 8192 bytes | 24 kB      | 32 kB
tag_group_permissions                | 0            | 0 bytes    | 24 kB      | 24 kB
topic_embeds                         | 0            | 8192 bytes | 16 kB      | 24 kB
custom_emojis                        | 0            | 8192 bytes | 16 kB      | 24 kB
api_key_scopes                       | 0            | 8192 bytes | 16 kB      | 24 kB
user_ip_address_histories            | 0            | 8192 bytes | 16 kB      | 24 kB
user_open_ids                        | 0            | 8192 bytes | 16 kB      | 24 kB
group_custom_fields                  | 0            | 8192 bytes | 16 kB      | 24 kB
web_hook_events                      | 0            | 8192 bytes | 16 kB      | 24 kB
form_templates                       | 0            | 8192 bytes | 16 kB      | 24 kB
associated_groups                    | 0            | 8192 bytes | 16 kB      | 24 kB
post_reply_keys                      | 0            | 0 bytes    | 24 kB      | 24 kB
chat_channel_archives                | 0            | 8192 bytes | 16 kB      | 24 kB
tag_users                            | 0            | 0 bytes    | 24 kB      | 24 kB
chat_message_reactions               | 0            | 8192 bytes | 16 kB      | 24 kB
backup_draft_topics                  | 0            | 0 bytes    | 24 kB      | 24 kB
shared_drafts                        | 0            | 0 bytes    | 24 kB      | 24 kB
anonymous_users                      | 0            | 0 bytes    | 24 kB      | 24 kB
category_tags                        | 0            | 0 bytes    | 24 kB      | 24 kB
incoming_chat_webhooks               | 0            | 8192 bytes | 16 kB      | 24 kB
allowed_pm_users                     | 0            | 0 bytes    | 24 kB      | 24 kB
message_bus                          | 0            | 8192 bytes | 16 kB      | 24 kB
post_details                         | 0            | 8192 bytes | 16 kB      | 24 kB
group_category_notification_defaults | 0            | 0 bytes    | 16 kB      | 16 kB
category_settings                    | 0            | 0 bytes    | 16 kB      | 16 kB
chat_uploads                         | 0            | 0 bytes    | 16 kB      | 16 kB
embeddable_hosts                     | 0            | 8192 bytes | 8192 bytes | 16 kB
chat_webhook_events                  | 0            | 0 bytes    | 16 kB      | 16 kB
developers                           | 0            | 0 bytes    | 16 kB      | 16 kB
sidebar_sections                     | 0            | 0 bytes    | 16 kB      | 16 kB
user_statuses                        | 0            | 8192 bytes | 8192 bytes | 16 kB
category_required_tag_groups         | 0            | 0 bytes    | 16 kB      | 16 kB
tag_groups                           | 0            | 8192 bytes | 8192 bytes | 16 kB
tag_group_memberships                | 0            | 0 bytes    | 16 kB      | 16 kB
invited_groups                       | 0            | 0 bytes    | 16 kB      | 16 kB
chat_mentions                        | 0            | 0 bytes    | 16 kB      | 16 kB
chat_drafts                          | 0            | 8192 bytes | 8192 bytes | 16 kB
web_hooks                            | 0            | 8192 bytes | 8192 bytes | 16 kB
group_tag_notification_defaults      | 0            | 0 bytes    | 16 kB      | 16 kB
reviewable_claimed_topics            | 0            | 0 bytes    | 16 kB      | 16 kB
category_tag_groups                  | 0            | 0 bytes    | 16 kB      | 16 kB
direct_message_users                 | 0            | 0 bytes    | 16 kB      | 16 kB
topic_tags                           | 0            | 0 bytes    | 16 kB      | 16 kB
direct_message_channels              | 0            | 0 bytes    | 8192 bytes | 8192 bytes
sidebar_urls                         | 0            | 0 bytes    | 8192 bytes | 8192 bytes
web_hook_event_types_hooks           | 0            | 0 bytes    | 8192 bytes | 8192 bytes
groups_web_hooks                     | 0            | 0 bytes    | 8192 bytes | 8192 bytes
tags_web_hooks                       | 0            | 0 bytes    | 8192 bytes | 8192 bytes
categories_web_hooks                 | 0            | 0 bytes    | 8192 bytes | 8192 bytes
badge_posts                          | 0            | 0 bytes    | 0 bytes    | 0 bytes

to this

table_name                           | row_estimate | table_size | index_size | total_size
-----------------------------------------------------------------------------------
post_timings                         | 839165632    | 39 GB      | 60 GB      | 99 GB
user_auth_token_logs                 | 55837296     | 13 GB      | 1571 MB    | 14 GB
topic_views                          | 69342912     | 3155 MB    | 4833 MB    | 7988 MB
posts                                | 3703619      | 4994 MB    | 1111 MB    | 6105 MB
post_search_data                     | 3655554      | 3294 MB    | 854 MB     | 4148 MB
topic_users                          | 19252818     | 1760 MB    | 1377 MB    | 3137 MB
user_actions                         | 12332480     | 902 MB     | 1911 MB    | 2813 MB
incoming_links                       | 17359070     | 1108 MB    | 1028 MB    | 2136 MB
notifications                        | 3265898      | 1248 MB    | 451 MB     | 1699 MB
user_visits                          | 6301336      | 364 MB     | 503 MB     | 867 MB
email_logs                           | 1642194      | 470 MB     | 150 MB     | 620 MB
user_profile_views                   | 4383830      | 234 MB     | 355 MB     | 589 MB
post_actions                         | 3310096      | 244 MB     | 278 MB     | 522 MB
optimized_images                     | 1219705      | 361 MB     | 147 MB     | 508 MB
topic_link_clicks                    | 4726663      | 285 MB     | 136 MB     | 422 MB
topic_links                          | 1050293      | 219 MB     | 201 MB     | 420 MB
post_stats                           | 3706837      | 242 MB     | 159 MB     | 400 MB
post_revisions                       | 211988       | 376 MB     | 15 MB      | 391 MB
unsubscribe_keys                     | 1122585      | 191 MB     | 126 MB     | 317 MB
topics                               | 301847       | 198 MB     | 69 MB      | 267 MB
uploads                              | 324756       | 113 MB     | 153 MB     | 267 MB
sidebar_section_links                | 966652       | 149 MB     | 94 MB      | 242 MB
post_custom_fields                   | 1176075      | 134 MB     | 107 MB     | 240 MB
topic_search_data                    | 296501       | 177 MB     | 58 MB      | 235 MB
post_replies                         | 1447174      | 84 MB      | 62 MB      | 146 MB
permalinks                           | 1003118      | 81 MB      | 60 MB      | 141 MB
search_logs                          | 599529       | 78 MB      | 37 MB      | 115 MB
user_stats                           | 58903        | 110 MB     | 1304 kB    | 111 MB
top_topics                           | 90583        | 69 MB      | 30 MB      | 99 MB
user_histories                       | 197285       | 62 MB      | 31 MB      | 92 MB
upload_references                    | 406557       | 47 MB      | 42 MB      | 89 MB
draft_sequences                      | 729650       | 46 MB      | 42 MB      | 88 MB
post_hotlinked_media                 | 413007       | 52 MB      | 35 MB      | 87 MB
user_badges                          | 373573       | 39 MB      | 30 MB      | 69 MB
given_daily_likes                    | 936258       | 42 MB      | 27 MB      | 69 MB
directory_items                      | 350832       | 32 MB      | 32 MB      | 65 MB
users                                | 58903        | 45 MB      | 18 MB      | 63 MB
topic_allowed_users                  | 431955       | 25 MB      | 28 MB      | 53 MB
quoted_posts                         | 386420       | 23 MB      | 25 MB      | 48 MB
scheduler_stats                      | 264749       | 40 MB      | 5848 kB    | 46 MB
post_uploads                         | 249805       | 26 MB      | 20 MB      | 46 MB
skipped_email_logs                   | 183171       | 32 MB      | 13 MB      | 45 MB
user_uploads                         | 363722       | 19 MB      | 23 MB      | 42 MB
user_auth_tokens                     | 49923        | 27 MB      | 7656 kB    | 34 MB
user_options                         | 58894        | 27 MB      | 3024 kB    | 29 MB
email_tokens                         | 77921        | 13 MB      | 10 MB      | 24 MB
poll_votes                           | 173471       | 12 MB      | 11 MB      | 22 MB
topic_custom_fields                  | 131252       | 10008 kB   | 12 MB      | 22 MB
group_users                          | 133321       | 12 MB      | 8856 kB    | 21 MB
shelved_notifications                | 212779       | 9360 kB    | 9392 kB    | 18 MB
dismissed_topic_users                | 167180       | 11 MB      | 7440 kB    | 18 MB
user_custom_fields                   | 106316       | 8848 kB    | 6376 kB    | 15 MB
user_emails                          | 59131        | 6136 kB    | 8776 kB    | 15 MB
reviewables                          | 31330        | 6736 kB    | 7048 kB    | 13 MB
user_search_data                     | 58894        | 5704 kB    | 5832 kB    | 11 MB
plugin_store_rows                    | 40617        | 7800 kB    | 2896 kB    | 10 MB
user_profiles                        | 58894        | 6224 kB    | 2992 kB    | 9216 kB
bookmarks                            | 38626        | 5192 kB    | 3952 kB    | 9144 kB
reviewable_histories                 | 68163        | 4768 kB    | 3344 kB    | 8112 kB
user_avatars                         | 58894        | 3864 kB    | 3624 kB    | 7488 kB
reviewable_scores                    | 35693        | 4352 kB    | 1880 kB    | 6232 kB
user_archived_messages               | 57929        | 3464 kB    | 2576 kB    | 6040 kB
stylesheet_cache                     | 137          | 4872 kB    | 48 kB      | 4920 kB
topic_thumbnails                     | 24120        | 1424 kB    | 2328 kB    | 3752 kB
incoming_referers                    | 12269        | 1656 kB    | 1896 kB    | 3552 kB
drafts                               | 2581         | 2720 kB    | 208 kB     | 2928 kB
poll_options                         | 11426        | 1600 kB    | 1224 kB    | 2824 kB
application_requests                 | 12632        | 896 kB     | 592 kB     | 1488 kB
group_histories                      | 7859         | 632 kB     | 600 kB     | 1232 kB
web_crawler_requests                 | 3909         | 648 kB     | 496 kB     | 1144 kB
user_api_keys                        | 321          | 904 kB     | 128 kB     | 1032 kB
ignored_users                        | 5135         | 424 kB     | 408 kB     | 832 kB
topic_groups                         | 5746         | 448 kB     | 288 kB     | 736 kB
topic_allowed_groups                 | 5776         | 296 kB     | 432 kB     | 728 kB
polls                                | 3506         | 408 kB     | 320 kB     | 728 kB
push_subscriptions                   | 1381         | 664 kB     | 48 kB      | 712 kB
category_users                       | 3959         | 256 kB     | 448 kB     | 704 kB
group_archived_messages              | 5711         | 376 kB     | 288 kB     | 664 kB
categories                           | 101          | 536 kB     | 112 kB     | 648 kB
incoming_domains                     | 3113         | 216 kB     | 240 kB     | 456 kB
group_mentions                       | 2821         | 208 kB     | 240 kB     | 448 kB
schema_migration_details             | 1477         | 272 kB     | 120 kB     | 392 kB
topic_timers                         | 1741         | 224 kB     | 120 kB     | 344 kB
user_second_factors                  | 1084         | 240 kB     | 88 kB      | 328 kB
category_featured_topics             | 748          | 104 kB     | 160 kB     | 264 kB
user_notification_schedules          | 1057         | 144 kB     | 96 kB      | 240 kB
javascript_caches                    | 8            | 128 kB     | 64 kB      | 192 kB
user_api_key_scopes                  | 936          | 112 kB     | 72 kB      | 184 kB
theme_fields                         | 17           | 152 kB     | 32 kB      | 184 kB
schema_migrations                    | 1475         | 104 kB     | 64 kB      | 168 kB
user_security_keys                   | 41           | 56 kB      | 112 kB     | 168 kB
chat_channels                        | 1            | 48 kB      | 112 kB     | 160 kB
muted_users                          | 431          | 64 kB      | 96 kB      | 160 kB
user_warnings                        | 437          | 64 kB      | 96 kB      | 160 kB
badges                               | 54           | 104 kB     | 48 kB      | 152 kB
invites                              | 126          | 64 kB      | 80 kB      | 144 kB
do_not_disturb_timings               | 240          | 56 kB      | 80 kB      | 136 kB
groups                               | 12           | 64 kB      | 48 kB      | 112 kB
data_explorer_query_groups           | 6            | 40 kB      | 64 kB      | 104 kB
data_explorer_queries                | 19           | 80 kB      | 16 kB      | 96 kB
email_change_requests                | 22           | 48 kB      | 48 kB      | 96 kB
linked_topics                        | 183          | 48 kB      | 48 kB      | 96 kB
screened_ip_addresses                | 15           | 48 kB      | 48 kB      | 96 kB
screened_emails                      | 9            | 48 kB      | 48 kB      | 96 kB
screened_urls                        | 2            | 48 kB      | 48 kB      | 96 kB
site_settings                        | 161          | 64 kB      | 32 kB      | 96 kB
user_chat_channel_memberships        | 18           | 40 kB      | 48 kB      | 88 kB
invited_users                        | 34           | 40 kB      | 48 kB      | 88 kB
category_search_data                 | 101          | 56 kB      | 32 kB      | 88 kB
topic_invites                        | 17           | 40 kB      | 48 kB      | 88 kB
child_themes                         | 2            | 40 kB      | 48 kB      | 88 kB
color_scheme_colors                  | 40           | 48 kB      | 32 kB      | 80 kB
category_groups                      | 142          | 48 kB      | 32 kB      | 80 kB
onceoff_logs                         | 36           | 48 kB      | 32 kB      | 80 kB
directory_columns                    | 10           | 48 kB      | 32 kB      | 80 kB
theme_modifier_sets                  | 6            | 48 kB      | 32 kB      | 80 kB
sitemaps                             | 10           | 48 kB      | 32 kB      | 80 kB
themes                               | 6            | 48 kB      | 32 kB      | 80 kB
category_custom_fields               | 78           | 48 kB      | 32 kB      | 80 kB
badge_types                          | 3            | 48 kB      | 32 kB      | 80 kB
translation_overrides                | 27           | 48 kB      | 32 kB      | 80 kB
chat_threads                         | 0            | 8192 bytes | 64 kB      | 72 kB
incoming_emails                      | 0            | 8192 bytes | 64 kB      | 72 kB
user_exports                         | 61           | 48 kB      | 16 kB      | 64 kB
chat_messages                        | 0            | 8192 bytes | 56 kB      | 64 kB
web_hook_event_types                 | 14           | 48 kB      | 16 kB      | 64 kB
ar_internal_metadata                 | 1            | 48 kB      | 16 kB      | 64 kB
badge_groupings                      | 5            | 48 kB      | 16 kB      | 64 kB
user_fields                          | 2            | 48 kB      | 16 kB      | 64 kB
color_schemes                        | 4            | 48 kB      | 16 kB      | 64 kB
remote_themes                        | 4            | 48 kB      | 16 kB      | 64 kB
user_field_options                   | 11           | 48 kB      | 16 kB      | 64 kB
backup_metadata                      | 6            | 48 kB      | 16 kB      | 64 kB
theme_settings                       | 10           | 48 kB      | 16 kB      | 64 kB
post_action_types                    | 7            | 40 kB      | 16 kB      | 56 kB
sidebar_sections                     | 1            | 8192 bytes | 48 kB      | 56 kB
external_upload_stubs                | 0            | 8192 bytes | 40 kB      | 48 kB
group_requests                       | 0            | 8192 bytes | 32 kB      | 40 kB
category_settings                    | 101          | 8192 bytes | 32 kB      | 40 kB
watched_words                        | 0            | 24 kB      | 16 kB      | 40 kB
category_tag_stats                   | 0            | 0 bytes    | 40 kB      | 40 kB
tags                                 | 0            | 8192 bytes | 24 kB      | 32 kB
group_associated_groups              | 0            | 0 bytes    | 32 kB      | 32 kB
imap_sync_logs                       | 0            | 8192 bytes | 24 kB      | 32 kB
tag_search_data                      | 0            | 8192 bytes | 24 kB      | 32 kB
user_associated_groups               | 0            | 0 bytes    | 32 kB      | 32 kB
published_pages                      | 0            | 8192 bytes | 24 kB      | 32 kB
api_keys                             | 0            | 8192 bytes | 24 kB      | 32 kB
backup_draft_posts                   | 0            | 8192 bytes | 24 kB      | 32 kB
oauth2_user_infos                    | 0            | 8192 bytes | 24 kB      | 32 kB
user_associated_accounts             | 0            | 8192 bytes | 24 kB      | 32 kB
chat_message_revisions               | 0            | 8192 bytes | 24 kB      | 32 kB
single_sign_on_records               | 0            | 8192 bytes | 24 kB      | 32 kB
theme_translation_overrides          | 0            | 8192 bytes | 24 kB      | 32 kB
category_form_templates              | 0            | 0 bytes    | 24 kB      | 24 kB
message_bus                          | 0            | 8192 bytes | 16 kB      | 24 kB
chat_message_reactions               | 0            | 8192 bytes | 16 kB      | 24 kB
shared_drafts                        | 0            | 0 bytes    | 24 kB      | 24 kB
chat_channel_archives                | 0            | 8192 bytes | 16 kB      | 24 kB
group_custom_fields                  | 0            | 8192 bytes | 16 kB      | 24 kB
tag_group_permissions                | 0            | 0 bytes    | 24 kB      | 24 kB
tag_users                            | 0            | 0 bytes    | 24 kB      | 24 kB
custom_emojis                        | 0            | 8192 bytes | 16 kB      | 24 kB
topic_embeds                         | 0            | 8192 bytes | 16 kB      | 24 kB
category_tags                        | 0            | 0 bytes    | 24 kB      | 24 kB
backup_draft_topics                  | 0            | 0 bytes    | 24 kB      | 24 kB
anonymous_users                      | 0            | 0 bytes    | 24 kB      | 24 kB
allowed_pm_users                     | 0            | 0 bytes    | 24 kB      | 24 kB
sidebar_urls                         | 9            | 8192 bytes | 16 kB      | 24 kB
user_ip_address_histories            | 0            | 8192 bytes | 16 kB      | 24 kB
user_open_ids                        | 0            | 8192 bytes | 16 kB      | 24 kB
api_key_scopes                       | 0            | 8192 bytes | 16 kB      | 24 kB
form_templates                       | 0            | 8192 bytes | 16 kB      | 24 kB
web_hook_events                      | 0            | 8192 bytes | 16 kB      | 24 kB
associated_groups                    | 0            | 8192 bytes | 16 kB      | 24 kB
theme_svg_sprites                    | 0            | 8192 bytes | 16 kB      | 24 kB
incoming_chat_webhooks               | 0            | 8192 bytes | 16 kB      | 24 kB
post_details                         | 0            | 8192 bytes | 16 kB      | 24 kB
post_reply_keys                      | 0            | 0 bytes    | 24 kB      | 24 kB
developers                           | 0            | 0 bytes    | 16 kB      | 16 kB
embeddable_hosts                     | 0            | 8192 bytes | 8192 bytes | 16 kB
group_category_notification_defaults | 0            | 0 bytes    | 16 kB      | 16 kB
invited_groups                       | 0            | 0 bytes    | 16 kB      | 16 kB
chat_drafts                          | 0            | 8192 bytes | 8192 bytes | 16 kB
topic_tags                           | 0            | 0 bytes    | 16 kB      | 16 kB
user_statuses                        | 0            | 8192 bytes | 8192 bytes | 16 kB
category_tag_groups                  | 0            | 0 bytes    | 16 kB      | 16 kB
category_required_tag_groups         | 0            | 0 bytes    | 16 kB      | 16 kB
tag_groups                           | 0            | 8192 bytes | 8192 bytes | 16 kB
chat_mentions                        | 0            | 0 bytes    | 16 kB      | 16 kB
web_hooks                            | 0            | 8192 bytes | 8192 bytes | 16 kB
chat_webhook_events                  | 0            | 0 bytes    | 16 kB      | 16 kB
summary_sections                     | 0            | 8192 bytes | 8192 bytes | 16 kB
user_chat_thread_memberships         | 0            | 0 bytes    | 16 kB      | 16 kB
reviewable_claimed_topics            | 0            | 0 bytes    | 16 kB      | 16 kB
tag_group_memberships                | 0            | 0 bytes    | 16 kB      | 16 kB
direct_message_users                 | 0            | 0 bytes    | 16 kB      | 16 kB
group_tag_notification_defaults      | 0            | 0 bytes    | 16 kB      | 16 kB
tags_web_hooks                       | 0            | 0 bytes    | 8192 bytes | 8192 bytes
categories_web_hooks                 | 0            | 0 bytes    | 8192 bytes | 8192 bytes
web_hook_event_types_hooks           | 0            | 0 bytes    | 8192 bytes | 8192 bytes
direct_message_channels              | 0            | 0 bytes    | 8192 bytes | 8192 bytes
groups_web_hooks                     | 0            | 0 bytes    | 8192 bytes | 8192 bytes
badge_posts                          | 0            | 0 bytes    | 0 bytes    | 0 bytes

which is quite a bit already. What do you think about the two indexes above?

2 « J'aime »

Ces index proviennent d’une précédente tentative de réindexation concurrente qui a échoué.

Lorsque Postgres effectue une réindexation concurrente, le nouvel index est créé avec le suffixe _ccnew. Une fois le nouvel index reconstruit, l’ancien est remplacé par le nouveau. Si une réindexation concurrente échoue, l’index temporaire _ccnew n’est pas supprimé.

Il est possible de supprimer manuellement ces index temporaires en toute sécurité avec DROP INDEX IF EXISTS ...

Quant à la taille des index, la réduction de 30 à 50 % sur les quatre principaux est impressionnante !

Si je lis correctement, l’index user_visits est passé de 13 Go à 503 Mo, soit moins de 5 % de la taille d’origine :exploding_head:

6 « J'aime »