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

总结

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

国产系统还需努力啊!

相关推荐
鸠摩智首席音效师3 分钟前
MySQL ERROR 1114 (HY000): The table is full
数据库·mysql
数据大魔方7 分钟前
【期货量化实战】豆粕期货量化交易策略(Python完整代码)
开发语言·数据库·python·算法·github·程序员创富
Codeking__27 分钟前
Redis的value类型介绍——zset
数据库·redis·缓存
muddjsv29 分钟前
SQLite3 核心命令全解析 (从入门到精通)
数据库
難釋懷33 分钟前
认识NoSQL
数据库·nosql
亿坊电商36 分钟前
利于SEO优化的CMS系统都有哪些特点?
前端·数据库
阿阿阿安36 分钟前
MySQL(一)数据库风险操作场景总结
数据库·mysql
心丑姑娘1 小时前
使用ClickHouse时的劣质SQL样例
数据库·sql·clickhouse
什么都不会的Tristan1 小时前
redis篇
数据库·redis·缓存
only°夏至besos1 小时前
MySQL 运维实战:常见问题排查与解决方案
运维·数据库·mysql