Actualización de PostgreSQL 13

:warning: ¡ADVERTENCIA! Si tu base de datos es muy grande, necesitarás mucho espacio extra en el disco (2x el tamaño de la base de datos) y debes tener mucho cuidado con esta actualización.

Acabamos de implementar cambios para actualizar nuestra imagen Docker a PostgreSQL 13. Cualquier administrador de sitio que reconstruya Discourse desde la línea de comandos será actualizado a PostgreSQL 13 desde la versión anterior, PostgreSQL 12. Ten en cuenta que si te abstuviste de actualizar cuando se produjo la actualización de PostgreSQL 12 hace un tiempo en mayo, puedes saltarte esa actualización e ir directamente a PostgreSQL 13.

Si habías pospuesto la actualización anteriormente, cambia la plantilla de PostgreSQL en app.yml de templates/postgres.10.template.yml a templates/postgres.template.yml.

Como con cualquier actualización, se recomienda encarecidamente realizar una copia de seguridad antes de hacer cualquier cosa.

Actualización

Guía de instalación oficial (contenedor único)

En tu próxima reconstrucción, verás este mensaje al final:

-------------------------------------------------------------------------------------
ACTUALIZACIÓN DE POSTGRES COMPLETADA

La base de datos antigua 12 se almacena en /shared/postgres_data_old

Para completar la actualización, vuelve a reconstruir usando:

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

¡Eso significa que todo salió bien en la actualización! Solo necesitas ejecutar una nueva reconstrucción para que tu sitio vuelva a estar operativo.

Instalación con contenedor de datos

Si estás ejecutando una configuración con un contenedor de datos dedicado basado en el ejemplo proporcionado en nuestro repositorio discourse_docker, debes asegurarte de que PostgreSQL se detenga de manera segura y limpia.

Actualmente, tenemos trabajos en segundo plano ejecutando consultas que duran varios minutos, por lo que detener el contenedor web ayudará a que el contenedor de datos se apague de forma segura.

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

Antes de ejecutar la primera reconstrucción en el contenedor de datos, puedes seguir el registro de PostgreSQL para ver si se apagó correctamente.

Ejecutar tail -f shared/data/log/var-log/postgres/current debería mostrarte el siguiente registro si fue limpio:

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

Realizar una actualización manual / entornos con espacio limitado

:warning::warning::warning:
DEBES HACER UNA COPIA DE SEGURIDAD DE POSTGRES_DATA ANTES DE INTENTAR ESTO
:warning::warning::warning:

Si estás en un entorno con espacio limitado y no tienes forma de obtener más espacio, puedes probar lo siguiente:

./launcher stop app #(o ambos web_only y data si ese es tu 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 primero data y luego web_only si ese es tu caso)

En mis pruebas, este procedimiento requiere menos de 1x el tamaño actual de tu base de datos en espacio libre.

Posponer la actualización

Si necesitas posponer la actualización durante tu próxima reconstrucción, puedes cambiar la plantilla de PostgreSQL en tu archivo app.yml modificando "templates/postgres.template.yml" a "templates/postgres.12.template.yml".

Esto no se recomienda, ya que algunos administradores de sitios podrían olvidar revertir el cambio posteriormente.

Tareas opcionales posteriores a la actualización

Optimización de estadísticas de PostgreSQL

Después de la actualización, el nuevo PostgreSQL no tendrá estadísticas de tablas a mano. Puedes generarlas usando:

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

O esta versión de una sola línea de la anterior:

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

Volver a crear los índices

La característica principal de esta actualización es un gran ahorro de espacio en nuestra tabla más grande en cada instancia, la tabla post_timings y sus índices. Después de realizar una actualización exitosa, necesitarás ejecutar un comando para reconstruir los índices y aprovechar los beneficios.

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

Si puedes verificar el tamaño de post_timings antes y después del REINDEX, ¡sería una estadística genial para compartir aquí!

Puedes usar la siguiente consulta para verificar los 20 objetos de datos más grandes; ejecútala antes y después del reíndice:

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;

Limpieza de datos antiguos

Para una instalación estándar, puedes eliminar los datos antiguos en formato PG12 con el siguiente comando:

cd /var/discourse
./launcher cleanup

Si tienes un contenedor de datos separado, necesitarás eliminar la copia de seguridad así:

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

Preguntas frecuentes (FAQ)

El clúster de origen no se apagó limpiamente

Si obtienes un error de actualización con el mensaje anterior, puedes probar un enfoque más sencillo para devolverlo a un estado mejor.

Reinicia el contenedor antiguo con ./launcher start app. Espera unos minutos hasta que vuelva a estar activo.

Ahora apágalo nuevamente con ./launcher stop app. Después, sigue los registros para ver si fue una apagada limpia:

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

Si los registros se ven como los de arriba, ahora puedes intentar actualizar nuevamente usando ./launcher rebuild app.

Los valores de lc_collate para la base de datos “postgres” no coinciden

Este error ocurre si estás usando configuraciones regionales (locales) no predeterminadas para tu base de datos. Se reportó que necesitas 3 variables para que tenga éxito. Asegúrate de que la sección env: de tu archivo app.yml tenga las 3 líneas:

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

Cambiando en_US.UTF-8 por tu configuración regional.

Cada reconstrucción realiza la actualización nuevamente (bucle de actualización)

Cuando esto sucede, tus registros de actualización contendrán:

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

Esto significa que aún hay archivos de la última actualización flotando. Mueve esos archivos a otro lugar antes de continuar.

Scripts de sugerencia “Actualización completada” - ¿Necesito hacer algo?

Una vez que se complete la actualización, verás una salida del mensaje pg_upgrade que 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

Puedes ignorar este mensaje de forma segura.

Me salté la actualización de PostgreSQL 12, ¿qué hago ahora?

Puedes seguir las instrucciones estándar en la parte superior de esta guía y se actualizarán desde tu versión a la 13 sin problemas.

Si estás siguiendo las instrucciones para entornos con espacio limitado, adapta los números de versión en consecuencia.

38 Me gusta
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 Me gusta

Estos índices son de cuando un reíndice concurrente falló anteriormente.

Cuando Postgres realiza un reíndice concurrente, el nuevo índice se crea con el sufijo _ccnew. Una vez que el nuevo índice se reconstruye, el antiguo se reemplaza por el nuevo. Si un reíndice concurrente falla, el índice temporal _ccnew no se elimina.

Es seguro eliminar estos índices temporales manualmente con DROP INDEX IF EXISTS ...

En cuanto a los tamaños de los índices, ¡la reducción del 30-50% en los cuatro principales es impresionante!

Si estoy leyendo correctamente, el índice user_visits se redujo de 13 GB a 503 MB, ¡menos del 5% del tamaño original :exploding_head:

6 Me gusta