You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When mounting a custom .psqlrc configuration file with timing enabled, some SQL queries within the docker-entrypoint.sh do not return the expected values, as they are superseded by the timing strings. For instance, it breaks the script that creates the initial database from working correctly.
For more context, I prefer to mount my custom .psqlrc file for local development, to have my common functions and aliases always ready when I need them.
Proposed solution
From my local testing, it would be enough to add --no-psqlrc flag to the query_runner variable in the docker_process_sql function.
Minimal example
.psqlrc
\set QUIET 1
\timing on
\unset QUIET
docker-compose.yml
version: "3.7"services:
database:
build:
context: .environment:
POSTGRES_DB: samplePOSTGRES_PASSWORD: postgresports:
- 5432:5432volumes:
# Mount psql config file in the system configuration directory.
- ./.psqlrc:/etc/postgresql-common/psqlrc:ro
I also have a following Dockerfile:
FROM postgres
COPY docker-entrypoint.sh /usr/local/bin/
with custom docker-entrypoint.sh where I modified the function to print extra debug info:
docker_setup_db() {
local dbAlreadyExists
dbAlreadyExists="$( POSTGRES_DB= docker_process_sql --dbname postgres --set db="$POSTGRES_DB" --tuples-only <<-'EOSQL' SELECT 1 FROM pg_database WHERE datname = :'db' ; EOSQL )" echo "Exists: $dbAlreadyExists" if [ -z "$dbAlreadyExists" ]; then POSTGRES_DB= docker_process_sql --dbname postgres --set db="$POSTGRES_DB" <<-'EOSQL' CREATE DATABASE :"db" ;EOSQLechoelseecho"DB already exists"fi}
Log
Building and running the above code with docker compose up will yield following log:
database_1 | 2021-10-23 20:37:19.438 UTC [49] LOG: database system is ready to accept connections
database_1 | done
database_1 | server started
database_1 | Exists:
database_1 | Time: 2.633 ms
database_1 | DB already exists
The text was updated successfully, but these errors were encountered:
Bug Info
When mounting a custom .psqlrc configuration file with timing enabled, some SQL queries within the docker-entrypoint.sh do not return the expected values, as they are superseded by the timing strings. For instance, it breaks the script that creates the initial database from working correctly.
For more context, I prefer to mount my custom .psqlrc file for local development, to have my common functions and aliases always ready when I need them.
Proposed solution
From my local testing, it would be enough to add
--no-psqlrc
flag to thequery_runner
variable in thedocker_process_sql
function.Minimal example
.psqlrc
docker-compose.yml
I also have a following Dockerfile:
with custom docker-entrypoint.sh where I modified the function to print extra debug info:
Log
Building and running the above code with
docker compose up
will yield following log:The text was updated successfully, but these errors were encountered: