LukeMathWalker / zero-to-production

Code for "Zero To Production In Rust", a book on API development using Rust.
https://www.zero2prod.com
Apache License 2.0
5.43k stars 470 forks source link

[3.8.4.2.2] No driver found for URL scheme "postgres" when creating database #232

Closed aichichang closed 7 months ago

aichichang commented 8 months ago

Hello!

I've followed the steps in the book, but trying to create the database with the script, I get an error saying there is no driver found for URL scheme "postgres"...

image

The docker container is created correctly and running but the logs seem to be a bit strange (it said it's shutting down at some point...)

2023-11-03 17:07:04 The files belonging to this database system will be owned by user "postgres".
2023-11-03 17:07:04 This user must also own the server process.
2023-11-03 17:07:04 
2023-11-03 17:07:04 The database cluster will be initialized with locale "en_US.utf8".
2023-11-03 17:07:04 The default database encoding has accordingly been set to "UTF8".
2023-11-03 17:07:04 The default text search configuration will be set to "english".
2023-11-03 17:07:04 
2023-11-03 17:07:04 Data page checksums are disabled.
2023-11-03 17:07:04 
2023-11-03 17:07:04 fixing permissions on existing directory /var/lib/postgresql/data ... ok
2023-11-03 17:07:04 creating subdirectories ... ok
2023-11-03 17:07:04 selecting dynamic shared memory implementation ... posix
2023-11-03 17:07:04 selecting default max_connections ... 100
2023-11-03 17:07:04 selecting default shared_buffers ... 128MB
2023-11-03 17:07:04 selecting default time zone ... Etc/UTC
2023-11-03 17:07:04 creating configuration files ... ok
2023-11-03 17:07:04 running bootstrap script ... ok
2023-11-03 17:07:04 performing post-bootstrap initialization ... ok
2023-11-03 17:07:04 syncing data to disk ... ok
2023-11-03 17:07:04 
2023-11-03 17:07:04 
2023-11-03 17:07:04 Success. You can now start the database server using:
2023-11-03 17:07:04 
2023-11-03 17:07:04     pg_ctl -D /var/lib/postgresql/data -l logfile start
2023-11-03 17:07:04 
2023-11-03 17:07:04 waiting for server to start....2023-11-03 17:07:04.907 UTC [48] LOG:  starting PostgreSQL 16.0 (Debian 16.0-1.pgdg120+1) on aarch64-unknown-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit
2023-11-03 17:07:04 2023-11-03 17:07:04.907 UTC [48] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2023-11-03 17:07:04 2023-11-03 17:07:04.910 UTC [51] LOG:  database system was shut down at 2023-11-03 17:07:04 UTC
2023-11-03 17:07:04 2023-11-03 17:07:04.914 UTC [48] LOG:  database system is ready to accept connections
2023-11-03 17:07:04  done
2023-11-03 17:07:04 server started
2023-11-03 17:07:05 CREATE DATABASE
2023-11-03 17:07:05 
2023-11-03 17:07:05 
2023-11-03 17:07:04 initdb: warning: enabling "trust" authentication for local connections
2023-11-03 17:07:04 initdb: hint: You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb.
2023-11-03 17:07:05 2023-11-03 17:07:05.192 UTC [1] LOG:  starting PostgreSQL 16.0 (Debian 16.0-1.pgdg120+1) on aarch64-unknown-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit
2023-11-03 17:07:05 2023-11-03 17:07:05.192 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2023-11-03 17:07:05 2023-11-03 17:07:05.192 UTC [1] LOG:  listening on IPv6 address "::", port 5432
2023-11-03 17:07:05 2023-11-03 17:07:05.194 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2023-11-03 17:07:05 2023-11-03 17:07:05.197 UTC [64] LOG:  database system was shut down at 2023-11-03 17:07:05 UTC
2023-11-03 17:07:05 2023-11-03 17:07:05.201 UTC [1] LOG:  database system is ready to accept connections
2023-11-03 17:12:05 2023-11-03 17:12:05.254 UTC [62] LOG:  checkpoint starting: time
2023-11-03 17:12:09 2023-11-03 17:12:09.577 UTC [62] LOG:  checkpoint complete: wrote 45 buffers (0.3%); 0 WAL file(s) added, 0 removed, 0 recycled; write=4.304 s, sync=0.006 s, total=4.324 s; sync files=12, longest=0.005 s, average=0.001 s; distance=261 kB, estimate=261 kB; lsn=0/1954488, redo lsn=0/1954450
2023-11-03 17:07:05 /usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
2023-11-03 17:07:05 
2023-11-03 17:07:05 waiting for server to shut down....2023-11-03 17:07:05.067 UTC [48] LOG:  received fast shutdown request
2023-11-03 17:07:05 2023-11-03 17:07:05.068 UTC [48] LOG:  aborting any active transactions
2023-11-03 17:07:05 2023-11-03 17:07:05.072 UTC [48] LOG:  background worker "logical replication launcher" (PID 54) exited with exit code 1
2023-11-03 17:07:05 2023-11-03 17:07:05.072 UTC [49] LOG:  shutting down
2023-11-03 17:07:05 2023-11-03 17:07:05.073 UTC [49] LOG:  checkpoint starting: shutdown immediate
2023-11-03 17:07:05 2023-11-03 17:07:05.100 UTC [49] LOG:  checkpoint complete: wrote 923 buffers (5.6%); 0 WAL file(s) added, 0 removed, 0 recycled; write=0.013 s, sync=0.014 s, total=0.028 s; sync files=301, longest=0.004 s, average=0.001 s; distance=4257 kB, estimate=4257 kB; lsn=0/1913050, redo lsn=0/1913050
2023-11-03 17:07:05 2023-11-03 17:07:05.108 UTC [48] LOG:  database system is shut down
2023-11-03 17:07:05  done
2023-11-03 17:07:05 server stopped
2023-11-03 17:07:05 
2023-11-03 17:07:05 PostgreSQL init process complete; ready for start up.

Checked my script with the Github example and they look the same. I might be missing something very obvious... not sure what can cause this error?

Thank you :)

LukeMathWalker commented 8 months ago

I'm not sure, to be honest 😅 Never seen this before.

bvmcode commented 7 months ago

I had the same issue on my mac, this command for install fixed it for me.

cargo install sqlx-cli --no-default-features --features native-tls,postgres

aichichang commented 7 months ago

Thank you both for getting back, will give this a go :) Going to close this now!