gpt4 book ai didi

postgresql - "postgres"数据库在 PostgreSQL 中是否始终可用?

转载 作者:行者123 更新时间:2023-11-29 11:43:11 24 4
gpt4 key购买 nike

我正在编写一个脚本,它需要获取 postgres 集群中的所有数据库,因此它需要连接到一个数据库(无论哪个数据库)来执行此操作。

是否可以假设“postgres”数据库始终可以连接到,或者如果不能,是否有一种编程方式来确定集群中我可以连接到的任意数据库?

最佳答案

PostgreSQL 有三个“系统”数据库:postgres、template0 和template1。我很确定所有这些都可以删除。 (您可能想在虚拟机中对此进行测试。)我确定特权用户可以删除 postgres 和 template1。默认情况下,template0 不接受连接。

话虽如此,“postgres”的主要目的是给你a database to connect to .

The postgres database is also created when a database cluster is initialized. This database is meant as a default database for users and applications to connect to. It is simply a copy of template1 and can be dropped and recreated if necessary.

所以这是一个合理的假设,但不是万无一失的假设。我可以想象一些偏执(谨慎)的商店可能会放弃“postgres”并使用不同的数据库作为他们的内部默认数据库,以防他们的服务器受到威胁。这有点像为 SSH 使用非默认端口。

关于postgresql - "postgres"数据库在 PostgreSQL 中是否始终可用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27731111/

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