#下载地址和选定的源码包 https://www.postgresql.org/download/ postgresql-14.0.tar.gz # 安装GCC编译器,需要GNU make 3.80 或更新版本 yum -y install gcc make --version
useradd -r postgres
tar -zxvf postgresql-14.0.tar.gz -C /data
cd /data/postgresql-14.0/ ./configure --prefix=/data/postgreSQL # 错误1-实际上是缺少readline-devel configure: error: readline library not found If you have readline already installed, see config.log for details on the failure. It is possible the compiler isn't looking in the proper directory. Use --without-readline to disable readline support. #错误2-查看依赖 yum search zlib configure: error: zlib library not found If you have zlib already installed, see config.log for details on the failure. It is possible the compiler isn't looking in the proper directory. Use --without-zlib to disable zlib support. # 解决-安装依赖 yum -y install -y readline-devel yum -y install -y zlib-devel
make # make all # make world # make make world-bin
make install # make install-docs # make install-world # make install-world-bin
mkdir -p /data/postgreSQL/pgsqlData chown postgres.postgres /data/postgreSQL/pgsqlData
su postgres # 初始化数据库 /data/postgreSQL/bin/initdb -D /data/postgreSQL/pgsqlData # 启动实例 /data/postgreSQL/bin/pg_ctl -D /data/postgreSQL/pgsqlData -l logfile start # 创建测试数据库 /data/postgreSQL/bin/createdb test # 登录 /data/postgreSQL/bin/psql test
ALTER USER postgres WITH PASSWORD '123456';
修改两个配置文件
# vi /data/postgreSQL/pgsqlData/pg_hba.conf host all all 0.0.0.0/0 md5 # vi /data/postgreSQL/pgsqlData/postgresql.conf listen_addresses = '*' # /data/postgreSQL/bin/pg_ctl -D /data/postgreSQL/pgsqlData reload
配置防火墙端口
firewall-cmd --add-port=5432/tcp --permanent firewall-cmd --reload
vi /usr/lib/systemd/system/postgresql.service
[Unit] Description=postgreSQL Server [Service] User=postgres Group=postgres Type=forking TimeoutSec=0 PermissionsStartOnly=true ExecStart=/data/postgreSQL/bin/pg_ctl -D /data/postgreSQL/pgsqlData start LimitNOFILE = 65535 Restart=on-failure RestartSec=3 RestartPreventExitStatus=1 PrivateTmp=false [Install] WantedBy=multi-user.target
加载配置和启动
systemctl daemon-reload systemctl start postgresql systemctl enable postgresql
pg_dump -h localhost -U postgres -p 5432 -d mydb -s -f /data/postgresql.backup /data/postgreSQL/bin/psql -h localhost -p 5432 -U mydb -W -d hl_pre < /data/tools/postgresql.backup