FATAL: could not access file "pg_stat_statements"
Solución rápida al error "No such file or directory" al intentar iniciar PostgreSQL cuando falta el paquete postgresql-contrib.
El problema
Cuando se intenta iniciar el motor de PostgreSQL, se genera el siguiente error:
[root@repanalitica 10]# systemctl start postgresql.service
Job for postgresql.service failed because the control process exited with error code.
See "systemctl status postgresql.service" and "journalctl -xe" for details. Revisando los logs
Al revisar los logs con journalctl -xe, encontramos:
Aug 30 10:22:23 repanalitica.covinoc.local postgres[44814]:
[1-1] 2023-08-30 10:22:23.573 -05 [44814] FATAL: could not access file "pg_stat_statements": No such file or directory
Aug 30 10:22:23 repanalitica.covinoc.local postmaster[44814]:
2023-08-30 10:22:23.573 -05 [44814] FATAL: could not access file "pg_stat_statements": No such file or directory
Aug 30 10:22:23 repanalitica.covinoc.local postmaster[44814]:
2023-08-30 10:22:23.574 -05 [44814] LOG: database system is shut down
Aug 30 10:22:23 repanalitica.covinoc.local systemd[1]:
postgresql.service: Main process exited, code=exited, status=1/FAILURE
Aug 30 10:22:23 repanalitica.covinoc.local systemd[1]:
postgresql.service: Failed with result 'exit-code'. La causa
Este error se debe a que no se ha instalado el paquete postgresql-contrib, el cual contiene extensiones adicionales como pg_stat_statements.
La solución
Para solucionar este inconveniente, instala el paquete postgresql-contrib:
[root@repanalitica 10]# yum install postgresql-contrib
Failed to set locale, defaulting to C.UTF-8
Last metadata expiration check: 0:46:46 ago on Wed Aug 30 09:38:56 2023.
Dependencies resolved.
============================================================================================================
Package Architecture Version Repository Size
============================================================================================================
Installing:
postgresql-contrib x86_64 10.23-1.module+el8.7.0+1118+c6c6f44a appstream 810 k
Installing dependencies:
uuid x86_64 1.6.2-43.el8 appstream 63 k
Transaction Summary
============================================================================================================
Install 2 Packages
Total download size: 873 k
Installed size: 2.7 M
Is this ok [y/N]: y
Downloading Packages:
(1/2): uuid-1.6.2-43.el8.x86_64.rpm 100 kB/s | 63 kB 00:00
(2/2): postgresql-contrib-10.23-1.module+el8.7.0+1118+c6c6f44a.x86_64.rpm 573 kB/s | 810 kB 00:01
------------------------------------------------------------------------------------------------------------
Total 477 kB/s | 873 kB 00:01
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : uuid-1.6.2-43.el8.x86_64 1/2
Running scriptlet: uuid-1.6.2-43.el8.x86_64 1/2
Installing : postgresql-contrib-10.23-1.module+el8.7.0+1118+c6c6f44a.x86_64 2/2
Running scriptlet: postgresql-contrib-10.23-1.module+el8.7.0+1118+c6c6f44a.x86_64 2/2
Verifying : postgresql-contrib-10.23-1.module+el8.7.0+1118+c6c6f44a.x86_64 1/2
Verifying : uuid-1.6.2-43.el8.x86_64 2/2
Installed:
postgresql-contrib-10.23-1.module+el8.7.0+1118+c6c6f44a.x86_64 uuid-1.6.2-43.el8.x86_64
Complete! Iniciar el servicio
Luego de la instalación, procede a iniciar el motor de PostgreSQL:
[root@repanalitica 10]# systemctl start postgresql.service
[root@repanalitica 10]# ¡Y listo! Problema resuelto.
💡 ¿Qué es pg_stat_statements?
pg_stat_statements es una extensión que rastrea estadísticas de ejecución de todas las sentencias SQL ejecutadas en el servidor. Es extremadamente útil para:
- Identificar consultas lentas
- Analizar el rendimiento de la base de datos
- Optimizar queries problemáticas
- Monitoreo y troubleshooting