出于安全原因,在默认情况下,initdb创建的新集群只能由集群所有者访问。
allow-group-access选项允许与cluster初始化宿主属于同一组的任何用户读取集群中的文件。
这对于普通用户非常方便。
https://www.postgresql.org/docs/12/app-initdb.html
1.宿主用户postgres初始化并启动数据库
--使用postgres用户初始化,并指定--allow-group-access
$ initdb --allow-group-access -D /home/postgres/data5432 -Upostgres -W
--启动数据库
$ pg_ctl -D /home/postgres/data5432 start &
2.给普通用户jerome添加组postgres
# usermod -G postgres jerome
3.普通用户jerome查看数据库数据目录
$ id jerome
uid=1000(jerome) gid=1000(jerome) groups=1000(jerome),1001(postgres)
$ ll /home/postgres/data5432/
total 64
drwxr-x---. 5 postgres postgres 41 Feb 7 16:26 base
-rw-r-----. 1 postgres postgres 67 Feb 7 16:28 current_logfiles
drwxr-x---. 2 postgres postgres 4096 Feb 7 16:26 global
drwxr-x---. 2 postgres postgres 6 Feb 7 16:26 pg_commit_ts
drwxr-x---. 2 postgres postgres 6 Feb 7 16:26 pg_dynshmem
-rw-r-----. 1 postgres postgres 4513 Feb 7 16:26 pg_hba.conf
-rw-r-----. 1 postgres postgres 1636 Feb 7 16:26 pg_ident.conf
drwxr-x---. 2 postgres postgres 78 Feb 7 16:28 pg_log
drwxr-x---. 4 postgres postgres 68 Feb 7 16:33 pg_logical
drwxr-x---. 4 postgres postgres 36 Feb 7 16:26 pg_multixact
drwxr-x---. 2 postgres postgres 18 Feb 7 16:28 pg_notify
drwxr-x---. 2 postgres postgres 6 Feb 7 16:26 pg_replslot
drwxr-x---. 2 postgres postgres 6 Feb 7 16:26 pg_serial
drwxr-x---. 2 postgres postgres 6 Feb 7 16:26 pg_snapshots
drwxr-x---. 2 postgres postgres 6 Feb 7 16:26 pg_stat
drwxr-x---. 2 postgres postgres 25 Feb 7 16:34 pg_stat_tmp
drwxr-x---. 2 postgres postgres 18 Feb 7 16:26 pg_subtrans
drwxr-x---. 2 postgres postgres 6 Feb 7 16:26 pg_tblspc
drwxr-x---. 2 postgres postgres 6 Feb 7 16:26 pg_twophase
-rw-r-----. 1 postgres postgres 3 Feb 7 16:26 PG_VERSION
drwxr-x---. 3 postgres postgres 60 Feb 7 16:26 pg_wal
drwxr-x---. 2 postgres postgres 18 Feb 7 16:26 pg_xact
-rw-r-----. 1 postgres postgres 88 Feb 7 16:26 postgresql.auto.conf
-rw-r-----. 1 postgres postgres 27042 Feb 7 16:27 postgresql.conf
-rw-r-----. 1 postgres postgres 54 Feb 7 16:28 postmaster.opts
-rw-r-----. 1 postgres postgres 82 Feb 7 16:28 postmaster.pid
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




