Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions runtime/functions
Original file line number Diff line number Diff line change
Expand Up @@ -318,13 +318,13 @@ load_extensions() {
psql -U ${PG_USER} -d ${database} -c "CREATE EXTENSION IF NOT EXISTS unaccent;" >/dev/null 2>&1
fi

IFS_ORG=$IFS
IFS_ORG2=$IFS
Copy link
Owner

@kkimurak kkimurak Jul 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about making IFS_ORG function-local? local is not standardized in POSIX, but since bash is specified in the shebang, I think we should not need to worry about shells that cannot use local, or shells that can use it but have differences in behavior.

Suggested change
IFS_ORG2=$IFS
local IFS_ORG=$IFS

This should be also applied to IFS_ORG in create_database().

I made sure that this change properly restore original IFS at the end of create_database(). Trace:

$ docker run --rm -e "DB_NAME=testdb,testdb2" -e "DB_USER=db_user" -e "DB_USER_IS_DB_OWNER=true" -e "DB_EXTENSION=btree_gist,pg_trgm" -e "DB_PASS=password" -e "DEBUG=true" kkimurak/sameersbn-postgresql:latest 
(---- omitted ----)
+ create_database
+ [[ -n testdb,testdb2 ]]
+ case $REPLICATION_MODE in
+ local 'IFS_ORG=
' <-- Here IFS_ORG contains newline
+ IFS=,
+ for database in ${DB_NAME}
+ echo 'Creating database: testdb...'
Creating database: testdb...
++ psql -U postgres -Atc 'SELECT 1 FROM pg_catalog.pg_database WHERE datname = '\''testdb'\'''
+ [[ -z '' ]]
+ psql -U postgres -c 'CREATE DATABASE "testdb" WITH TEMPLATE = "template1";'
+ load_extensions testdb
+ local database=testdb
+ [[ '' == true ]]
+ local IFS_ORG=,
+ IFS=,
(---- omitted ----)
‣ Setting db_user as an owner of database testdb2...
+ IFS='
+ IFS='
' <-- IFS restored to contain newline at the end of create_database()
+ create_replication_user
(---- omitted ----)
Starting PostgreSQL 16...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, this makes more sense :D
As said, it was already midnight and you can imagine it wasn't 10 minutes to debug this error from scratch.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again for taking time. Also, I've included this in the pull request sameersbn#175 I submitted to the upstream project (sameersbn@420ce73), so please let me know if you have any issues.

IFS=,
for extension in ${DB_EXTENSION}; do
echo "‣ Loading ${extension} extension..."
psql -U ${PG_USER} -d ${database} -c "CREATE EXTENSION IF NOT EXISTS ${extension};" >/dev/null 2>&1
done
IFS=$IFS_ORG
IFS=$IFS_ORG2
}

create_database() {
Expand Down