我正在使用postgres:14-高山图像在Docker上设置本地Postgres数据库,并在它上运行戈朗-迁移运行数据库迁移,在运行migrate工具后收到以下错误消息:
error: pq: role "root" does not exist我运行了以下命令:
$ docker run --name postgres14 -p 5432:5432 -e POSTGRES_USER=root -e POSTGRES_PASSWORD=pass -d postgres:14-alpine
$ docker exec -it postgres14 createdb --user=root --owner=root demodb
$ migrate -path db/migrations -database postgresql://root:pass@localhost:5432/demodb?sslmode=disable --verbose up这些命令也可以在这个Makefile中查看,完整的代码基可以在这个储存库中找到。
下面是Postgres容器中的日志:
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
The database cluster will be initialized with locale "en_US.utf8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
Data page checksums are disabled.
fixing permissions on existing directory /var/lib/postgresql/data ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... UTC
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok
Success. You can now start the database server using:
pg_ctl -D /var/lib/postgresql/data -l logfile start
waiting for server to start....2022-10-15 09:56:41.209 UTC [36] LOG: starting PostgreSQL 14.5 on x86_64-pc-linux-musl, compiled by gcc (Alpine 11.2.1_git20220219) 11.2.1 20220219, 64-bit
2022-10-15 09:56:41.211 UTC [36] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2022-10-15 09:56:41.217 UTC [37] LOG: database system was shut down at 2022-10-15 09:56:41 UTC
2022-10-15 09:56:41.220 UTC [36] LOG: database system is ready to accept connections
done
server started
CREATE DATABASE
/usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
waiting for server to shut down...2022-10-15 09:56:41.422 UTC [36] LOG: received fast shutdown request
.2022-10-15 09:56:41.423 UTC [36] LOG: aborting any active transactions
2022-10-15 09:56:41.423 UTC [36] LOG: background worker "logical replication launcher" (PID 43) exited with exit code 1
2022-10-15 09:56:41.424 UTC [38] LOG: shutting down
2022-10-15 09:56:41.434 UTC [36] LOG: database system is shut down
done
server stopped
PostgreSQL init process complete; ready for start up.为了正确配置root角色,我应该做些什么?
发布于 2022-10-15 15:10:44
原来安装在我的操作系统上的Postgres服务器使用的是同一个端口,这与在相同端口号下向容器数据库发出的请求发生了冲突。
这个问题可以通过对容器数据库使用不同的端口号,或者通过关闭操作系统上的数据库来解决。
发布于 2022-10-15 10:56:31
码头形象文档指定POSTGRES_USER环境变量默认为postgres,如果没有设置,请尝试使用该变量而不是root,或者删除容器,然后使用正确的环境变量再次构建它。
一旦您在psql shell中,您就可以用
CREATE USER username WITH PASSWORD 'your_password';然后授予用户对特定数据库的访问权限:
GRANT ALL PRIVILEGES ON DATABASE demodb TO username;完成后,您可以在make文件中的连接字符串中使用用户。
https://stackoverflow.com/questions/74078604
复制相似问题