+3 votes
in Databases by (71.8k points)
For my project, I need to submit the log file that contains all the SQL queries I executed at the command line. How can I create the log file in Postgres on Ubuntu?

1 Answer

+1 vote
by (71.8k points)
selected by
Best answer

To create the log file in Postgresql installed on Ubuntu, you need to modify the postgresql.conf file of Postgresql server. Here are the steps...

  1. Open terminal (ALT+CTL+T) and type the following command - sudo gedit /etc/postgresql/9.5/main/postgresql.conf . If you have different version of Postgresql, change 9.5 to your version number. This command will open the conf file in gedit.
  2. In the postgresql.conf file, search for 'log_statement' and set the value to 'all' (log_statement = 'all'            # none, ddl, mod, all)
  3. Save and close the file.
  4. Restart the Postgresql server (sudo service postgresql restart OR /etc/init.d/postgresql-9.5 restart)
  5. Now the log file will have all the sql commands you type on the terminal. You can find the log file in folder /var/log/postgresql

Related questions