环境:
当前版本:pg 9.4.6 安装路劲为:/data/pg946/
目标版本:pg 9.5.1 安装路劲为:/data/pg951/*****************************************************
1.安装新版本
*****************************************************/*******make --versiongcc --versionperl --versionpython --version----1.安装环境包yum -y install wget gcc gcc-c++ readline-devel zlib-devel make   systemtap systemtap-sdt-devel \
perl perl-devel python python-devel tcl  tcl-devel    perl-ExtUtils-Embed \
sgml-common docbook stylesheets openjade  sgml-tools  xsltproc libxslt libxslt-devel \
libxml2 libxml2-devel zlib zlib-devel openssl openssl-devel   pam pam-devel bison flex libreadline6-devel ******/----2.编译安装#useradd postgres && echo 'password' |passwd --stdin  postgres#mkdir -p /data/pg951/data   && chown -R postgres /data/pg951/data# wget https://ftp.postgresql.org/pub/source/v9.5.1/#mkdir -p /soft && cd /soft#rz# tar xf postgresql-9.5.1.tar.gz && cd postgresql-9.5.1#./configure./configure --prefix=/data/pg951 \
--with-pgport=5435  \
--with-perl --with-python --with-tcl  \
--with-openssl  --without-ldap  \--with-libxml  --with-libxslt    \
--enable-thread-safety    \
--with-wal-blocksize=64   \
--with-blocksize=32 \
--with-wal-segsize=64 \
-enable-dtrace  \
--enable-debug#make && make install-----3.执行数据库初始化脚本(指定字符集)$/data/pg951/bin/initdb  -D /data/pg951/data  --encoding=utf8   -U postgres---结果如下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 database encoding has accordingly been set to "SQL_ASCII".
The default text search configuration will be set to "english".Data page checksums are disabled.fixing permissions on existing directory /data/pg951/data ... 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/pg951/data/base/1 ... ok
initializing pg_authid ... 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 ... okWARNING: 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:/data/pg951/bin/pg_ctl -D /data/pg951/data -l logfile start----4.启动pg新版本$cp postgresql.conf  /data/pg951/data/$/data/pg951/bin/pg_ctl  -D /data/pg951/data  status$/data/pg951/bin/pg_ctl  -D /data/pg951/data  start $退出变更登录
exit*****************************************************
---2.升级
*****************************************************-----1.将两个库都停止服务$ netstat -lntp | grep postgres
tcp        0      0 0.0.0.0:5432                0.0.0.0:*                   LISTEN      6287/postgres
tcp        0      0 127.0.0.1:5435              0.0.0.0:*                   LISTEN      6303/postgres   $/data/pg946/bin/pg_ctl   -D /data/pg946/data  stop $/data/pg951/bin/pg_ctl  -D /data/pg951/data  stop  $ /data/pg946/bin/pg_ctl  -D /data/pg946/data  status
pg_ctl: no server running$ /data/pg951/bin/pg_ctl  -D /data/pg951/data  status
pg_ctl: no server running------2.执行pg_upgrade#mkdir -p /data/upgrade   && chown -R postgres /data/upgrade  ----2.1 进行pg_upgrade检查$cd /data/upgrade/$/data/pg951/bin/pg_upgrade   -c    -b /data/pg946/bin   \
-B /data/pg951/bin/ -d /data/pg946/data -D /data/pg951/data -p 5432 -P 5435Performing Consistency Checks
-----------------------------
Checking cluster versions                                   ok
Checking database user is the install user                  ok
Checking database connection settings                       ok
Checking for prepared transactions                          ok
Checking for reg* system OID user data types                ok
Checking for contrib/isn with bigint-passing mismatch       ok
Checking for presence of required libraries                 ok
Checking database user is the install user                  ok
Checking for prepared transactions                          ok*Clusters are compatible*----2.2进行pg_upgrade升级两种升级方式:
1).缺省的通过拷贝数据文件到新的data目录下,拷贝的方式升级较慢,但是原库还可用;
2).硬链接的方式升级较快,但是原库不可用.$/data/pg951/bin/pg_upgrade   -b /data/pg946/bin   \
-B /data/pg951/bin/ -d /data/pg946/data -D /data/pg951/data -p 5432 -P 5435----执行结果
Performing Consistency Checks
-----------------------------
Checking cluster versions                                   ok
Checking database user is the install user                  ok
Checking database connection settings                       ok
Checking for prepared transactions                          ok
Checking for reg* system OID user data types                ok
Checking for contrib/isn with bigint-passing mismatch       ok
Creating dump of global objects                             ok
Creating dump of database schemasok
Checking for presence of required libraries                 ok
Checking database user is the install user                  ok
Checking for prepared transactions                          okIf pg_upgrade fails after this point, you must re-initdb the
new cluster before continuing.Performing Upgrade
------------------
Analyzing all rows in the new cluster                       ok
Freezing all rows on the new cluster                        ok
Deleting files from new pg_clog                             ok
Copying old pg_clog to new server                           ok
Setting next transaction ID and epoch for new cluster       ok
Deleting files from new pg_multixact/offsets                ok
Copying old pg_multixact/offsets to new server              ok
Deleting files from new pg_multixact/members                ok
Copying old pg_multixact/members to new server              ok
Setting next multixact ID and offset for new cluster        ok
Resetting WAL archives                                      ok
Setting frozenxid and minmxid counters in new cluster       ok
Restoring global objects in the new cluster                 ok
Restoring database schemas in the new clusterok
Creating newly-required TOAST tables                        ok
Copying user relation filesok
Setting next OID for new cluster                            ok
Sync data directory to disk                                 ok
Creating script to analyze new cluster                      ok
Creating script to delete old cluster                       okUpgrade Complete
----------------
Optimizer statistics are not transferred by pg_upgrade so,
once you start the new server, consider running:./analyze_new_cluster.shRunning this script will delete the old cluster's data files:./delete_old_cluster.sh---3. 修改新版本为正常端口号$ grep -i "^port" /data/pg951/data/postgresql.conf
port = 5435         # (change requires restart)$ sed  -i "s/5435/5432/1" /data/pg951/data/postgresql.conf
port = 5432         # (change requires restart)----4.修改环境变量# su - postgres$  vi  ~/.bash_profile # postgres
#PostgreSQL端口
PGPORT=5432#PostgreSQL数据目录
PGDATA=/data/pg951/dataexport PGPORT PGDATA #所使用的语言
export LANG=en_US.utf8#PostgreSQL 安装目录
export PGHOME=/data/pg951#PostgreSQL 连接库文件
export LD_LIBRARY_PATH=$PGHOME/lib:/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib:$LD_LIBRARY_PATH
export DATE=`date +"%Y%m%d%H%M"`#将PostgreSQL的命令行添加到 PATH 环境变量
export PATH=$PGHOME/bin:$PATH#PostgreSQL的 man 手册
export MANPATH=$PGHOME/share/man:$MANPATH#PostgreSQL的默认用户
export PGUSER=postgres#PostgreSQL默认主机地址
export PGHOST=127.0.0.1#默认的数据库名
export PGDATABASE=postgres#source ~/.bash_profile ----5.PostgreSQL执行脚本#复制PostgreSQL执行脚本
cp /soft/postgresql-9.5.1/contrib/start-scripts/linux  /etc/init.d/postgresql#增加执行权限
chmod +x /etc/init.d/postgresql#编辑PostgreSQL执行脚本,确定以下参数或修改#vi /etc/init.d/postgresql# Installation prefix
prefix=/data/pg951# Data directory
PGDATA="/data/pg951/data"# Who to run the postmaster as, usually "postgres".  (NOT "root")
PGUSER=postgres# Where to keep a log file
PGLOG="$PGDATA/serverlog"----6.启动新版本
/data/pg951/bin/pg_ctl  -D /data/pg951/data  start-----7.验证
$ /data/pg951/bin/psql  --version
psql (PostgreSQL) 9.5.1$ /data/pg951/bin/psql
psql (9.5.1)
Type "help" for help.postgres@127.0.0.1 ~=# \lList of databasesName    |  Owner   | Encoding |  Collate   |   Ctype    |   Access privileges
-----------+----------+----------+------------+------------+-----------------------postgres  | postgres | UTF8     | en_US.utf8 | en_US.utf8 | template0 | postgres | UTF8     | en_US.utf8 | en_US.utf8 | =c/postgres          +|          |          |            |            | postgres=CTc/postgrestemplate1 | postgres | UTF8     | en_US.utf8 | en_US.utf8 | postgres=CTc/postgres+|          |          |            |            | =c/postgreswind      | postgres | UTF8     | en_US.utf8 | en_US.utf8 |
(4 rows)postgres@127.0.0.1 ~=# \c wind
You are now connected to database "wind" as user "postgres".
postgres@127.0.0.1 wind=# \dList of relationsSchema | Name | Type  |  Owner
--------+------+-------+----------public | t00  | table | postgres
(1 row)postgres@127.0.0.1 wind=# select count(*) from t00;count
-------1000
(1 row)Time: 2.308 ms
postgres@127.0.0.1 wind=# ---8.删除老版本软件$ cat delete_old_cluster.sh
#!/bin/shrm -rf '/data/pg941/data'$ ./delete_old_cluster.sh 

