¿Cómo registrar consultas PostgreSQL?
¿Cómo habilitar el registro de todos los SQL ejecutados por PostgreSQL 8.3?
Editado (más información) He cambiado estas líneas :
log_directory = 'pg_log'
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'
log_statement = 'all'
Y reinicie el servicio PostgreSQL... pero no se creó ningún registro... Estoy usando Windows Server 2003.
¿Alguna idea?
8 answers
En su archivo data/postgresql.conf
, cambie la configuración log_statement
a 'all'
.
Editar
Mirando su nueva información, diría que puede haber algunas otras configuraciones para verificar:
- asegúrese de haber activado la variable
log_destination
- asegúrese de encender el
logging_collector
- también asegúrese de que el directorio
pg_log
ya existe dentro del directoriodata
, y que el usuario de postgres puede escribir en él.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-11-17 19:20:32
Edite su /etc/postgresql/9.3/main/postgresql.conf
y cambie las líneas de la siguiente manera.
Nota: Si no encontró el archivo postgresql.conf
, simplemente escriba $locate postgresql.conf
en una terminal
#log_directory = 'pg_log'
tolog_directory = 'pg_log'
#log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'
tolog_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'
#log_statement = 'none'
tolog_statement = 'all'
#logging_collector = off
tologging_collector = on
Opcional:
SELECT set_config('log_statement', 'all', true);
sudo /etc/init.d/postgresql restart
osudo service postgresql restart
Consulta de fuego en postgresql
select 2+2
Buscar inicio de sesión actual
/var/lib/pgsql/9.2/data/pg_log/
Los archivos de registro tienden a crecer mucho con el tiempo, y podrían matar a su máquina. Por su seguridad, escriba un script bash que eliminará los registros y reiniciará el servidor postgresql.
Gracias @ paul, @Jarret Hardie, @Zoltán, @Rix Beck, @Latif Premani{[17]]}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-01-27 13:02:26
SELECT set_config('log_statement', 'all', true);
Con un derecho de usuario correspondiente puede utilizar la consulta anterior después de conectar. Esto afectará el registro hasta que finalice la sesión.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-05-16 14:18:59
También necesita agregar estas líneas en PostgreSQL y reiniciar el servidor:
log_directory = 'pg_log'
log_filename = 'postgresql-dateformat.log'
log_statement = 'all'
logging_collector = on
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-07-11 20:00:06
Establece log_statement
a all
:
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2009-04-06 16:37:33
+1 a las respuestas anteriores. Utilizo la siguiente configuración
log_line_prefix = '%t %c %u ' # time sessionid user
log_statement = 'all'
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-04-08 09:53:12
Para su información: Las otras soluciones solo registrarán sentencias de la base de datos predeterminada-generalmente postgres
-para registrar otras; comience con su solución; luego:
ALTER DATABASE your_database_name
SET log_statement = 'all';
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-08-08 08:45:54
Solo para tener más detalles para CentOS 6.4 (Red Hat 4.4.7-3) ejecutando PostgreSQL 9.2, basado en las instrucciones que se encuentran en esta página web :
- Establecer (descomentar)
log_statement = 'all'
ylog_min_error_statement = error
en/var/lib/pgsql/9.2/data/postgresql.conf
. - Vuelva a cargar la configuración de PostgreSQL. Para mí, esto se hizo corriendo
/usr/pgsql-9.2/bin/pg_ctl reload -D /var/lib/pgsql/9.2/data/
. - Encuentra el inicio de sesión de hoy
/var/lib/pgsql/9.2/data/pg_log/
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-12-09 09:33:30