银河麒麟V10-ARM架构-postgresql安装与部署指南

提示:本人长期接收外包任务。

前言

本文详细介绍应用源码进行pgsql的安装步骤,本文以postgresql-12.0为例。

一、下载并解压安装包

下载地址:https://ftp.postgresql.org/pub/source/

解压安装包,创建安装路径:

复制代码
[root@localhost ~]# tar -zvxf postgresql-12.0.tar.gz
[root@localhost ~]# mkdir -p /export/servers/app/postgresql-12.0 

二、配置并安装

进入解压文件,执行pgsql编译安装:

复制代码
[root@localhost ~]# cd postgresql-12.0
[root@localhost postgresql-12.0]# ./configure --prefix=/export/servers/app/postgresql-12.0 && make && make install  

如果命令窗中提示"PostgreSQL installation complete.",则表示安装成功。

如果出现"readline library"等相关错误,则需要进行依赖库安装 :

复制代码
[root@localhost postgresql-12.0]# sudo apt install libreadline-dev

三、添加环境变量

在系统环境变量文件中添加pgsql相关路径,并刷新配置。

复制代码
[root@localhost postgresql-12.0]#vim /etc/profile
c 复制代码
export PGHOME=/export/servers/app/postgresql-12.5
export PGDATA=/export/servers/data/pgsql/
export PATH=$PGHOME/bin:$PATH
export LANG=en_US.utf8
export LD_LIBRARY_PATH=$PGHOME/lib:$LD_LIBRARY_PATH
复制代码
 [root@localhost postgresql-12.0]#source /etc/profile

四、初始化数据库

1.创建用户和数据中心,并设置文件所有权。

复制代码
 [root@localhost postgresql-12.0]#useradd postgres
 [root@localhost postgresql-12.0]#mkdir -p /export/servers/data/pgsql/
 [root@localhost postgresql-12.0]#chown postgres:postgres /export/servers/data/pgsql/

2.初始化数据库

以postgres的身份进行数据库初始化:

复制代码
[root@localhost postgresql-12.0]#su - postgres  
[postgres@localhost bin]$/export/servers/app/postgresql-12.0/bin/initdb -D /export/servers/data/pgsql/

如果命令窗中提示"Success.You can now start the database server using...",则表示初始化成功。

五、数据库连接配置

1.修改监听地址

将postgresql.conf文件中的配置项修改为listen_addresses='*',若主机有多张网卡,也可将其修改为指定网卡的IP。

复制代码
[postgres@localhost bin]$ vim /export/servers/data/pgsql/postgresql.conf

2.允许远程连接

在pg_hba.conf文件末尾处添加一行"host all all 0.0.0.0/0 md5"。修改配置文件后需要重启服务。

复制代码
[postgres@localhost bin]$vim /export/servers/data/pgsql/pg_hba.conf
[postgres@localhost bin]$/export/servers/app/postgresql-12.0/bin/pg_ctl -D /export/servers/data/pgsql/ -l logfile restart

注意:最后一项如果设置为"md5",表示使用密码登录。如果为"trust",则表示无密码登录。

六、启动数据库服务

先后执行如下两条指令来启动数据库服务:

复制代码
[postgres@localhost bin]$/export/servers/app/postgresql-12/bin/pg_ctl -D /export/servers/data/pgsql/ -l logfile start
waiting for server to start..../bin/sh: logfile: Permission denied
stopped waiting
pg_ctl: could not start server
Examine the log output.

[postgres@localhost bin]$ pg_ctl start
waiting for server to start....2023-03-03 11:27:58.887 CST [41939] LOG: starting PostgreSQL 12.5 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 7.3.0, 64-bit
2023-03-03 11:27:58.888 CST [41939] LOG: listening on IPv4 address "0.0.0.0", port 5432
2023-03-03 11:27:58.888 CST [41939] LOG: listening on IPv6 address "::", port 5432
2023-03-03 11:27:58.890 CST [41939] LOG: listening on Unix socket "/tmp/.s.PGSQL.5432"
2023-03-03 11:27:58.908 CST [41940] LOG: database system was shut down at 2023-03-03 11:12:37 CST
2023-03-03 11:27:58.911 CST [41939] LOG: database system is ready to accept connections
done
server started

验证5432端口是否开启:

复制代码
[postgres@localhost bin]$netstat -anp | grep 5432

如下图所示,则表示成功开启。

七、登录并修改postgres密码

1.将postgres的密码修改为postgres。建议账号和密码设置为一致,方便记忆。

复制代码
[postgres@localhost pgsql]# psql  
postgres=#alter user postgres with password 'postgres';  
ALTER ROLE
postgres=#exit

2.验证密码是否修改成功

复制代码
[postgres@localhost pgsql]$ psql
Password for user postgres:        # 输入修改的密码:这里是postgres

输入正确密码后命令窗如下所示:

八、执行SQL语句

至此,pgsql数据库安装完毕。在上图中的postgres=#处即可执行SQL语句。

总结

银河麒麟系统安装程序比较繁琐,潜在问题比较多,个人建议均通过源码自定义编译安装。

国产系统还需努力啊!

相关推荐
IT策士5 小时前
Redis 从入门到精通:数据结构Set 与 Sorted
数据结构·数据库·redis
2401_873479405 小时前
如何用IP离线库检测DNS隧道和C2通信?企业DNS安全防护指南
网络·数据库·tcp/ip·安全·ip
填满你的记忆5 小时前
10万QPS下,Redis缓存如何避免雪崩?
数据库·redis·缓存
IT界的老黄牛5 小时前
MongoDB 主从切换排查实战:从 docker ps 到 jq,一套 SOP 定位死因
数据库·mongodb·docker
睡不醒男孩0308235 小时前
第四篇:数据库国产化与信创替代的守护者:基于CLup的异构数据库一站式运维平台构建
运维·数据库·金融·clup·中启乘数
Lumistory5 小时前
2026年城市照明工程4大核心痛点及解决方案
大数据·数据库
岳麓丹枫0015 小时前
PG数据库无法接受连接问题分析定位
数据库·postgresql
JdSnE27zv6 小时前
SQLite内存数据库
数据库·sql·sqlite
SelectDB技术团队6 小时前
预约发布会|核心产品力首发,如何构建面向 Agent 时代的企业级数据引擎
数据库·数据仓库·人工智能·数据分析·可观测·apache doris·selectdb
2601_961845156 小时前
2026四级作文预测题|英语四级写作押题+提纲PDF
java·c语言·数据库·c++·python·pdf·php