阅读量:1
以下是一份CentOS下PostgreSQL的使用教程:
安装
- 添加官方仓库:
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-$(rpm -E %{rhel})-x86_64/pgdg-redhat-repo-latest.noarch.rpm。 - 禁用系统自带模块(可选):
sudo dnf -qy module disable postgresql。 - 安装PostgreSQL:
sudo yum install -y postgresql16-server postgresql16(以16版本为例)。 - 初始化数据库:
sudo /usr/pgsql-16/bin/postgresql-16-setup initdb。 - 启动服务并设置开机自启:
sudo systemctl start postgresql-16,sudo systemctl enable postgresql-16。
配置
- 若需远程访问,编辑
/var/lib/pgsql/16/data/postgresql.conf,将listen_addresses设为'*'。 - 编辑
/var/lib/pgsql/16/data/pg_hba.conf,添加host all all 0.0.0.0/0 md5以允许所有IP用MD5认证访问。 - 重启服务使配置生效:
sudo systemctl restart postgresql-16。
创建用户和数据库
- 切换到postgres用户:
sudo -i -u postgres。 - 创建数据库:
createdb your_database_name。 - 创建用户:
CREATE USER your_username WITH PASSWORD 'your_password'。 - 授权:
GRANT ALL PRIVILEGES ON DATABASE your_database_name TO your_username。
连接数据库
本地连接:psql -U postgres;远程连接:psql -U your_username -d your_database -h your_host -p your_port。
以上就是关于“centos postgresql使用教程”的相关介绍,筋斗云是国内较早的云主机应用的服务商,拥有10余年行业经验,提供丰富的云服务器、租用服务器等相关产品服务。云服务器资源弹性伸缩,主机vCPU、内存性能强悍、超高I/O速度、故障秒级恢复;电子化备案,提交快速,专业团队7×24小时服务支持!
简单好用、高性价比云服务器租用链接:https://www.jindouyun.cn/product/cvm