Aggiornamento di PostgreSQL 13

:warning: ATTENZIONE! Se il tuo database è molto grande, avrai bisogno di molto spazio su disco aggiuntivo (2x la dimensione del database) e dovrai prestare molta attenzione durante questo aggiornamento!

Abbiamo appena implementato le modifiche per aggiornare la nostra immagine Docker a PostgreSQL 13. Qualsiasi amministratore di sito che ricostruisce Discourse da riga di comando verrà aggiornato a PostgreSQL 13 dalla precedente versione PostgreSQL 12. Nota che se hai rinviato l’aggiornamento quando è stato rilasciato l’aggiornamento a PostgreSQL 12 lo scorso maggio, puoi saltare quell’aggiornamento e passare direttamente a PostgreSQL 13.

Se avevi precedentemente rinviato l’aggiornamento, modifica il template di PostgreSQL in app.yml da templates/postgres.10.template.yml a templates/postgres.template.yml.

Come per qualsiasi aggiornamento, è fortemente consigliato eseguire un backup prima di procedere.

Aggiornamento

Guida all’installazione ufficiale (singolo contenitore)

Al prossimo rebuild, vedrai questo messaggio alla fine:

-------------------------------------------------------------------------------------
AGGIORNAMENTO DI POSTGRES COMPLETATO

Il vecchio database 12 è salvato in /shared/postgres_data_old

Per completare l'aggiornamento, esegui nuovamente il rebuild usando:

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

Ciò significa che l’aggiornamento è andato a buon fine! Devi solo eseguire un nuovo rebuild per riavviare il tuo sito.

Installazione con contenitore dati dedicato

Se stai utilizzando una configurazione con un contenitore dati dedicato basato sul campione fornito nel nostro repository discourse_docker, assicurati di spegnere PostgreSQL in modo sicuro e pulito.

Oggi, abbiamo processi in background che eseguono query della durata di diversi minuti, quindi spegnere il contenitore web aiuterà a garantire lo spegnimento sicuro del contenitore dati.

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

Prima di eseguire il primo rebuild sul contenitore dati, puoi seguire il log di PostgreSQL per verificare se è stato spento correttamente.

Eseguire tail -f shared/data/log/var-log/postgres/current dovrebbe mostrare il seguente log se lo spegnimento è stato pulito:

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

Esecuzione di un aggiornamento manuale / ambienti con spazio limitato

:warning::warning::warning:
DEVI ESEGUIRE UN BACKUP DI POSTGRES_DATA PRIMA DI PROVARE QUESTO
:warning::warning::warning:

Se ti trovi in un ambiente con spazio limitato e non hai modo di ottenere più spazio, puoi provare quanto segue:

./launcher stop app #(o entrambi web_only e data se è il tuo caso)
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 #(o prima data e poi web_only se è il tuo caso)

Nei miei test, questa procedura richiede meno di 1x la dimensione attuale del tuo database in spazio libero.

Posticipare l’aggiornamento

Se hai bisogno di posticipare l’aggiornamento durante il prossimo rebuild, puoi sostituire il template di PostgreSQL nel tuo file app.yml modificando \"templates/postgres.template.yml\" in \"templates/postgres.12.template.yml\".

Questo non è raccomandato, poiché alcuni amministratori di sito potrebbero dimenticare di annullare la modifica successivamente.

Attività opzionali post-aggiornamento

Ottimizzazione delle statistiche di PostgreSQL

Dopo l’aggiornamento, il nuovo PostgreSQL non avrà a disposizione le statistiche delle tabelle. Puoi generarle utilizzando:

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

O questa versione in una riga della precedente:

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

Ricreazione degli indici

La principale caratteristica di questo aggiornamento è il notevole risparmio di spazio nella nostra tabella più grande in ogni istanza, la tabella post_timings e i suoi indici. Dopo aver completato un aggiornamento riuscito, dovrai eseguire un comando per ricostruire gli indici e sfruttare i vantaggi.

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

Se puoi verificare le dimensioni di post_timings prima e dopo il REINDEX, sarebbe una statistica interessante da condividere qui!

Puoi utilizzare la query sottostante per verificare i 20 oggetti dati più grandi; eseguila prima e dopo il 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;

Pulizia dei vecchi dati

Per un’installazione standard, puoi eliminare i vecchi dati nel formato PG12 con il seguente comando:

cd /var/discourse
./launcher cleanup

Se hai un contenitore dati separato, dovrai rimuovere la copia di backup in questo modo:

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

FAQ

Il cluster sorgente non è stato spento correttamente

Se ricevi un errore di aggiornamento con il messaggio sopra, puoi provare un approccio più semplice per riportarlo in uno stato migliore.

Riavvia il vecchio contenitore con ./launcher start app. Attendi qualche minuto fino al suo riavvio.

Ora spegnilo nuovamente con ./launcher stop app. Dopo di che, segui i log per verificare se è stato uno spegnimento pulito:

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

Se i log sono come quelli sopra, ora puoi provare a eseguire nuovamente l’aggiornamento usando ./launcher rebuild app.

I valori lc_collate per il database “postgres” non corrispondono

Questo errore si verifica se stai utilizzando localizzazioni non predefinite per il tuo database. È stato segnalato che sono necessarie 3 variabili per il successo dell’operazione. Assicurati che la sezione env: del tuo file app.yml contenga le 3 righe:

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

Sostituendo en_US.UTF-8 con la tua localizzazione.

Ogni rebuild esegue nuovamente l’aggiornamento, ovvero ciclo di aggiornamento

Quando ciò accade, i log di aggiornamento conterranno:

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

Ciò significa che ci sono ancora file residui dall’ultimo aggiornamento. Spostali altrove prima di continuare.

Suggerimenti sugli script completi dell’aggiornamento - devo fare qualcosa?

Una volta completato l’aggiornamento, vedrai un output dal messaggio pg_upgrade che dice:

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

Puoi ignorare tranquillamente questo messaggio.

Ho saltato l’aggiornamento a PostgreSQL 12, cosa devo fare ora?

Puoi seguire le istruzioni standard nella parte superiore di questa guida; esse aggiorneranno dalla tua versione alla 13 senza problemi.

Se stai seguendo le istruzioni per ambienti con spazio limitato, adatta i numeri di versione di conseguenza.

38 Mi Piace
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 Mi Piace

Questi indici risalgono a quando un reindicizzazione concorrente è fallita in precedenza.

Quando Postgres esegue una reindicizzazione concorrente, il nuovo indice viene creato con il suffisso _ccnew. Una volta che il nuovo indice è stato ricostruito, quello vecchio viene sostituito con quello nuovo. Se una reindicizzazione concorrente fallisce, l’indice temporaneo _ccnew non viene eliminato.

È sicuro eliminare manualmente questi indici temporanei con DROP INDEX IF EXISTS ...

Per quanto riguarda le dimensioni degli indici, la riduzione del 30-50% sui primi quattro è impressionante!

Se ho letto correttamente, l’indice user_visits è sceso da 13 GB a 503 MB, \u003c5% della dimensione originale :exploding_head:

6 Mi Piace