Skip to content

Commit

Permalink
Allow logging to /dev/stderr
Browse files Browse the repository at this point in the history
For easier debugging, it should be pretty easy to switch daemon to log into the /dev/stderr.
This adds such a feature by setting POSTGRESQL_LOG_DESTINATION environment variable to /dev/stderr.
Requested at #353
  • Loading branch information
hhorak authored and phracek committed Oct 3, 2023
1 parent 49349bd commit f7205f4
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 10 deletions.
2 changes: 1 addition & 1 deletion 10/root/usr/share/container-scripts/postgresql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Sets how much memory is dedicated to PostgreSQL to use for caching data
Set to an estimate of how much memory is available for disk caching by the operating system and within the database itself

**`POSTGRESQL_LOG_DESTINATION (default: /var/lib/pgsql/data/userdata/log/postgresql-*.log)`**
Where to log errors, the default is `/var/lib/pgsql/data/userdata/log/postgresql-*.log` and this file is rotated; it can be changed to `/dev/stderr` to make debugging easier
Where to log errors, the default is `/var/lib/pgsql/data/userdata/log/postgresql-*.log` and this file is rotated; it can be changed to `/dev/stderr` to make debugging easier

The following environment variables deal with extensions. They are all optional, and if not set, no extensions will be enabled.

Expand Down
2 changes: 1 addition & 1 deletion 12/root/usr/share/container-scripts/postgresql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Sets how much memory is dedicated to PostgreSQL to use for caching data
Set to an estimate of how much memory is available for disk caching by the operating system and within the database itself

**`POSTGRESQL_LOG_DESTINATION (default: /var/lib/pgsql/data/userdata/log/postgresql-*.log)`**
Where to log errors, the default is `/var/lib/pgsql/data/userdata/log/postgresql-*.log` and this file is rotated; it can be changed to `/dev/stderr` to make debugging easier
Where to log errors, the default is `/var/lib/pgsql/data/userdata/log/postgresql-*.log` and this file is rotated; it can be changed to `/dev/stderr` to make debugging easier

The following environment variables deal with extensions. They are all optional, and if not set, no extensions will be enabled.

Expand Down
2 changes: 1 addition & 1 deletion 13/root/usr/share/container-scripts/postgresql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Sets how much memory is dedicated to PostgreSQL to use for caching data
Set to an estimate of how much memory is available for disk caching by the operating system and within the database itself

**`POSTGRESQL_LOG_DESTINATION (default: /var/lib/pgsql/data/userdata/log/postgresql-*.log)`**
Where to log errors, the default is `/var/lib/pgsql/data/userdata/log/postgresql-*.log` and this file is rotated; it can be changed to `/dev/stderr` to make debugging easier
Where to log errors, the default is `/var/lib/pgsql/data/userdata/log/postgresql-*.log` and this file is rotated; it can be changed to `/dev/stderr` to make debugging easier

The following environment variables deal with extensions. They are all optional, and if not set, no extensions will be enabled.

Expand Down
2 changes: 1 addition & 1 deletion 15/root/usr/share/container-scripts/postgresql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Sets how much memory is dedicated to PostgreSQL to use for caching data
Set to an estimate of how much memory is available for disk caching by the operating system and within the database itself

**`POSTGRESQL_LOG_DESTINATION (default: /var/lib/pgsql/data/userdata/log/postgresql-*.log)`**
Where to log errors, the default is `/var/lib/pgsql/data/userdata/log/postgresql-*.log` and this file is rotated; it can be changed to `/dev/stderr` to make debugging easier
Where to log errors, the default is `/var/lib/pgsql/data/userdata/log/postgresql-*.log` and this file is rotated; it can be changed to `/dev/stderr` to make debugging easier

The following environment variables deal with extensions. They are all optional, and if not set, no extensions will be enabled.

Expand Down
2 changes: 1 addition & 1 deletion src/root/usr/share/container-scripts/postgresql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Sets how much memory is dedicated to PostgreSQL to use for caching data
Set to an estimate of how much memory is available for disk caching by the operating system and within the database itself

**`POSTGRESQL_LOG_DESTINATION (default: /var/lib/pgsql/data/userdata/log/postgresql-*.log)`**
Where to log errors, the default is `/var/lib/pgsql/data/userdata/log/postgresql-*.log` and this file is rotated; it can be changed to `/dev/stderr` to make debugging easier
Where to log errors, the default is `/var/lib/pgsql/data/userdata/log/postgresql-*.log` and this file is rotated; it can be changed to `/dev/stderr` to make debugging easier

The following environment variables deal with extensions. They are all optional, and if not set, no extensions will be enabled.

Expand Down
42 changes: 37 additions & 5 deletions test/run_test
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,8 @@ run_s2i_enable_ssl_test
run_upgrade_test
run_migration_test
run_pgaudit_test
<<<<<<< HEAD
run_logging_test
||||||| parent of bcc9062 (Add support for extensions loading and creation.)
=======
run_new_pgaudit_test
>>>>>>> bcc9062 (Add support for extensions loading and creation.)
run_logging_test
"

test $# -eq 1 -a "${1-}" == --list && echo "$TEST_LIST" && exit 0
Expand Down Expand Up @@ -997,6 +993,42 @@ run_new_pgaudit_test() {
run_pgaudit_test
}

run_logging_test()
{
local data_dir name=pg-test-logging

# create a dir for data
create_volume_dir
data_dir="${volume_dir}"

DOCKER_ARGS="
-e POSTGRESQL_ADMIN_PASSWORD=password
-e POSTGRESQL_LOG_DESTINATION=/dev/stderr
-v ${data_dir}:/var/lib/pgsql/data:Z
" create_container "$name"

assert_runtime_option "$name" log_destination logging_collector log_directory log_filename
wait_ready "$name"

# enable the pgaudit extension
echo 'psql -U nonexistent' | docker exec -i $(get_cid "$name") bash || :

# give server some time for write all audit messages
sleep 1

# check whether we have a correct output in the container log
if ! docker logs $(get_cid "$name") 2>&1 | grep -q 'FATAL: role "nonexistent" does not exist' ; then
echo "ERROR: the container log does not include expected error message"
return 1
fi

# the traditional log file should not exist
while f in "${data_dir}"/userdata/log/postgresql-*.log ] ; do
echo "ERROR: the traditional log file $f should not exist"
return 1
done
}

# configuration defaults
POSTGRESQL_MAX_CONNECTIONS=100
POSTGRESQL_MAX_PREPARED_TRANSACTIONS=0
Expand Down

0 comments on commit f7205f4

Please sign in to comment.