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/data
mkdir -p /data/pgsql/log
cd /data/pgsql/log
touch pgsql.log
chown -R postgres:postgres /data/pgsql

5. 添加环境变量

vim /etc/profile

内容如下:

#postgresql
export PGHOME=/data/pgsql
export PGBASE=/usr/local/pgsql
export PATH=$PATH:$PGBASE/bin

使之生效

source /etc/profile

6. 初始化数据

切换到postgres用户下 su - postgres

[postgres@localhost ~]$ cd /usr/local/pgsql/bin/
[postgres@localhost bin]$ ls
clusterdb   ecpg               pg_config       pg_isready      pg_rewind            pg_waldump  vacuumdb
createdb    initdb             pg_controldata  pg_receivewal   pg_test_fsync        postgres
createuser  pg_archivecleanup  pg_ctl          pg_recvlogical  pg_test_timing       postmaster
dropdb      pg_basebackup      pg_dump         pg_resetwal     pg_upgrade           psql
dropuser    pgbench            pg_dumpall      pg_restore      pg_verify_checksums  reindexdb
[postgres@localhost bin]$ ./initdb -D /data/pgsql/data
The 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 ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default timezone ... PRC
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok
WARNING: enabling "trust" authentication for local connections
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:
    ./pg_ctl -D /data/pgsql/data -l logfile start

7. 检查数据目录:

[root@localhost data]# ls
base          pg_hba.conf    pg_notify     pg_stat      pg_twophase  postgresql.auto.conf
global        pg_ident.conf  pg_replslot   pg_stat_tmp  PG_VERSION   postgresql.conf
pg_commit_ts  pg_logical     pg_serial     pg_subtrans  pg_wal
pg_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   start
waiting for server to start.... done
server started

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

[postgres@localhost bin]$ ./psql 
psql (11.4)
Type "help" for help.
postgres=# \password
Enter 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 登录

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/69915315/viewspace-2651313/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/69915315/viewspace-2651313/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值