接 “【PostgreSQL】- 1.1 在 Debian 12 上安装 PostgreSQL 15”,在本小节我们进行初始化。
创建集群
初始化与创建集群
切换用户为 postgres
~# sudo -i -u postgres
~$ mkdir /opt/pgdata/mydatabase
~$ pg_createcluster --datadir=/opt/pgdata/mydatabase 15 mydatabase
Creating new PostgreSQL cluster 15/mydatabase ...
/usr/lib/postgresql/15/bin/initdb -D /opt/pgdata/mydatabase --auth-local peer --auth-host scram-sha-256 --no-instructions
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
The database cluster will be initialized with locale "C".
The default database encoding has accordingly been set to "SQL_ASCII".
The default text search configuration will be set to "english".
Data page checksums are disabled.
fixing permissions on existing directory /opt/pgdata/mydatabase ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Asia/Shanghai
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok
Warning: systemd does not know about the new cluster yet. Operations like "service postgresql start" will not handle it. To fix, run:
sudo systemctl daemon-reload
Ver Cluster Port Status Owner Data directory Log file
15 mydatabase 5432 down postgres /opt/pgdata/mydatabase /var/log/postgresql/postgresql-15-mydatabase.log
在这里创建的 mydatabase 是一个 PostgreSQL 集群,它包含了运行一个特定版本的 PostgreSQL 所需的所有数据文件、配置文件和事务日志。命令中:
-
--datadir=/opt/pgdata/mydatabase指定了新集群的数据目录位置。 -
15是 Post

本文详细介绍了如何在Debian12上安装PostgreSQL15,包括创建集群、初始化过程、切换用户、设置权限、创建新用户、配置pg_hba.conf以控制访问,以及防火墙规则的配置。
最低0.47元/天 解锁文章
1074

被折叠的 条评论
为什么被折叠?



