0

PostgreSQL 9.4.11

Ubuntu 16.04

For learning porpuses I'd like to log all the SQL commands.

What I'm trying is based on this How to log PostgreSQL queries?

So, I did:

1. #log_directory = 'pg_log' to log_directory = '/home/michael/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. sudo service postgresql restart

Then I do: 1. sudo su postgres 2. psql

And get this error:

postgres@hp:/etc/postgresql/9.4/main$ psql
psql: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

If I return the postgresql.conf back to the initial statement and restart postgresql, psql runs without any errors.

Could you help me understand why it is like that and how to cope with this problem?

Community
  • 1
  • 1
Michael
  • 4,273
  • 3
  • 40
  • 69
  • do you have folder `pg_log` in `michael`? What you should do first is just remove the `#` and there should be a folder `pg_log` in your postgres instalation. – Juan Carlos Oropeza Feb 24 '17 at 15:41
  • No, I don't. I'll try. One moment. As for pg_log. I tried it. But I couldn't find my log files. So, I decided to change it to my home directory. – Michael Feb 24 '17 at 15:43
  • Well, just adding a directory 'pg_log ' to my home directory didn't help. But returning to log_directory = 'pg_log' helps. And I have found my log file. But now I can't understand why my config did not work? It's just an absolute path to a directory. Usually programs can create a directory if it doesn't exist. And I even created one myself. So, what is the problem? – Michael Feb 24 '17 at 15:58
  • Im a windows person. But you can't assume because you change a text a file a directory would be created. And even when you create the folder you need to give proper permisions. – Juan Carlos Oropeza Feb 24 '17 at 15:59
  • Thank you very much. If you organize anything looking like an answer, I'd gladly accept it. – Michael Feb 24 '17 at 16:06

1 Answers1

0

The lines with the # in the config file mean are a comment.

If you want activate that option, just remove the # to use the default option.

If you want use a different folder, make sure that exist and have proper permission.

Juan Carlos Oropeza
  • 47,252
  • 12
  • 78
  • 118