A) 挂载了具有所需所有权和权限的 Virtualbox 目录:
ls -l /var:
drwx------. 1 postgres postgres 4096 Aug 20 12:43 pgshared
(和 /var/pgshared/data 目录已经创建了完全相同的权限)
B) 将 PGDATA 环境变量从默认更改为该数据目录
C) initdb 失败并出现以下错误:
fixing permissions on existing directory /var/pgshared/data ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Europe/Brussels
creating configuration files ... ok
running bootstrap script ... 2021-08-20 12:16:08.088 CEST [2807] LOG: could not link file "pg_wal/xlogtemp.2807" to "pg_wal/000000010000000000000001": Operation not permitted
2021-08-20 12:16:08.090 CEST [2807] FATAL: could not open file "pg_wal/000000010000000000000001": No such file or directory
child process exited with exit code 1
initdb: removing contents of data directory "/var/pgshared/data"
附加评论:
使用 -D 选项具有相同的结果(无论 PGDATA 环境变量如何)