Open karlhorky opened 1 week ago
In the PostgreSQL docs the default log destination should be stderr
log_destination (string) PostgreSQL supports several methods for logging server messages, including stderr and syslog. On Windows, eventlog is also supported. Set this parameter to a list of desired log destinations separated by commas. The default is to log to stderr only. This parameter can only be set in the postgresql.conf file or on the server command line.
Maybe there is a difference in the postgresql.conf
file that @Petzlc is using?
This also how my postgres server looks when I start it, but I think its since I did the new system setup the last time with postgres@16, never knew this was an issue
$ postgres
2024-07-09 13:17:25.766 CEST [17760] LOG: redirecting log output to logging collector process
2024-07-09 13:17:25.766 CEST [17760] HINT: Future log output will appear in directory "log".
I think we need to find a way to set this logging_collector
to off, That should be the solution to that, according to this
Mine is on
The log_destination
is already 'stderr' which should be the correct setting for this
The logging_collector is off by default so the PostgreSQL logs (which are sent to the server's standard error stream) are not handled by the logging collector process. This means that the destination of the logs depend on where the server's stderr stream is directed to.
The point is this : This means that the destination of the logs depend on where the server's stderr stream is directed to
Source https://betterstack.com/community/guides/logging/how-to-start-logging-with-postgresql/
Maybe it's something that Chocolatey sets?
But yeah, let's turn it off in the Windows setup at least (maybe also in the macOS setup / Linux setup if we can confirm that this is something we need)
This should be the command that does that. I have now a normal log messages, after running the below command
sed -i.bak "s/^logging_collector = on/logging_collector = off/" "$PGDATA/postgresql.conf"
Before
After
Error log now showing when there is anything
I think the behavior is constant in macOS, it logs errors to the console there
Error loging
I am not even sure if there is any terminal that shows where Postgres is running on Linux. At least its what I found out from Cornelia today.
Using this command, sudo -u postgres psql
moves to the psql
directly and does not show anywhere postgres is running
Some commands can be run to see where Postgres is running on Linux
pg_lsclusters
ps aux | grep postgres
But these show only the file path I think, it doesn't open a terminal for Postgres where errors can be logged
This should be the command that does that. I have now a normal log messages, after running the below command
sed -i.bak "s/^logging_collector = on/logging_collector = off/" "$PGDATA/postgresql.conf"
Sounds pretty good. Notes:
logging_collector = on
in it? $PGDATA
environment variable exists at the time we're going to run it?-i.bak
part)Using this command,
sudo -u postgres psql
moves to thepsql
directly and does not show anywhere postgres is running
This is not the command to start PostgreSQL on Linux though, this is running psql
as the postgres
user (-u
flag is the "user" flag)
What happens when we run this command with a file that doesn't have logging_collector = on in it?
I don't have an official docs to back this up, but when what sed
is looking for is not found, it just ignores the operation. There are some traces of if sed found something
that it continues the operation, but no mention of what happens when it doesn't find what it is looking for
https://www.gnu.org/software/sed/manual/sed.html#:~:text=If%20such%20line%20is%20found
Where should we add this to the Windows setup guide? Are we sure this file and the $PGDATA environment variable exists at the time we're going to run it?
We may need to add it to be run after the first environment variables have been set. I think at this stage, we can be certain that the $PGDATA
exists if the student has done the right thing
Is there any way to simplify or make the flag more explicit for this command (the -i.bak part)
Maybe I can remove this. I thought it was important that I add it so that backup of the config is created before the modification, but maybe we don't need it afterall
Ok yeah go ahead with a PR.
There was 1 unanswered question:
Are we sure this file ... exists at the time we're going to run it?
This point was also talking about the file, not only the $PGDATA
environment variable. If we're pretty sure that this file will exist, then that's a first part of the answer. 2nd part: what happens with the sed
command if this file doesn't exist?
My answer below @Eprince-hub I believe that the Postgres config file should already exist.
Some reference to the file and env variable existence
https://www.postgresql.org/docs/current/storage-file-layout.html
If it doesn't for whatever reason, then there will be an error output like the one below
@Petzlc reported today that PostgreSQL is misconfigured on his machine - the original message is in German:
The same message in English, for search keywords and discoverability:
Our System Setup guide should not lead to logs being saved somewhere else - they should be visible in the terminal where
postgres
is startedTurning the
logging_collector
off in thepostgres.conf
file will solve the issue