---
title: （可选）安装PostgreSQL
description: "将PostgreSQL数据库从x86架构的服务器迁移到鲲鹏服务器，需要确保x86服务器和鲲鹏服务器上都安装并运行PostgreSQL。如果已经存在PostgreSQL主从部署的环境，请跳过本章节。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengdbs/ecosystemEnable/PostgreSQL/kunpengdbs_ptgl_btps_0005.html
sourcePath: /source/zh/kunpengdbs/ecosystemEnable/PostgreSQL/kunpengdbs_ptgl_btps_0005.html
indexId: b2c9f08aa4cb6acfde3c713746263589d7daa6b587e4402b85fbeb8dbf90d17179
---
# （可选）安装PostgreSQL

将PostgreSQL数据库从x86架构的服务器迁移到鲲鹏服务器，需要确保x86服务器和鲲鹏服务器上都安装并运行PostgreSQL。如果已经存在PostgreSQL主从部署的环境，请跳过本章节。

- 在x86架构的服务器上安装PostgreSQL的操作步骤请参见PostgreSQL的官方文档《  PostgreSQL 13 安装指南(https://www.postgresql.org/docs/13/installation.html)
》或《  PostgreSQL 15 安装指南(https://www.postgresql.org/docs/15/installation.html)
》。
- 在鲲鹏服务器上安装PostgreSQL的操作步骤请参见本文档  安装PostgreSQL
。

#### 安装PostgreSQL

1. 安装依赖。

```
yum -y install gcc gcc-c++
yum -y install automake zlib  bzip2-libs readline bison ncurses gmp mpfr mpfr-devel libmpc
yum -y install zlib-devel bzip2 bzip2-devel  readline-devel libaio-devel ncurses-devel gmp-devel
```


2. 下载PostgreSQL源码。

```
mkdir -p /data/pg-13.2
cd /data/pg-13.2
wget https://ftp.postgresql.org/pub/source/v13.2/postgresql-13.2.tar.gz --no-check-certificate
tar -zxvf postgresql-13.2.tar.gz
cd /data/pg-13.2/postgresql-13.2
./configure -prefix=/usr/local/pgsql-13.2
```


3. 配置ARM架构相关的编译选项。
x86架构不需要执行当前操作步骤。


  a. 打开文件。

```
vi /data/pg-13.2/postgresql-13.2/src/Makefile.global
```


  b. 按“i”进入编辑模式，在文件中找到“CFLAGS”和“CXXFLAGS”并在后面添加以下编译选项。

```
-march=armv8-a+crc+lse
```


  c. 按“Esc”键，输入:wq!，按“Enter”保存并退出编辑。
4. 编译PostgreSQL。

```
make -j20
make -j20 install
```


  “-j20”参数充分利用多核CPU优势，加快编译速度，参数“-j”后数字为CPU核数，可用cat /proc/cpuinfo | grep processor | wc -l进行查看，此数值应小于等于CPU核数。

5. 验证安装。

  a. 查看安装目录，确认二进制文件编译安装成功。

```
ls /usr/local/pgsql-13.2
/usr/local/pgsql-13.2/bin/postgres --version
```


  b. 创建postgres用户和用户组，并创建data和archive目录。

```
groupadd postgres
useradd -g postgres postgres
mkdir -p /data/pg-13.2/data
chown -R postgres:postgres /data/pg-13.2/data
mkdir -p /data/pg-13.2/archive
chown -R postgres:postgres /data/pg-13.2/archive
```
