I’ve installed postgres on manjaro, then I’ve created the user wiki with password wiki.
❯ sudo -iu postgres
[postgres@arch-desktop ~]$ createuser -P wiki
[postgres@arch-desktop ~]$ psql
postgres=# \du
Role name
wiki
And when I try to run this program I get the error
thread 'main' panicked at 'Connection Error: error returned from database: database "wiki" does not exist', src/main.rs:53:9
// Change this according to your database implementation,
// or supply it as an environment variable.
// the database URL string follows the following format:
// "protocol://username:password@host:port/database"
const DATABASE_URL: &str = "postgres://wiki:wiki@localhost:5432";
it shouldn’t be using wiki
as the database name.
In the tutorial, why is it creating the database after it’s already connected to it? Shouldn’t it check if the database exists and create it only if it doesn’t?
If I create the database manually with
[postgres@arch-desktop ~]$ createdb media_wiki_db
postgres=# ALTER DATABASE media_wiki_db OWNER TO wiki;
and use this instead
const DATABASE_URL: &str = "postgres://wiki:wiki@localhost:5432/media_wiki_db";
I get the error
thread 'main' panicked at 'Execution Error: error returned from database: cannot drop the currently open database', src/main.rs:53:9
thread ‘main’ panicked at ‘Execution Error: error returned from database: permission denied to create database’, src/main.rs:53:9
If I use the postgres database
const DATABASE_URL: &str = "postgres://wiki:wiki@localhost:5432/postgres";
I get
thread 'main' panicked at 'Execution Error: error returned from database: permission denied to create database', src/main.rs:53:9
Probably missing CREATEDB
permission
❯ sudo -iu postgres
[postgres@arch-desktop ~]$ createdb test
postgres=# ALTER USER wiki CREATEDB;
postgres=# ALTER DATABASE test OWNER TO wiki;
postgres=# \l
\q
Ctrl+D
Changed to const DATABASE_URL: &str = "postgres://wiki:wiki@localhost:5432/test";
❯ cargo run
thread 'main' panicked at 'Connection Error: error returned from database: database "test/media_wiki_db" does not exist', src/main.rs:53:9
What am I doing wrong? How do I connect to the database? Actually what I would like to do is drop the database, recreate it and connect. At least for now.