146

I would like to take a look at the PostgreSQL log files to see what my app writes to them but I can't find them.

Any ideas?

Mikko Ohtamaa
  • 82,057
  • 50
  • 264
  • 435
acorello
  • 4,473
  • 4
  • 31
  • 46

10 Answers10

239

On OSX Homebrew installation the log can be found at:

Latest Homebrew:

/opt/homebrew/var/log/postgres.log

or older:

/usr/local/var/log/postgres.log 

or for older version of postgres (< 9.6)

/usr/local/var/postgres/server.log

Bonus - check if PostgreSQL is running using Homebrew:

brew services info --all
Mikko Ohtamaa
  • 82,057
  • 50
  • 264
  • 435
  • 2
    I had to uncomment some logging related lines in `/usr/local/var/postgres/postgresql.conf` – raine Sep 09 '18 at 15:18
  • 2
    if you have a specific version installed via homebrew, the path might be different, e.g. `/opt/homebrew/var/log/postgresql@14.log` – jaynetics Mar 03 '23 at 15:12
74

Just ask your database:

SELECT 
    * 
FROM 
    pg_settings 
WHERE 
    category IN( 'Reporting and Logging / Where to Log' , 'File Locations')
ORDER BY 
    category,
    name;

In my case, it's in "/Library/PostgreSQL/8.4/data/pg_log"

Frank Heikens
  • 117,544
  • 24
  • 142
  • 135
51

The plist used to launch your Postgres on boot may also set the logfile:

$ dir ~/Library/LaunchAgents
org.postgresql.postgres.plist

$ cat ~/Library/LaunchAgents/org.postgresql.postgres.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  [...]
  <key>StandardErrorPath</key>
  <string>/usr/local/var/postgres/server.log</string>
</dict>
</plist>

So in this case, /usr/local/var/postgres/server.log.

lambshaanxy
  • 22,552
  • 10
  • 68
  • 92
35

On OS X, if you're using the EnterpriseDB installation of PostgreSQL, your log files will be in /Library/PostgreSQL/8.4/data/pg_log

Of course, you'll want to substitute 8.4 for whichever version number you're running.

18

For Apple M1(Big Sur / Monterey) users who installed postgres using homebrew the location is -

/opt/homebrew/var/log/postgres.log
Ravi Kumar Gupta
  • 1,698
  • 2
  • 22
  • 38
9

If you are using Postgres.app, you can find the Data Directory location in the Preferences dialog box. In that directory, the log is at postgres-server.log.

For example, on my machine, the log is at /Users/nofinator/Library/Application Support/Postgres/var-9.4/postgres-server.log.

nofinator
  • 2,906
  • 21
  • 25
2

I have different Postgresql versions installed on my mac (with macports), and all the logs can be found here

/opt/local/var/log/postgresql84/postgres.log
/opt/local/var/log/postgresql91/postgres.log
/opt/local/var/log/postgresql92/postgres.log
plang
  • 5,446
  • 3
  • 25
  • 36
0

Postgresapp 9.3.5.1 and later keep a server log. The log is inside the data directory, named postgres-server.log.

Martin Sommer
  • 536
  • 5
  • 14
0

And for users of macports, expect something like /opt/local/var/log/postgresql11 (assuming you are running postgresql 11) after upgrading to Big Sur.

JL Peyret
  • 10,917
  • 2
  • 54
  • 73
0

Postgres 13

All logs are arranged per in the order of dates in postgres version 13. The correct folder to find it is :

sudo ls /Library/PostgreSQL/13/data/log

Here you can see all the logs file that were created to select any one log file use

sudo vim /Library/PostgreSQL/13/data/log/postgresql-2021-08-20_051906.log

Vaibs007
  • 29
  • 4