千家信息网

怎么在CentOS 7.4环境下源码编译安装postgreSQL 11.4

发表于:2025-11-07 作者:千家信息网编辑
千家信息网最后更新 2025年11月07日,本篇内容介绍了"怎么在CentOS 7.4环境下源码编译安装postgreSQL 11.4"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况
千家信息网最后更新 2025年11月07日怎么在CentOS 7.4环境下源码编译安装postgreSQL 11.4

本篇内容介绍了"怎么在CentOS 7.4环境下源码编译安装postgreSQL 11.4"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

1. 安装依赖包

yum install -y readline readline-devel openssl openssl-devel zlib zlib-devel

2. 下载软件

wget https://ftp.postgresql.org/pub/source/v11.4/postgresql-11.4.tar.gz

3. 解压并安装

tar -zvvf postgresql-11.4.tar.gz#进入解压后的文件夹cd postgresql-11.4./configure --prefix=/usr/local/pgsql  #指定默认安装路径make #编译make install #安装

4. 添加用户并更改权限

useradd postgres #添加用户passwd postgres #设置密码mkdir -p /data/pgsql/datamkdir -p /data/pgsql/logcd /data/pgsql/logtouch pgsql.logchown -R postgres:postgres /data/pgsql

5. 添加环境变量

vim /etc/profile

内容如下:

#postgresqlexport PGHOME=/data/pgsqlexport PGBASE=/usr/local/pgsqlexport PATH=$PATH:$PGBASE/bin

使之生效

source /etc/profile

6. 初始化数据

切换到postgres用户下 su - postgres

[postgres@localhost ~]$ cd /usr/local/pgsql/bin/[postgres@localhost bin]$ lsclusterdb   ecpg               pg_config       pg_isready      pg_rewind            pg_waldump  vacuumdbcreatedb    initdb             pg_controldata  pg_receivewal   pg_test_fsync        postgrescreateuser  pg_archivecleanup  pg_ctl          pg_recvlogical  pg_test_timing       postmasterdropdb      pg_basebackup      pg_dump         pg_resetwal     pg_upgrade           psqldropuser    pgbench            pg_dumpall      pg_restore      pg_verify_checksums  reindexdb
[postgres@localhost bin]$ ./initdb -D /data/pgsql/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 "en_US.UTF-8".The default database encoding has accordingly been set to "UTF8".The default text search configuration will be set to "english".Data page checksums are disabled.fixing permissions on existing directory /data/pgsql/data ... okcreating subdirectories ... okselecting default max_connections ... 100selecting default shared_buffers ... 128MBselecting default timezone ... PRCselecting dynamic shared memory implementation ... posixcreating configuration files ... okrunning bootstrap script ... okperforming post-bootstrap initialization ... oksyncing data to disk ... okWARNING: enabling "trust" authentication for local connectionsYou 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:    ./pg_ctl -D /data/pgsql/data -l logfile start

7. 检查数据目录:

[root@localhost data]# lsbase          pg_hba.conf    pg_notify     pg_stat      pg_twophase  postgresql.auto.confglobal        pg_ident.conf  pg_replslot   pg_stat_tmp  PG_VERSION   postgresql.confpg_commit_ts  pg_logical     pg_serial     pg_subtrans  pg_walpg_dynshmem   pg_multixact   pg_snapshots  pg_tblspc    pg_xact

其中

base目录是表空间目录;

global目录是相关全局变量目录;

pg_hba.conf是访问控制配置文件;

postgresql.conf是postgresql的主配置文件。

8. 修改pg_hba.conf文件

将该文件中的IPV4的连接修改为0.0.0.0/0,表示信任来自所有id连接的客户端,加密方式改为md5,如下图所示:

9.修改postgresql.conf配置文件

localhost改为*,表示监听所有的网络连接。其他的参数保持默认即可。

10. 关闭防火墙

systemctl stop firewalld

11. 启动数据库

[postgres@localhost bin]$ ./pg_ctl -D /data/pgsql/data -l /data/pgsql/log/pgsql.log   startwaiting for server to start.... doneserver started

12. 登录数据库并设置密码

[postgres@localhost bin]$ ./psql psql (11.4)Type "help" for help.postgres=# \passwordEnter new password: Enter it again: postgres=# \l                                  List of databases   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   -----------+----------+----------+-------------+-------------+----------------------- postgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |  template0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +           |          |          |             |             | postgres=CTc/postgres template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +           |          |          |             |             | postgres=CTc/postgres(3 rows)

13. navicat 登录

"怎么在CentOS 7.4环境下源码编译安装postgreSQL 11.4"的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注网站,小编将为大家输出更多高质量的实用文章!

0