Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DB initialization fails #1

Closed
xpmatteo opened this issue Jan 29, 2023 · 5 comments
Closed

DB initialization fails #1

xpmatteo opened this issue Jan 29, 2023 · 5 comments

Comments

@xpmatteo
Copy link

Hi Esko,

I've been trying all afternoon to get the DB init script to run with docker, but I always get

psql:/docker-entrypoint-initdb.d/create-tables.sql: error: could not read from input file: Is a directory

I tried in multiple ways -- don't know what's wrong. It's probably due to the fact that I'm not running Docker Desktop, but I'm using a replacement with Colima

@xpmatteo
Copy link
Author

No matter what I try (use absolute path; add type: bind; use "docker run" without compose) I always get a directory created and not a file

@luontola
Copy link
Owner

Does the file src/create-tables.sql exist?

➜  tdd-mooc-untestable-code git:(main) cat src/create-tables.sql 
create table users
(
    user_id       integer primary key,
    password_hash varchar(100) not null
);

What command gives that error? This is how the logs should look normally:

➜  tdd-mooc-untestable-code git:(main) docker compose up
[+] Running 2/2
 ⠿ Network tdd-mooc-untestable-code_default  Created                                                                                                 0.2s
 ⠿ Container tdd-mooc-untestable-code-db-1   Created                                                                                                 0.2s