postgresql大版本升级相关推荐

  1. PostgreSQL大版本升级(pg_upgrade)11.7升12.2

    原版本:11.7 安装路径:/usr/local/pgsql/bin/ 数据目录路径:/usr/local/pgsql/data/ 新版本:12.2 安装路径:/usr/local/pgsql12/b ...

  2. RDS PostgreSQL一键大版本升级技术解密

    简介:内容简要: 一.PostgreSQL行业位置 二.PostgreSQL版本升级背景 三.PostgreSQL版本升级解密 四.PostgreSQL版本升级成果 一.PostgreSQL行业位置 ...

  3. pg之使用pg_upgrade进行大版本升级

    搞了一个公众号PostgreSQL运维技术,欢迎来踩~ 悄悄放一张: PostgreSQL运维技术 pg_upgrade官网:https://www.postgresql.org/docs/curre ...

  4. postgresql大表join优化

    postgresql大表join优化 一.背景 1.数据量: 表名 数据量 f_invoice 87346130 f_invoice_item 97535867 2.索引: 表:f_invoice_i ...

  5. android 版本更新并启动,更新如此之快! 华为P20系列开启第二次安卓大版本升级...

    近期,EMUI正式开启对华为P20系列升级EMUI10内测招募.同时,根据此前EMUI公布信息,华为Mate10系列等多款较早机型也在升级EMUI10计划之中,将会在稍晚时候开启内测. 华为P20系列 ...

  6. postgresql java类型_JAVA存取PostgreSQL大对象类型oid

    //VM配置:256M-512M //通过lo_import('文件路径')函数向oid字段插入二进制文件,通过(不会内存溢出). /** * * @author Liu Yuanyuan */ pr ...

  7. 华为云数据库PostgreSQL 大揭秘

    各位开发者.企业老板们,一个好消息悄然来临:即日起,1元就可以畅享4核8G的华为云数据库PostgreSQL服务1个月,快来开启专属你的PG上云之旅吧~ PostgreSQL是一种典型的开源关系型数据 ...

  8. postgres大版本升级

    前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家.点击跳转到教程. 进行升级版本之前请一定做好备份! 查看当前版本: [postgres@node1 ~]$ psql ...

  9. FineUI大版本升级,外置ExtJS库、去AXD化、表格合计行、表格可编辑单元格的增删改、顶部菜单框架

    FineUI v3.3.0 更新的内容非常多,所以一下子从 v3.2.6 连跳 3 个小版本,直接来到了 v3.3.0.详细的更新记录请参考这里:http://fineui.com/version 主 ...

