提示:本人长期接收外包任务。
本文详细介绍应用源码进行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
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
[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/
以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...”,则表示初始化成功。
将postgresql.conf文件中的配置项修改为listen_addresses='*',若主机有多张网卡,也可将其修改为指定网卡的IP。
[postgres@localhost bin]$ vim /export/servers/data/pgsql/postgresql.conf
在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@localhost pgsql]# psql
postgres=#alter user postgres with password 'postgres';
ALTER ROLE
postgres=#exit
[postgres@localhost pgsql]$ psql
Password for user postgres: # 输入修改的密码:这里是postgres
输入正确密码后命令窗如下所示:
至此,pgsql数据库安装完毕。在上图中的postgres=#处即可执行SQL语句。
银河麒麟系统安装程序比较繁琐,潜在问题比较多,个人建议均通过源码自定义编译安装。
国产系统还需努力啊!