Attaching to tdd-mooc-untestable-code-db-1
tdd-mooc-untestable-code-db-1  | The files belonging to this database system will be owned by user "postgres".
tdd-mooc-untestable-code-db-1  | This user must also own the server process.
tdd-mooc-untestable-code-db-1  | 
tdd-mooc-untestable-code-db-1  | The database cluster will be initialized with locale "en_US.utf8".
tdd-mooc-untestable-code-db-1  | The default database encoding has accordingly been set to "UTF8".
tdd-mooc-untestable-code-db-1  | The default text search configuration will be set to "english".
tdd-mooc-untestable-code-db-1  | 
tdd-mooc-untestable-code-db-1  | Data page checksums are disabled.
tdd-mooc-untestable-code-db-1  | 
tdd-mooc-untestable-code-db-1  | fixing permissions on existing directory /var/lib/postgresql/data ... ok
tdd-mooc-untestable-code-db-1  | creating subdirectories ... ok
tdd-mooc-untestable-code-db-1  | selecting dynamic shared memory implementation ... posix
tdd-mooc-untestable-code-db-1  | selecting default max_connections ... 100
tdd-mooc-untestable-code-db-1  | selecting default shared_buffers ... 128MB
tdd-mooc-untestable-code-db-1  | selecting default time zone ... Etc/UTC
tdd-mooc-untestable-code-db-1  | creating configuration files ... ok
tdd-mooc-untestable-code-db-1  | running bootstrap script ... ok
tdd-mooc-untestable-code-db-1  | performing post-bootstrap initialization ... ok
tdd-mooc-untestable-code-db-1  | syncing data to disk ... ok
tdd-mooc-untestable-code-db-1  | 
tdd-mooc-untestable-code-db-1  | initdb: warning: enabling "trust" authentication for local connections
tdd-mooc-untestable-code-db-1  | You can change this by editing pg_hba.conf or using the option -A, or
tdd-mooc-untestable-code-db-1  | --auth-local and --auth-host, the next time you run initdb.
tdd-mooc-untestable-code-db-1  | 
tdd-mooc-untestable-code-db-1  | Success. You can now start the database server using:
tdd-mooc-untestable-code-db-1  | 
tdd-mooc-untestable-code-db-1  |     pg_ctl -D /var/lib/postgresql/data -l logfile start
tdd-mooc-untestable-code-db-1  | 
tdd-mooc-untestable-code-db-1  | waiting for server to start....2023-01-31 13:59:27.673 UTC [47] LOG:  starting PostgreSQL 13.3 (Debian 13.3-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
tdd-mooc-untestable-code-db-1  | 2023-01-31 13:59:27.675 UTC [47] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
tdd-mooc-untestable-code-db-1  | 2023-01-31 13:59:27.688 UTC [48] LOG:  database system was shut down at 2023-01-31 13:59:27 UTC
tdd-mooc-untestable-code-db-1  | 2023-01-31 13:59:27.693 UTC [47] LOG:  database system is ready to accept connections
tdd-mooc-untestable-code-db-1  |  done
tdd-mooc-untestable-code-db-1  | server started
tdd-mooc-untestable-code-db-1  | CREATE DATABASE
tdd-mooc-untestable-code-db-1  | 
tdd-mooc-untestable-code-db-1  | 
tdd-mooc-untestable-code-db-1  | /usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/create-tables.sql
tdd-mooc-untestable-code-db-1  | CREATE TABLE
tdd-mooc-untestable-code-db-1  | 
tdd-mooc-untestable-code-db-1  | 
tdd-mooc-untestable-code-db-1  | 2023-01-31 13:59:28.271 UTC [47] LOG:  received fast shutdown request
tdd-mooc-untestable-code-db-1  | waiting for server to shut down....2023-01-31 13:59:28.272 UTC [47] LOG:  aborting any active transactions
tdd-mooc-untestable-code-db-1  | 2023-01-31 13:59:28.274 UTC [47] LOG:  background worker "logical replication launcher" (PID 54) exited with exit code 1
tdd-mooc-untestable-code-db-1  | 2023-01-31 13:59:28.274 UTC [49] LOG:  shutting down
tdd-mooc-untestable-code-db-1  | 2023-01-31 13:59:28.293 UTC [47] LOG:  database system is shut down
tdd-mooc-untestable-code-db-1  |  done
tdd-mooc-untestable-code-db-1  | server stopped
tdd-mooc-untestable-code-db-1  | 
tdd-mooc-untestable-code-db-1  | PostgreSQL init process complete; ready for start up.
tdd-mooc-untestable-code-db-1  | 
tdd-mooc-untestable-code-db-1  | 2023-01-31 13:59:28.391 UTC [1] LOG:  starting PostgreSQL 13.3 (Debian 13.3-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
tdd-mooc-untestable-code-db-1  | 2023-01-31 13:59:28.392 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
tdd-mooc-untestable-code-db-1  | 2023-01-31 13:59:28.392 UTC [1] LOG:  listening on IPv6 address "::", port 5432
tdd-mooc-untestable-code-db-1  | 2023-01-31 13:59:28.395 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
tdd-mooc-untestable-code-db-1  | 2023-01-31 13:59:28.399 UTC [84] LOG:  database system was shut down at 2023-01-31 13:59:28 UTC
tdd-mooc-untestable-code-db-1  | 2023-01-31 13:59:28.404 UTC [1] LOG:  database system is ready to accept connections

@xpmatteo
Copy link
Author

Yes, the create_tables.sql file exists

Then what happens is

tdd-mooc-untestable-code-db-1  | 2023-01-31 15:35:03.097 UTC [49] LOG:  database system is ready to accept connections
tdd-mooc-untestable-code-db-1  |  done
tdd-mooc-untestable-code-db-1  | server started
tdd-mooc-untestable-code-db-1  | CREATE DATABASE
tdd-mooc-untestable-code-db-1  |
tdd-mooc-untestable-code-db-1  |
tdd-mooc-untestable-code-db-1  | /usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/create-tables.sql
tdd-mooc-untestable-code-db-1  | psql:/docker-entrypoint-initdb.d/create-tables.sql: error: could not read from input file: Is a directory
tdd-mooc-untestable-code-db-1 exited with code 1

I am sure it's not a problem with your repo it's a problem with my setup. I'm suggesting that you might want to use these pair of commands instead of docker compose for any student that has the same problem as me:

docker run --name untestable-code --rm -p 5432:5432 -e POSTGRES_USER=untestable -e POSTGRES_PASSWORD=secret postgres:13
docker exec -i untestable-code psql --user untestable < src/create-tables.sql

Thanks for the exercise, I went through it with a colleague and it was an interesting learning for both

@luontola
Copy link
Owner

This sounds like this Colima issue: abiosoft/colima#102

@xpmatteo
Copy link
Author

xpmatteo commented Feb 1, 2023

Yes I'm sure it's a Colima issue, perhaps different from the one you point out. I'm not persistent enough to chase the problem, I'm happy with the workaround above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants