postgres 11 单实例最大支持多少个database?

有人在pg8时代(10年前)问过,当时说10000个没问题,而且每个db会在/base下建立1个文件夹, 文件ext3只支持32000个子文件夹,所以这是上限了. 而现在早就ext4了,根本没有限制了.

然而....

实测了一下, 安装好postgis后, /base里有4个文件夹. 2个7.7M个文件夹 是默认postgres库, 2个18.4M的文件夹 是template_postgis库

每次用安装了postgis的模板数据库新建1个数据库,都会在/base下新建1个 18.4M文件夹

这倒没什么. 关键问题是

每个刚创建的空库,已经18MB了

也就是说, 1000个就18G了....

所以,postgres单实例支持多少个db是个伪问题,  瓶颈在于你的硬盘大小....233333

幸亏买了PostgreSQL 即学即用,  里面结合例子讲得很清楚,用schema.

再参考官网文档:https://www.postgresql.org/docs/11/ddl-schemas.html

There are several reasons why one might want to use schemas:

  • To allow many users to use one database without interfering with each other.

  • To organize database objects into logical groups to make them more manageable.

  • Third-party applications can be put into separate schemas so they do not collide with the names of other objects.

Schemas are analogous to directories at the operating system level, except that schemas cannot be nested.

可以进行逻辑分组, 这样不同schema里就可以有同名的对象了(比如表). 而且不同schema是隔离的.

类似操作系统里的文件夹,只是不能嵌套(要是schema能嵌套+ 能和db一样基于template复制,就更好了!)