源码安装Postgresql9.5


2016-09-21 09:36:28
标签: 系统  数据库  database
原创作品,允许转载,转载时请务必以超链接形式标明文章  原始出处 、作者信息和本声明。否则将追究法律责任。 http://lorne.blog.51cto.com/9062483/1854785

Postgresql简介:

PostgreSQL是一个功能强大,开源对象关系型数据库系统。它拥有超过15年的持续开发和经验证的体系结构,赢得了良好的声誉:可靠性,数据完整性和正确性

官方号称:

PostgreSQL: The world's most advanced open source database

官网下载地址:https://www.postgresql.org/download/

Postgresql部署:

环境:

[root@node-01 ~]# cat /etc/redhat-release 
CentOS Linux release 7.2.1511 (Core)

 下载包:

[root@node-01 ~]# wget https://ftp.postgresql.org/pub/source/v9.5.4/postgresql-9.5.4.tar.gz

 安装依赖包:

[root@node-01 ~]# yum install gcc gcc-c++ automake autoconf libtool make readline-devel zlib-devel  -y
[root@node-01 ~]# yum install -y perl-ExtUtils-Embed  perl-ExtUtils-MakeMake perl-ExtUtils-MakeMaker-Coverage readline readline-devel pam pam-devel libxml2 libxml-devel libxml2-python libxml2-static  libxslt libxslt-devel  tcl tcl-devel python-devel openssl openssl-devel

创建postgresql用户及设置密码(postgresql默认不允许root用户启动):

[root@node-01 ~]# useradd -u 6233 -p 123456 postgres    
[root@node-01 ~]# id postgres
uid=6233(postgres) gid=6233(postgres) groups=6233(postgres)

 编译安装postgresql:

[root@node-01 ~]# tar -xf postgresql-9.5.4.tar.gz 
[root@node-01 ~]# cd postgresql-9.5.4
[root@node-01 postgresql-9.5.4]# ./configure --prefix=/usr/local/postgresql  --with-pgport=1921 --with-perl --with-tcl --with-python --with-openssl --with-pam  --with-libxml --with-libxslt --enable-thread-safety --with-wal-blocksize=16 --with-blocksize=16
编译安装有两种方式:make和gmake,这里推荐gmake
方法1:gmake world &&  gmake install-world
方法2:make -j 4 && make install 
[root@node-01 postgresql-9.5.4]# gmake world &&  gmake install-world
[root@node-01 postgresql-9.5.4]# ls /usr/local/postgresql/
bin  include  lib  share

 设置数据库目录及权限:

[root@node-01 ~]# mkdir -p /data/postgresql
[root@node-01 ~]# chown -R postgres.postgres /data/postgresql/

 添加系统环境变量:

[root@node-01 ~]# echo 'export PATH=$PATH:/usr/local/postgresql/bin/' >> /etc/profile
[root@node-01 ~]# psql -V
psql (PostgreSQL) 9.5.4

 初始化数据库:

[root@node-01 ~]# su - postgres
[postgres@node-01 ~]$ initdb -D /data/postgresql/ -U postgres -E UTF8 --locale=C -W
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 "C".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /data/postgresql ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
creating template1 database in /data/postgresql/base/1 ... ok
initializing pg_authid ... ok
Enter new superuser password:      设置超级用户的密码
Enter it again: 
setting password ... ok
initializing dependencies ... ok
creating system views ... ok
loading system objects' descriptions ... ok
creating collations ... ok
creating conversions ... ok
creating dictionaries ... ok
setting privileges on built-in objects ... ok
creating information schema ... ok
loading PL/pgSQL server-side language ... ok
vacuuming database template1 ... ok
copying template1 to template0 ... ok
copying template1 to postgres ... 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/postgresql/ -l logfile start

参数:
-U postgres:指定的数据库超级管理员,自定义
-W :设置密码
-D :数据存放目录
-E :设置编译

修改验证方式简单的配置:

[postgres@node-01 ~]$ vim /data/postgresql/pg_hba.conf
host    all             all             127.0.0.1/32            md5    MD5验证方式需要输入用户密码
[postgres@node-01 ~]$ vim /data/postgresql/postgresql.conf
port = 1236                            # (change requires restart)
max_connections = 100 
unix_socket_directories = '/dev/shm/'

 添加服务管理脚本:

[root@node-01 ~]# cd postgresql-9.5.4
[root@node-01 postgresql-9.5.4]# cp contrib/start-scripts/linux /etc/init.d/postgresql
[root@node-01 postgresql-9.5.4]# chmod +x /etc/init.d/postgresql
[root@node-01 postgresql-9.5.4]# chkconfig postgresql on
[root@node-01 postgresql-9.5.4]# vim /etc/init.d/postgresql 
prefix=/usr/local/postgresql
PGDATA="/data/postgresql"
PGUSER=postgres
PGLOG="$PGDATA/serverlog"

启动postgresql:

[root@node-01 postgresql-9.5.4]# /etc/init.d/postgresql start
[root@node-01 postgresql-9.5.4]#  lsof -i :1236              
COMMAND     PID     USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
postmaste 16232 postgres    3u  IPv6  53256      0t0  TCP localhost:bvcontrol (LISTEN)
postmaste 16232 postgres    4u  IPv4  53257      0t0  TCP localhost:bvcontrol (LISTEN)

 登陆postgresql:

[root@node-01 ~]# psql -h 127.0.0.1 -p 1236 -U postgres -d postgres
Password for user postgres: 
psql (9.5.4)
Type "help" for help.

postgres=#

 安装所有的扩展包:

[root@node-01 ~]# cd postgresql-9.5.4/contrib/  
[root@node-01 contrib]# ls -d */ | xargs -n 1 -P 0 sh -c 'cd {}; make ; make install;'c

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
PostgreSQL 9.5 支持双主复制(也称为异步复制)。在这种配置中,两个 PostgreSQL 实例都可以向对方写入数据,这样可以提高系统的可用性和容错性。下面是 PostgreSQL 9.5 双主复制的详细步骤: 1. 安装 PostgreSQL 9.5 安装 PostgreSQL 9.5 的方法与其他版本相同,可以使用包管理器或从代码编译安装。 2. 配置主服务器 在主服务器上,需要进行以下配置: 2.1 修改 postgresql.conf 文件 将以下参数设置为: ``` wal_level = hot_standby max_wal_senders = 10 wal_keep_segments = 32 ``` 2.2 修改 pg_hba.conf 文件 在该文件中添加从备服务器连接主服务器的 IP 地址和用户名。 3. 配置备服务器 在备服务器上,需要进行以下配置: 3.1 修改 postgresql.conf 文件 将以下参数设置为: ``` hot_standby = on ``` 3.2 创建 recovery.conf 文件 在备服务器的数据目录中创建 recovery.conf 文件,并将以下内容添加到该文件中: ``` standby_mode = 'on' primary_conninfo = 'host=<主服务器IP> port=5432 user=<用户名> password=<密码>' restore_command = 'cp /var/lib/postgresql/9.5/main/archive/%f %p' ``` 其中,`<主服务器IP>`、`<用户名>` 和 `<密码>` 需要替换为实际的值,`restore_command` 参数用于将 WAL 日志文件从归档目录中复制到备服务器的 pg_xlog 目录中。 4. 启动主服务器和备服务器 在主服务器上启动 PostgreSQL 服务,然后在备服务器上启动 PostgreSQL 服务。备服务器会自动连接到主服务器并开始复制数据。 5. 测试双主复制 可以在任何一个服务器上进行写操作,并在另一个服务器上进行读操作来测试双主复制是否正常工作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值