Atualização do PostgreSQL 13

:warning: AVISO! Se o seu banco de dados for muito grande, você precisará de muito espaço extra em disco (2x o tamanho do banco de dados) e deve ter muito cuidado com esta atualização!

Acabamos de implementar alterações para atualizar nossa imagem Docker para o PostgreSQL 13. Qualquer administrador de site que reconstrua o Discourse via linha de comando será atualizado para o PostgreSQL 13 a partir do PostgreSQL 12 anterior. Observe que, se você adiara a atualização quando a atualização do PostgreSQL 12 ocorreu em maio, você pode pular essa atualização e ir direto para o PostgreSQL 13.

Se você havia adiado a atualização anteriormente, altere o modelo do PostgreSQL no app.yml de templates/postgres.10.template.yml para templates/postgres.template.yml.

Como em qualquer atualização, é altamente recomendado fazer um backup antes de fazer qualquer coisa.

Atualizando

Guia de Instalação Oficial (contêiner único)

Na sua próxima reconstrução, você verá esta mensagem no final:

-------------------------------------------------------------------------------------
ATUALIZAÇÃO DO POSTGRES CONCLUÍDA

O banco de dados antigo 12 está armazenado em /shared/postgres_data_old

Para concluir a atualização, reconstrua novamente usando:

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

Isso significa que tudo correu bem na atualização! Você só precisa emitir uma nova reconstrução para colocar seu site de volta no ar.

Instalação com Contêiner de Dados

Se você estiver executando uma configuração com um contêiner de dados dedicado baseado no exemplo fornecido em nosso repositório discourse_docker, certifique-se de desligar o PostgreSQL de maneira segura e limpa.

Atualmente, temos jobs em segundo plano executando consultas que levam vários minutos, então desligar o contêiner web ajudará o contêiner de dados a ser desligado com segurança.

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

Antes de emitir a primeira reconstrução para o contêiner de dados, você pode seguir o log do PostgreSQL para ver se ele foi desligado corretamente.

Executar um tail -f shared/data/log/var-log/postgres/current deve fornecer o seguinte log se estiver limpo:

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

Fazendo uma atualização manual / ambientes com espaço limitado

:warning::warning::warning:
VOCÊ DEVE FAZER UM BACKUP DOS DADOS DO POSTGRES ANTES DE TENTAR ISSO
:warning::warning::warning:

Se você estiver em um ambiente com espaço limitado e sem nenhuma maneira de obter mais espaço, pode tentar o seguinte:

./launcher stop app #(ou ambos web_only e data, se for o seu 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 #(ou primeiro data e depois web_only, se for o seu caso)

Em meus testes, este procedimento requer menos de 1x o tamanho atual do seu banco de dados em espaço livre.

Adiar a atualização

Se você precisar adiar a atualização na sua próxima reconstrução, pode trocar o modelo do PostgreSQL no seu arquivo app.yml alterando \"templates/postgres.template.yml\" para \"templates/postgres.12.template.yml\".

Isso não é recomendado, pois alguns administradores de site podem esquecer de reverter a alteração depois.

Tarefas opcionais pós-atualização

Otimizando estatísticas do PostgreSQL

Após a atualização, o novo PostgreSQL não terá estatísticas de tabela em mãos. Você pode gerar essas estatísticas usando:

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

Ou esta versão de uma linha do acima:

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

Recriando os índices

A principal característica desta atualização é uma grande economia de arquivos na nossa maior tabela em cada instância, a tabela post_timings e seus índices. Após realizar uma atualização bem-sucedida, você precisará executar um comando para recriar os índices e colher os benefícios.

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

Se você puder verificar o tamanho de post_timings antes e depois do REINDEX, seria uma estatística legal para compartilhar aqui!

Você pode usar a consulta abaixo para verificar os 20 maiores objetos de dados; execute-a antes e depois do 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;

Limpando dados antigos

Para uma instalação padrão, você pode excluir os dados antigos no formato PG12 com o seguinte comando:

cd /var/discourse
./launcher cleanup

Se você tiver um contêiner de dados separado, precisará remover a cópia de backup assim:

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

FAQ

O cluster de origem não foi desligado corretamente

Se você receber uma falha na atualização com a mensagem acima, pode tentar uma abordagem mais simples para colocá-lo em um estado melhor.

Reinicie o contêiner antigo com ./launcher start app. Aguarde alguns minutos até que ele volte a subir.

Agora desligue-o novamente com ./launcher stop app. Depois disso, siga os logs para ver se foi um desligamento limpo:

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 os logs parecerem como acima, você pode tentar fazer a atualização novamente usando ./launcher rebuild app.

Os valores de lc_collate para o banco de dados “postgres” não correspondem

Esse erro ocorre se você estiver usando locais (locales) não padrão para seu banco de dados. Foi relatado que você precisa de 3 variáveis para que isso seja bem-sucedido. Certifique-se de que a seção env: do seu arquivo app.yml tenha as 3 linhas:

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

Alterando en_US.UTF-8 para o seu local (locale).

Cada reconstrução faz a atualização novamente, ou seja, loop de atualização

Quando isso acontece, seus logs de atualização conterão:

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

Isso significa que ainda há arquivos da última atualização espalhados. Mova-os para outro lugar antes de continuar.

Scripts de sugestão “Atualização Concluída” - preciso fazer algo?

Uma vez que a atualização for concluída, você verá uma saída da mensagem pg_upgrade dizendo:

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

Você pode ignorar com segurança esta mensagem.

Eu pulei a atualização do PostgreSQL 12, o que fazer agora?

Você pode seguir as instruções padrão no topo deste guia e elas atualizarão da sua versão para a 13 sem problemas.

Se você estiver seguindo as instruções para ambientes com espaço limitado, adapte os números da versão de acordo.

38 curtidas
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 curtidas

Esses índices são de quando uma reindexação concorrente falhou anteriormente.

Quando o Postgres está executando uma reindexação concorrente, o novo índice é criado com o sufixo _ccnew. Assim que o novo índice é reconstruído, o antigo é substituído pelo novo. Se uma reindexação concorrente falhar, o índice temporário _ccnew não é excluído.

É seguro remover esses índices temporários manualmente com DROP INDEX IF EXISTS ...

Quanto aos tamanhos dos índices, a redução de 30-50% nos quatro principais é impressionante!

Se estou lendo corretamente, o índice user_visits caiu de 13GB para 503MB, \u003c5% do tamanho original :exploding_head:

6 curtidas