最新文章

  1. JQuery中的事件和选择器
  2. 爸爸和无我编程十条诫律
  3. MySQL怎么导入webcontent_把网页信息添加到mysql,在MyEclipse运行Tomcat出现下面的错误,弄不明白,求助怎么解决呀...
  4. JDK动态代理小例子
  5. ae中心点重置工具_不懂这些知识,你的AE白学了!
  6. 轻松构建基于 Serverless 架构的小程序
  7. python Django数据库保存操作
  8. 将JSON格式数据转换为javascript对象 JSON.parse()
  9. linux下查找命令which/whereis/locate/find的对比和总结
  10. Codeforces Round #212 (Div. 2) C. Insertion Sort 思维
  11. 指针和字符串,数组和字符串(1)
  12. Tcp-IP详解之Telnet
  13. UE4 虚幻引擎,SourceControl源码管理
  14. UVALive 7269 Snake Carpet
  15. 5G系统——5G QoS
  16. 编程c语言counter,c语言中计算平均分时,计数器(counter)的初始化
  17. ssh-keygen命令详解
  18. linux查询数据库归档日志,关于 Oracle 归档日志
  19. 【算法】NP完全问题以及世界数学七大难题
  20. 虚拟机构建局域网用户和组远程

热门文章

  1. 【Java小攻略】时间API全解析
  2. 完整版MYSQL 使用基础 - 这么用就对了
  3. KY-RTI分布仿真技术:前言
  4. 【Unity课设】孤岛奇缘 文档 + 源码 + 执行文件(简简单单~)
  5. solaris 10u11 安装vim7.4
  6. anyRTC-在线娃娃机
  7. 读书笔记--实践者的研究方法
  8. 计算机弹奏致爱数字,华为电脑——我的至爱
  9. 《程序员的自我修养-Ch7_动态链接》
  10. C# dotnet 一个看上去还能用的二进制序列化帮助类