2. postgresql创建数据库实例

本文介绍了在Linux环境下创建PostgreSQL数据库实例的详细步骤,包括创建用户、数据目录,使用initdb或pg_ctl初始化数据目录,并强调了初始化过程中的权限设置和密码配置。同时,文章提醒读者避免使用yum源安装以获取更高的定制性。
部署运行你感兴趣的模型镜像

1. create user

yum安装,会自动创建postgres用户,但是,建议安装前,先创建用户

[root@pghost1 ~]$ groupadd -g 1000 postgres

[root@pghost1 ~]$ useradd -g 1000 -u 1000 postgres

[root@pghost1 ~]$ id postgres

uid=1000(postgres) gid=1000(postgres) groups=1000(postgres)

a) user can not root

b) 如果是部署集群,建议配置NTP服务,统一集群中每个节点的操作系统用户的uid和gid

 

2. create data directory

通常会建立形如/pgdata/9.x/xxx_data, xxx为业务线名

[root@pghost1 ~]$ mkdir -p /pgdata/10/{data,backups,scripts,archive_wals}

权限,initdb也会回收权限

[root@pghost1 ~]$ chown -R postgres.postgres /pgdata/10

[root@pghost1 ~]$ chmod 0700 /pgdata/10/data

 

3. initial data directory

实例化数据目录使用initdb工具。创建新的数据库目录(目录包括存放数据库数据的目录),创建template1和postgres数据库,初始化该数据库实例的默认区域和字符集编码。

-W参数,所以在初始化的过程中,要求为数据库超级用户创建密码

-bash-4.2$ /usr/pgsql-10/bin/initdb -D /pgdata/10/data -W

The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

Enter new superuser password: 
Enter it again: 

fixing permissions on existing directory /pgdata/10/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

    /usr/pgsql-10/bin/pg_ctl -D /pgdata/10/data -l logfile start

系统自动创建了template1数据库和postgres数据库,

template1是生成其他数据库的模板,

postgres数据库是一个默认数据库,用于给用户、工具或者第三方应用提供默认数据库。

输出的最后一行还告诉了你如何启动刚才初始化的数据库。

 

另外,

除了initdb,还可以用pg_ctl工具初始化

[postgres@pghost1 ~]$ /opt/pgsql/bin/pg_ctl init -D /pgdata/10/data -o 

至此,数据库目录初始化完成。

------------------------------------------------------------------------------------------------------

yum源安装PostgreSQL, 

自动创建/var/lib/pgsql/10目录和它的两个子目录:data目录和backups目录。

通过service postgresql-10 init命令会初始化/var/lib/pgsql/10/data目录作为数据目录。

方便,但定制性不好,不建议

您可能感兴趣的与本文相关的镜像

Stable-Diffusion-3.5

Stable-Diffusion-3.5

图片生成
Stable-Diffusion

Stable Diffusion 3.5 (SD 3.5) 是由 Stability AI 推出的新一代文本到图像生成模型,相比 3.0 版本,它提升了图像质量、运行速度和硬件效率

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值