# How to log PostgreSQL queries?

If you would like to log all PostgreSQL queries into a file, you can do that by
changing few settings int the configuration file

Open the `data/postgresql.conf` file and change the following settings:

- `#log_directory = 'pg_log’` change to `log_directory = 'pg_log’`
- `#log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log’` change to
  `log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'`
- `#log_statement = 'none’` change to `log_statement = 'all’`
- `#logging_collector = off` change to `logging_collector = on`
- Run the following statement:

```sql
SELECT set_config('log_statement', 'all', true);
```

- Then restart the PostgreSQL server

```bash
sudo service postgresql restart
```

Now, you can find the logs in the following directory
`/var/lib/pgsql/9.2/data/pg_log/`
