gpt4 book ai didi

postgresql - docker 容器 : Relation X doesn't exist in database

转载 作者:行者123 更新时间:2023-12-05 06:30:20 26 4
gpt4 key购买 nike

我正在开发一个 java 应用程序,我使用 docker 创建了数据库 PostgreSQL 的镜像。

我有一个文件夹“docker-entrypoint-initdb.d”,其中包含用于创建表和数据的文件。

当我启动我的应用程序时,出现以下异常:

org.postgresql.util.PSQLException: ERROR: relation
"myerp.sequence_comptable" does not exist.

这里是docker-compose.yml的内容:

version: '2'
services:
myerp.db:
image: postgres:10
ports:
- "127.0.0.1:9032:5432"
volumes:
- "./init/db/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d"
environment:
- POSTGRES_DB=db_myerp
- POSTGRES_USER=usr_myerp
- POSTGRES_PASSWORD=myerp

当我启动命令 docker compose up 时:

Creating network "dev_default" with the default driver
Creating dev_myerp.db_1 ... done
Attaching to dev_myerp.db_1
myerp.db_1 | The files belonging to this database system will be owned by user "postgres".
myerp.db_1 | This user must also own the server process.
myerp.db_1 |
myerp.db_1 | The database cluster will be initialized with locale "en_US.utf8".
myerp.db_1 | The default database encoding has accordingly been set to "UTF8".
myerp.db_1 | The default text search configuration will be set to "English".
myerp.db_1 |
myerp.db_1 | Data page checksums are disabled.
myerp.db_1 |
myerp.db_1 | fixing permissions on existing directory /var/lib/postgresql/data ... ok
myerp.db_1 | creating subdirectories ... ok
myerp.db_1 | selecting default max_connections ... 100
myerp.db_1 | selecting default shared_buffers ... 128MB
myerp.db_1 | selecting dynamic shared memory implementation ... posix
myerp.db_1 | creating configuration files ... ok
myerp.db_1 | running bootstrap script ... ok
myerp.db_1 | performing post-bootstrap initialization ... ok
myerp.db_1 | syncing data to disk ... ok
myerp.db_1 |
myerp.db_1 | Success. You can now start the database server using:
myerp.db_1 |
myerp.db_1 | pg_ctl -D /var/lib/postgresql/data -l logfile start
myerp.db_1 |
myerp.db_1 |
myerp.db_1 | WARNING: enabling "trust" authentication for local connections
myerp.db_1 | You can change this by editing pg_hba.conf or using the option -A, or
myerp.db_1 | --auth-local and --auth-host, the next time you run initdb.
myerp.db_1 | waiting for server to start....2018-09-24 14:53:52.027 UTC [40] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
myerp.db_1 | 2018-09-24 14:53:52.061 UTC [41] LOG: database system was shut down at 2018-09-24 14:53:51 UTC
myerp.db_1 | 2018-09-24 14:53:52.069 UTC [40] LOG: database system is ready to accept connections
myerp.db_1 | done
myerp.db_1 | server started
myerp.db_1 | CREATE DATABASE
myerp.db_1 |
myerp.db_1 |
myerp.db_1 | /usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
myerp.db_1 |
myerp.db_1 | waiting for server to shut down....2018-09-24 14:53:52.541 UTC [40] LOG: received fast shutdown request
myerp.db_1 | 2018-09-24 14:53:52.552 UTC [40] LOG: aborting any active transactions
myerp.db_1 | 2018-09-24 14:53:52.555 UTC [40] LOG: worker process: logical replication launcher (PID 47) exited with exit code 1
myerp.db_1 | 2018-09-24 14:53:52.559 UTC [42] LOG: shutting down
myerp.db_1 | 2018-09-24 14:53:52.588 UTC [40] LOG: database system is shut down
myerp.db_1 | done
myerp.db_1 | server stopped
myerp.db_1 |
myerp.db_1 | PostgreSQL init process complete; ready for start up.
myerp.db_1 |
myerp.db_1 | 2018-09-24 14:53:52.657 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
myerp.db_1 | 2018-09-24 14:53:52.657 UTC [1] LOG: listening on IPv6 address "::", port 5432
myerp.db_1 | 2018-09-24 14:53:52.667 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
myerp.db_1 | 2018-09-24 14:53:52.696 UTC [58] LOG: database system was shut down at 2018-09-24 14:53:52 UTC
myerp.db_1 | 2018-09-24 14:53:52.705 UTC [1] LOG: database system is ready to accept connections
myerp.db_1 | 2018-09-24 14:57:16.551 UTC [68] ERROR: relation "myerp.sequence_ecriture_comptable" does not exist at character 46
myerp.db_1 | 2018-09-24 14:57:16.551 UTC [68] STATEMENT:
myerp.db_1 | SELECT derniere_valeur FROM myerp.sequence_ecriture_comptable
myerp.db_1 | WHERE annee = $1 AND journal_code = $2

你能帮帮我吗?

谢谢

最佳答案

我遇到了同样的错误:

psql:/docker-entrypoint-initdb.d/init2.sql:20: ERROR: relation "tablename" does not exist

可以通过在每个最开始添加下面一行来解决docker-entrypoint-initdb.d/* sql文件:

\c dbname;

关于postgresql - docker 容器 : Relation X doesn't exist in database,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52493874/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com