¿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?

Author: ROMANIA_engineer, 2009-04-06

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 directorio data, y que el usuario de postgres puede escribir en él.
 397
Author: Jarret Hardie,
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

  1. #log_directory = 'pg_log' to log_directory = 'pg_log'

  2. #log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log' to log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'

  3. #log_statement = 'none' to log_statement = 'all'

  4. #logging_collector = off to logging_collector = on

  5. Opcional: SELECT set_config('log_statement', 'all', true);

  6. sudo /etc/init.d/postgresql restart o sudo service postgresql restart

  7. Consulta de fuego en postgresql select 2+2

  8. 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]]}

 69
Author: vijay,
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.

 34
Author: Rix Beck,
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
 26
Author: Latif Premani,
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:

Reporte de errores y Registro - log_statement

 24
Author: Chad Birch,
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'
 19
Author: Shekhar,
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';

Ref: https://serverfault.com/a/376888 / log_statement

 15
Author: A T,
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 :

  1. Establecer (descomentar) log_statement = 'all' y log_min_error_statement = error en /var/lib/pgsql/9.2/data/postgresql.conf.
  2. 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/.
  3. Encuentra el inicio de sesión de hoy /var/lib/pgsql/9.2/data/pg_log/
 9
Author: Zoltá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-12-09 09:33:30