为什么 postgres 不创建数据库?

编程入门 行业动态 更新时间:2024-10-26 11:24:50
本文介绍了为什么 postgres 不创建数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在 minikube 上部署一个简单的 postgres 容器时遇到问题.它不会创建postgres"挂载持久卷时的数据库:

I have problems in deploying a simple postgres container on minikube. It doesn't create "postgres" database when a persistent volume is mounted:

kubectl exec -it POSTGRES_POD -- sh / $ su postgres / $ psql psql: FATAL: database "postgres" does not exist

这是我的 postgres 部署:

Here is my postgres deployment:

resource "kubernetes_deployment" "backend_postgres" { metadata { ... } spec { replicas = 1 ... template { metadata { ... } spec { volume { name = "data" persistent_volume_claim { claim_name = kubernetes_persistent_volume_claim.data.metadata[0].name } } container { name = "postgres" image = "postgres:10-alpine" port { container_port = 5432 } env { name = "POSTGRES_PASSWORD" value_from { secret_key_ref { name = kubernetes_secret.postgres_password.metadata[0].name key = "password" } } } volume_mount { name = "data" mount_path = "/var/lib/postgresql/data" sub_path = "postgres" } } } } } }

持久卷成功挂载并且 postgres 成功写入 /var/lib/postgresql/data 但正如我之前提到的,它不会创建postgres".数据库.

The persistent volume successfully gets mounted and postgres successfully writes to /var/lib/postgresql/data but as I mentioned earlier, it doesn't create "postgres" database.

但是当我不挂载持久卷时,一切正常.

But when I don't mount a persistent volume, everything works fine.

这是我没有安装任何持久卷的部署:

Here is my deployment without mounting any persistent volume:

resource "kubernetes_deployment" "backend_postgres" { metadata { ... } spec { replicas = 1 ... template { metadata { ... } spec { container { name = "postgres" image = "postgres:10-alpine" port { container_port = 5432 } env { name = "POSTGRES_PASSWORD" value_from { secret_key_ref { name = kubernetes_secret.postgres_password.metadata[0].name key = "password" } } } } } } } }

我几天来都在处理这个奇怪的场景.

I'm working on this strange scenario for days.

我在 minikube 上运行 kubernetes 集群.任何形式的帮助或建议将不胜感激.

I'm runing the kubernetes cluster on minikube. Any kind of help or suggestion would be really appreciated.

推荐答案

由于它使用的是持久卷,因此大概不会每次都重新创建数据库实例,而是重新使用已经存在的实例.不知何故,已经存在的那个并没有按照您希望的方式进行配置.

Since it is using a persistent volume, it presumably won't be recreating the database instance each time, but rather re-using the one that already exists. And somehow, the one that already exists isn't configured the way you want it to be.

在确保数据库没有在任何地方运行后,您可以将它全部移到其他地方(因为您可能会发现您实际上需要它来做某事),将持久目录留空.然后再试一次,看看它是否创建了一个合适的数据库实例,并带有预期的postgres".数据库.

After making sure that the database is not running anywhere, you could move it all someplace else (because you may discover you actually need it for something) leaving the persistent directory empty. Then try again and see if it creates a suitable database instance complete with the expected "postgres" database.

更多推荐

为什么 postgres 不创建数据库?

本文发布于:2023-10-15 11:58:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1494275.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据库   postgres

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!