在CentOS上安装PostgreSQL的步骤如下:
更新系统包
sudo yum update -y
启用PostgreSQL官方仓库
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
安装PostgreSQL
sudo yum install -y postgresql13-server
初始化数据库
sudo postgresql-setup --initdb
启动PostgreSQL服务
sudo systemctl start postgresql
设置开机自启
sudo systemctl enable postgresql
创建数据库用户和数据库
sudo -u postgres psql
在psql命令行中:
CREATE USER your_username WITH PASSWORD 'your_password';
CREATE DATABASE your_database OWNER your_username;
GRANT ALL PRIVILEGES ON DATABASE your_database TO your_username;
\q
安装依赖包
sudo yum groupinstall -y "Development Tools"
sudo yum install -y readline-devel zlib-devel
下载PostgreSQL源码
wget https://ftp.postgresql.org/pub/source/v13.6/postgresql-13.6.tar.gz
tar -zxvf postgresql-13.6.tar.gz
cd postgresql-13.6
配置编译选项
./configure --prefix=/usr/local/pgsql --with-includes=/usr/include --with-libraries=/usr/lib64
编译并安装
make
sudo make install
初始化数据库
/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
启动PostgreSQL服务
/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data start
设置开机自启(可选) 可以创建一个systemd服务文件来实现开机自启。
无论使用哪种方法安装,都可以通过以下命令验证PostgreSQL是否安装成功:
psql --version
如果显示了PostgreSQL的版本信息,则表示安装成功。
postgresql.conf
和pg_hba.conf
。希望这些步骤能帮助你在CentOS上成功安装PostgreSQL!
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:在 CentOS 上安装 PGAdmin 后如何连接 PostgreSQL