Postgres create database 默认添加另一个模式和 public

Postgres create database is adding another schema along with public by default

Postgres 级别:
新手

场景
我正在阅读一些 Postgres 教程并玩弄 chinook database 我一定对 search_path 或用户 role 做了一些事情,因为现在每当我输入 CREATE DATABASE 我都会默认获得 2 个模式 publicchinook。不知道为什么。

步骤

psql> CREATE DATABASE foo;
psql> \c foo

psql (12.2, server 11.6)
You are now connected to database "foo" as user "username".

psql> \dn

  Name   |  Owner
---------+----------
 chinook | username
 public  | postgres

psql> \dt chinook.*

            List of relations
 Schema  |     Name      | Type  | Owner
---------+---------------+-------+-------
 chinook | album         | table | username
 chinook | artist        | table | username
 chinook | cars          | table | username
 chinook | color         | table | username
 chinook | commitlog     | table | username
 chinook | customer      | table | username
 chinook | employee      | table | username
 chinook | genre         | table | username
 chinook | invoice       | table | username
 chinook | invoiceline   | table | username
 chinook | mediatype     | table | username
 chinook | playlist      | table | username
 chinook | playlisttrack | table | username
 chinook | track         | table | username

问题
一个全新的数据库导致 chinook 架构及其所有表被添加,以及 'public 架构。

  1. 我想回到 CREATE DATABASE foo 仅使用 public 模式创建数据库的状态。我不想要 chinook 架构。

  2. 我是怎么变成这样的?

谢谢

您必须修改了 template1 数据库。来自 docs on templates:

CREATE DATABASE actually works by copying an existing database. By default, it copies the standard system database named template1. Thus that database is the “template” from which new databases are made. If you add objects to template1, these objects will be copied into subsequently created user databases.

您可以连接到该数据库并删除该架构:

$ psql -c "DROP SCHEMA chinook" template1

如果您现在创建一个新数据库,它不应再包含此架构。