养生
postgresql下载(银河麒麟V10SP3通过源码安装postgresql18安装过程-避坑记录)

一、服务器环境

服务器系统:银河麒麟V10 x86版本

[root@lc-paas-007 ~]# uname -aLinux lc-paas-007 4.19.90-24.4.v2101.ky10.x86_64 #1 SMP Mon May 24 12:14:55 CST 2021 x86_64 x86_64 x86_64 GNU/Linux


官方下载地址:https://www.kylinos.cn/support/trial/download/

数据库系统:Postgresql18

源码官方地址:https://www.postgresql.org/ftp/source/

官方文档地址:https://www.postgresql.org/docs/18/installation.html


二、安装步骤

2.1 下载源码安装包

# 下载源码curl -O https://ftp.postgresql.org/pub/source/v18.1/postgresql-18.1.tar.gz# 解压缩tar -zxvf ./postgresql-18.1.tar.gz# 进入文件夹cd ./postgresql-18.1

2.2 安装必要的工具

yum install -y gcc gcc-c++ icu libicu-devel zlib-devel readline-devel

2.3创建postgres用户

# 创建用户组groupadd postgres# 往用户组中添加用户useradd -g postgres postgres

2.4 编译安装

#创建安装目录mkdir -p /u01/postgresql # 配置 安装时 指定安装目录./configure  --prefix=/u01/postgresql # 编译make # 安装make install

2.5 修改目录权限

#修改安装目录权限chown -R postgres:postgres /u01/postgres

2.6切换postgres用户 并创建初始数据库

#切换用户[root@lc-paas-007 postgresql]# su postgresbash-5.0$ pwd/u01/postgresql#创建初始数据库bash-5.0$ /u01/postgresql/bin/initdb /u01/postgresql/dataThe files belonging to this database system will be owned by user "postgres".This user must also own the server process. The database cluster will be initialized with locale "zh_CN.UTF-8".The default database encoding has accordingly been set to "UTF8".initdb: could not find suitable text search configuration for locale "zh_CN.UTF-8"The default text search configuration will be set to "simple". Data page checksums are enabled. fixing permissions on existing directory /u01/postgresql/data ... okcreating subdirectories ... okselecting dynamic shared memory implementation ... posixselecting default "max_connections" ... 100selecting default "shared_buffers" ... 128MBselecting default time zone ... Asia/Shanghaicreating configuration files ... okrunning bootstrap script ... okperforming post-bootstrap initialization ... oksyncing data to disk ... ok initdb: warning: enabling "trust" authentication for local connectionsinitdb: hint: You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb. Success. You can now start the database server using:     /u01/postgresql/bin/pg_ctl -D /u01/postgresql/data -l logfile start bash-5.0$  /u01/postgresql/bin/pg_ctl -D /u01/postgresql/data -l logfile startwaiting for server to start.... doneserver started#数据库初始化成功 设置日志文件bash-5.0$  /u01/postgresql/bin/pg_ctl -D /u01/postgresql/data -l logfile statuspg_ctl: server is running (PID: 387369)/u01/postgresql/bin/postgres "-D" "/u01/postgresql/data"#停止数据库bash-5.0$ /u01/postgresql/bin/pg_ctl -D /u01/postgresql/data -l /u01/postgresql/shutdown.log stop -m fast

三、配置pg开机自启

3.1 创建/etc/systemd/system/postgresql.service文件

#切换回root用户#创建文件 postgresql.service [root@lc-paas-007 ~]# vim /etc/systemd/system/postgresql.service[Unit]Description=PostgreSQL database serverdocumentation=man:postgres(1)After=network.target [Service]Type=forkingUser=postgresGroup=postgresExecStart=/u01/postgresql/bin/pg_ctl -D /u01/postgresql/data -l /u01/postgresql/startup.log startExecStop=/u01/postgresql/bin/pg_ctl -D /u01/postgresql/data -l /u01/postgresql/shutdown.log stop -m fastExecReload=/u01/postgresql/bin/pg_ctl -D /u01/postgresql/data reloadPIDFile=/u01/postgresql/data/postmaster.pid [Install]WantedBy=multi-user.target

3.2设置开机启动

