公司服务器上安装的Postgresql版本是9.2.7,是比较老的了,不支持并行查询和插入,但是上头又总是提出非常大的查询需求(6亿*31这种),所以想升级到9.6,以便加入并行机制,提升下效率。
官网直接下载source包,我下载的是9.6.12版本,没什么理由,9.6里最新的而已。
直接解压并配置
# tar -zxvf postgresql-9.6.12.tar.gz
# cd postgresql-9.6.12
# ./configure --prefix=/data/5435/pgsql-9.6 --with-perl --with-python --with-openssl --with-pam --without-ldap --with-libxml --with-libxslt
把一些缺少的包打上,然后编译
# gmake world
# gmake install-world
安装完成(不出其他幺儿子的话)
这里创建下postgres用户(升级的话,肯定原来用户就有,就不用创建了)
# useradd postgres
还有,需要修改下postgresql.conf和pg_hba.conf两个文件。
初始化数据库
# su - postgres
$ /data/5435/pgsql-9.6/bin/initdb -E UTF8 -D /data/5435/pgsql --locale=zh_CN.UTF-8 -U postgres -W
新库这里就准备好了,然后把旧的数据文件直接拷贝进新的目录里,记得是拷贝哦。拷贝完成后进行升级验证
$ /data/5435/pgsql-9.6/bin/pg_upgrade -c -j 2 -U postgres -v -b /usr/bin -B /data/5435/pgsql-9.6/bin -d /data/5432 -D /data/5435/pgsql -p 5432 -P 5435
pg_upgrade的说明:
$ /data/5435/pgsql-9.6/bin/pg_upgrade --help
pg_upgrade upgrades a PostgreSQL cluster to a different major version.
Usage:
pg_upgrade [OPTION]...
Options:
-b, --old-bindir=BINDIR old cluster executable directory
-B, --new-bindir=BINDIR new cluster executable directory
-c, --check check clusters only, don't change any data
-d, --old-datadir=DATADIR old cluster data directory
-D, --new-datadir=DATADIR new cluster data directory
-j, --jobs number of simultaneous processes or threads to use
-k, --link link instead of copying files to new cluster
-o, --old-options=OPTIONS old cluster options to pass to the server
-O, --new-options=OPTIONS new cluster options to pass to the server
-p, --old-port=PORT old cluster port number (default 50432)
-P, --new-port=PORT new cluster port number (default 50432)
-r, --retain retain SQL and log files after success
-U, --username=NAME cluster superuser (default "postgres")
-v, --verbose enable verbose internal logging
-V, --version display version information, then exit
-?, --help show this help, then exit
Before running pg_upgrade you must:
create a new database cluster (using the new version of initdb)
shutdown the postmaster servicing the old cluster
shutdown the postmaster servicing the new cluster
When you run pg_upgrade, you must provide the following information:
the data directory for the old cluster (-d DATADIR)
the data directory for the new cluster (-D DATADIR)
the "bin" directory for the old version (-b BINDIR)
the "bin" directory for the new version (-B BINDIR)
For example:
pg_upgrade -d oldCluster/data -D newCluster/data -b oldCluster/bin -B newCluster/bin
or
$ export PGDATAOLD=oldCluster/data
$ export PGDATANEW=newCluster/data
$ export PGBINOLD=oldCluster/bin
$ export PGBINNEW=newCluster/bin
$ pg_upgrade
Report bugs to <pgsql-bugs@postgresql.org>.
但是,我校验没通过:
Values to be changed:
First log segment after reset: 000000010000000000000002
"/usr/bin/pg_ctl" -w -l "pg_upgrade_server.log" -D "/data/5432" -o "-p 5432 -b -c listen_addresses='' -c unix_socket_permissions=0700 -c unix_socket_directory='/data/5435'" start >> "pg_upgrade_server.log" 2>&1
*failure*
There were problems executing ""/usr/bin/pg_ctl" -w -l "pg_upgrade_server.log" -D "/data/5432" -o "-p 5432 -b -c listen_addresses='' -c unix_socket_permissions=0700 -c unix_socket_directory='/data/5435'" start >> "pg_upgrade_server.log" 2>&1"
Consult the last few lines of "pg_upgrade_server.log" for
the probable cause of the failure.
connection to database failed: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/data/5435/.s.PGSQL.5432"?
could not connect to old postmaster started with the command:
"/usr/bin/pg_ctl" -w -l "pg_upgrade_server.log" -D "/data/5432" -o "-p 5432 -b -c listen_addresses='' -c unix_socket_permissions=0700 -c unix_socket_directory='/data/5435'" start
然后查看server.log
command: "/usr/bin/pg_ctl" -w -l "pg_upgrade_server.log" -D "/data/5432" -o "-p 5432 -b -c listen_addresses='' -c unix_socket_permissions=0700 -c unix_socket_directory='/data/5435'" start >> "pg_upgrade_server.log" 2>&1
等待服务器进程启动 ....致命错误: 未认可的配置参数 "unix_socket_directory"
.... 已停止等待
pg_ctl: 无法启动服务器进程
检查日志输出.
查了很多资料,都没有<未认可的配置参数 "unix_socket_directory">这玩意儿的说明,但是我直接在pg_ctl 调用unix_socket_directory='/data/5435'
是可以的,而且使用link,而不是copy,也是检查通过,时间有限,先记录一下问题,后面继续研究。By the way,我虚拟机上检查是通过的,可能生产环境有特殊配置emmmm。




