银河麒麟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语句。

总结

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

国产系统还需努力啊!

相关推荐
时序数据说6 分钟前
时序数据库Apache IoTDB核心技术深度解析
大数据·数据库·开源·apache·时序数据库·iotdb
时序数据说11 分钟前
时序数据库IoTDB在工业物联网时序数据管理中的应用
大数据·数据库·分布式·物联网·时序数据库·iotdb
DarkChunk1 小时前
[LevelDB]关于LevelDB存储架构到底怎么设计的?
数据库
martian6651 小时前
达梦数据库中无效触发器的排查与解决方案指南
开发语言·数据库
网硕互联的小客服1 小时前
RAID 阵列有哪些?分别有什么作用?
运维·服务器·网络·数据库·网络安全·raid
noravinsc3 小时前
django filter 统计数量 按属性去重
数据库·django·sqlite
Estar.Lee9 小时前
MySQL中外键约束详解 外键在表关系维护中的作用
运维·数据库·mysql·api·免费api
灯琰19 小时前
五款MySQL 可视化客户端软件
数据库·mysql
两袖清风9989 小时前
【MySQL】三大范式
数据库·mysql
Wooden-Flute11 小时前
八、数据库恢复技术
服务器·数据库·oracle