[root@lc-paas-007 postgresql]# systemctl enable postgresqlCreated symlink /etc/systemd/system/multi-user.target.wants/postgresql.service → /etc/systemd/system/postgresql.service.[root@lc-paas-007 postgresql]# systemctl start postgresql[root@lc-paas-007 postgresql]# systemctl status postgresql● postgresql.service - PostgreSQL database server   Loaded: loaded (/etc/systemd/system/postgresql.service; enabled; vendor preset: disabled)   Active: active (running) since Tue 2025-12-30 10:35:59 CST; 5s ago     Docs: man:postgres(1)  Process: 387880 ExecStart=/u01/postgresql/bin/pg_ctl -D /u01/postgresql/data -l /u01/postgresql/startup.log start (code=exited, status=0/SUCCESS) Main PID: 387882 (postgres)    Tasks: 9   Memory: 17.6M   CGroup: /system.slice/postgresql.service           ├─387882 /u01/postgresql/bin/postgres -D /u01/postgresql/data           ├─387883 postgres: io worker 1           ├─387884 postgres: io worker 0           ├─387885 postgres: io worker 2           ├─387886 postgres: checkpointer           ├─387887 postgres: background writer           ├─387889 postgres: walwriter           ├─387890 postgres: autovacuum launcher           └─387891 postgres: logical replication launcher 12月 30 10:35:59 lc-paas-007 systemd[1]: Starting PostgreSQL database server...12月 30 10:35:59 lc-paas-007 systemd[1]: Started PostgreSQL database server.

3.3 配置环境变量 修改postgres初始密码

修改 /etc/profile文件

vi /etc/profile export PG_HOME=/u01/postgresqlexport PATH=$JAVA_HOME/bin:$PG_HOME/bin:$PATH  #修改完成后保存 #让环境变量立即生效source /etc/profile

切换postgres用户修改密码:

#切换postgres用户su postgres [postgres@lc-paas-007 bin]$ psql -U postgres -h localhost -p 5432 -d postgrespsql (18.1)Type "help" for help. #这里改成我的密码postgres=# alter user postgres with password 'mypg@12345'; ALTER ROLEpostgres=# commit;WARNING:  there is no transaction in progress postgres-# \q  exit;

修改端口和配置

[root@lc-paas-007 data]# ll总用量 68drwx------ 7 postgres postgres    63 12月 30 11:05 basedrwx------ 2 postgres postgres  4096 12月 30 11:07 globaldrwx------ 2 postgres postgres     6 12月 30 10:24 pg_commit_tsdrwx------ 2 postgres postgres     6 12月 30 10:24 pg_dynshmem-rw------- 1 postgres postgres  5790 12月 30 10:42 pg_hba.conf-rw------- 1 postgres postgres  2681 12月 30 10:24 pg_ident.confdrwx------ 4 postgres postgres    68 12月 30 11:15 pg_logicaldrwx------ 4 postgres postgres    36 12月 30 10:24 pg_multixactdrwx------ 2 postgres postgres     6 12月 30 10:24 pg_notifydrwx------ 2 postgres postgres     6 12月 30 10:24 pg_replslotdrwx------ 2 postgres postgres     6 12月 30 10:24 pg_serialdrwx------ 2 postgres postgres     6 12月 30 10:24 pg_snapshotsdrwx------ 2 postgres postgres     6 12月 30 10:43 pg_statdrwx------ 2 postgres postgres     6 12月 30 10:24 pg_stat_tmpdrwx------ 2 postgres postgres    18 12月 30 10:24 pg_subtransdrwx------ 2 postgres postgres     6 12月 30 10:24 pg_tblspcdrwx------ 2 postgres postgres     6 12月 30 10:24 pg_twophase-rw------- 1 postgres postgres     3 12月 30 10:24 PG_VERSIONdrwx------ 4 postgres postgres  4096 12月 30 11:18 pg_waldrwx------ 2 postgres postgres    18 12月 30 10:24 pg_xact-rw------- 1 postgres postgres    88 12月 30 10:24 postgresql.auto.conf-rw------- 1 postgres postgres 32355 12月 30 10:43 postgresql.conf-rw------- 1 postgres postgres    57 12月 30 10:43 postmaster.opts-rw------- 1 postgres postgres    80 12月 30 10:43 postmaster.pid   #修改访问权限[root@lc-paas-007 data]# vi pg_hba.conf # "local" is for Unix domain socket connections onlylocal   all             all                                     trust# IPv4 local connections:host    all             all             127.0.0.1/32            trusthost    all             all             0.0.0.0/0               md5 # IPv6 local connections:host    all             all             ::1/128                 trust# Allow replication connections from localhost, by a user with the# replication privilege.local   replication     all                                     trusthost    replication     all             127.0.0.1/32            trusthost    replication     all             ::1/128                 trust   #修改端口 和连接数[root@lc-paas-007 data]# vi postgresql.conf  listen_addresses = '*'          # what IP address(es) to listen on;                                                     # comma-separated list of addresses;                                                     # defaults to 'localhost'; use '*' for all                                                    # (change requires restart)port = 5433                             # (change requires restart)max_connections = 500    # (change requires restart)

3.4 开放防火墙端口

firewall-cmd --state firewall-cmd --zone=public --add-port=5433/tcp --permanent firewall-cmd --reload firewall-cmd --list-all


至此,PostgreSQL 18 已在麒麟v10操作系统上成功通过源码编译安装,过程顺利,特此记录以备后续参考。


顶一下()     踩一下()

热门推荐

发表评论
0评