阅读量:1
Postgresql-12.5 安装及配置
环境基于银河麒麟V10 服务器版本操作
此安装步骤Linux操作系统几乎通用
下载数据库安装包
链接:https://pan.baidu.com/s/1wt4Yjwv79W-fCd4tlMC4-w
提取码:0117
1.下载依赖
可以用系统自带的依赖库下载
yum install -y openssl openssl-devel pam pam-devel libxml2 libxml2-devel libxslt libxslt-devel perl perl-devel install perl-ExtUtils-Embed readline readline-devel zlib zlib-devel gettext gettext-devel bison flex gcc gcc-c++ readline-devel
我自己下载的有离线安装包
链接:https://pan.baidu.com/s/1krNqdXfK4qMbEQweXH2gMA
提取码:0117
2.读入数据
上传postgresql-12.5.tar.gz安装包,我的放在了/root/postgresql-12.5文件夹下解压
tar -zvxf postgresql-12.5.tar.gz
3.创建文件路径,并将解压后的文件复制到该路径下
上传postgresql-12.5.tar.gz安装包,我的放在了/root/postgresql-12.5文件夹下解压
[root@localhost ~]# mkdir -p /export/servers/app/postgresql-12.5
创建文件路径,并将解压后postgresql-12.5的文件复制到export/servers/app/postgresql-12.5 路径下
4.配置安装
上传postgresql-12.5.tar.gz安装包,我的放在了/root/postgresql-12.5文件夹下解压
[root@localhost postgresql-12.5]# ./configure --prefix=/export/servers/app/postgresql-12.5 &&make &&make install
报错的话按照报错去下载依赖文件,安装完成之后再次安装
提示:PostgreSQL installation complete.
表示安装完成
5.添加环境变量
[root@localhost postgresql-12.5]# vim /etc/profile
把光标拉至最下面然后按键 i 后将下面的复制到里面
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
操作完之后按EXC 输入:wq 保存并退出
#刷新并使文件生效
[root@localhost postgresql-12.5]# source /etc/profile
6.创建数据目录
[root@localhost postgresql-12.5]# useradd postgres [root@localhost postgresql-12.5]# mkdir -p /export/servers/data/pgsql/ [root@localhost postgresql-12.5]# chown postgres:postgres /export/servers/data/pgsql/ [root@localhost postgresql-12.5]# ll
7.初始化数据库
切换用户
[root@localhost postgresql-12.5]# su - postgres
进入相对路劲
[postgres@localhost postgresql-12.5]$ cd /export/servers/app/postgresql-12.5/bin
使用initdb启动
[postgres@localhost bin]$ /export/servers/app/postgresql-12.5/bin/initdb -D /export/servers/data/pgsql/
8.修改监听端口
[postgres@localhost bin]$ vim /export/servers/data/pgsql/postgresql.conf
找到对应的地方添加一条
# - Connection Settings- listen_addresses = '*'
9.启动pg_ctl
[postgres@localhost bin]$ /export/servers/app/postgresql-12.5/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.<br><br>
启动服务
[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
10.验证5432端口
[postgres@localhost bin]$ netstat -anp | grep 5432
11.登录并修改postgres密码
切换用户
[root@localhost pgsql]# su - postgres
登录数据库
[postgres@localhost pgsql]# psql
修改用户密码
postgres=# alter user postgres with password '输入修改的密码';
12.修改是否需要密码登录数据库
修改为md5表示用密码登录,如果为trust表示不需要密码
[postgres@localhost bin]$ cd /export/servers/data/pgsql/ [postgres@localhost bin]$ vim pg_hba.conf
修改配置文件后需要重启
[postgres@localhost pgsql]$ /export/servers/app/postgresql-12.5/bin/pg_ctl -D /export/servers/data/pgsql/ -l logfile restart
总结
以上就是postgresql的安装配置内容,我通过别的博主的帖子学习写的仅供学习,如有侵权请联系我删除
QQ:3356650288