为什么postgres不创建数据库?

编程入门 行业动态 更新时间:2024-10-26 13:35:14
本文介绍了为什么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:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1494274.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据库   postgres

发布评论

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

>www.elefans.com

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