当你安装postgresql使用apt-get,它运行initdb并自动创建一个main集群。通常,默认数据目录位置在/var/lib/postgresql/<version>/<cluster>/. .
在自定义目录中安装 PostgreSQL 有三种方法。选项1和2并不理想。
-
安装为默认值
/var/lib/postgresql/<version>/<cluster>然后把它搬到别的地方。更新数据目录的位置/etc/postgresql/<version>/<cluster>/postgresql.conf. .这并不理想,因为PostgreSQL确保数据目录只能通过postgres创建群集时 linux user。您可以通过自己移动数据目录来错误配置权限。 -
运行
initdb然而,除非您手动擦除目录,否则这是不可能的。initdb命令会抱怨已经有一个集群main位于/var/lib/postgresql/<version>/<cluster>. .
正确的方式
解决这个问题的正确方法是防止PostgreSQL运行initdb直到您准备好创建一个群集。
- 在一个新的系统(没有PostgreSQL)上,安装
postgresql-common包第一。请勿安装postgresql还没有。
sudo apt install postgresql-common
- 编辑
/etc/postgresql-common/createcluster.conf并配置自定义数据目录如下:
# Default values for pg_createcluster(8)
# Occurrences of '%v' are replaced by the major version number,
# and '%c' by the cluster name. Use '%%' for a literal '%'.
# Create a "main" cluster when a new postgresql-x.y server package is installed
create_main_cluster = true
# Default start.conf value, must be one of "auto", "manual", and "disabled".
# See pg_createcluster(8) for more documentation.
#start_conf = 'auto'
# Default data directory.
data_directory = '/my/awesome/location/postgresql/%v/%c'
- 安装 PostgreSQL:
sudo apt install postgresql
你应该全部设置。将创建新的数据库文件/my/awesome/localtion/. .
不相关,但确保为密码创建密码postgressuperuser 如下:
sudo -u postgres psql postgres
psql (14.5 (Debian 14.5-1.pgdg110+1))
Type "help" for help.
postgres=# \password
Enter new password for user "postgres":
结局。
2151

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



