postgresql安装教程centos
时间: 2024-11-30 09:12:48 浏览: 5
Centos6.8安装Postgresql11数据库.docx
PostgreSQL是一种开源的关系型数据库管理系统,在CentOS上安装它,可以分为几个步骤:
1. **更新系统**:
```sh
sudo yum update -y
```
2. **安装依赖**:
对于RPM包安装,你需要安装一些基础的开发工具和软件包,例如:
```sh
sudo yum install -y curl-devel bzip2-devel libxml2-devel openssl-devel
```
3. **下载安装文件**:
```sh
curl https://get.postgresql.org/keys/PGPKEY_PGPASSWORD | sudo gpg --dearmor > /usr/share/keyrings/postgresql-archive-keyring.gpg
curl https://get.postgresql.org/versions/$(curl https://www.postgresql.org/ftp/source/pgdg-centos10-x86_64/pgdg-centos10-x86_64.txt).asc | sudo gpg --verify
wget https://get.postgresql.org/ports/$POSTGRES_MAJOR/redhat/RPMS/x86_64/pgdg-redhat-repo-latest.noarch.rpm -O pgdg-redhat-repo-latest.rpm
```
4. **添加存储库**:
```sh
sudo rpm -Uvh --replacepkgs pgdg-redhat-repo-latest.rpm
```
5. **安装PostgreSQL**:
```
sudo yum install -y postgresql14-14
sudo systemctl enable postgresql-14
```
7. **首次设置**:
首次运行会提示创建初始用户、数据库等,按照提示操作。
8. **验证安装**:
使用`psql`命令连接到新安装的PostgreSQL服务器,如:
```sh
sudo -u postgres psql
```
阅读全文