zoukankan      html  css  js  c++  java
  • postgresql数据迁移

    postgresql从库故障准备新库

    1,创建用户
    [root@localhost home]# userdel postgres
    [root@localhost home]# groupdel postgres

    mkdir /home/mydb
    chown -R postgres:postgres /home/mydb
    2,解压安装包
    [root@localhost home]## tar -xvf postgres/postgresql-8.1.4.tar

    cd postgres/postgresql-8.1.4
    编译安装: ./configure --prefix=/usr/local/pgsql -localstatedir=/home/mydb

    $ ./configure --prefix=/usr/local/pgsql --with-pgconfigdir=/usr/local/pgsql/bin/ --with-pgbindir=/usr/local/pgsql/bin/ --with-pgincludedir=/usr/local/pgsql
    /include/ --with-pgincludeserverdir=/usr/local/pgsql/include/server/ --with-pglibdir=/usr/local/pgsql/lib/ --with-pgpkglibdir=/usr/local/pgsql/lib/ --with-pgsharedir=/usr/local/pgsql/share/
    make

    All of PostgreSQL successfully made. Ready to install


    su - postgres

    vi .bash_profile

    PATH=$PATH:$HOME/bin:/usr/local/pgsql/bin

    /usr/local/pgsql/bin/initdb /home/mydb


    /usr/local/pgsql/bin/pg_ctl -D /home/mydb star

    3.slony安装

    tar -xvf slony1-1.2.6.tar

    su - root

    ./configure --with-pgsourcetree=/usr/local/pgsql/bin

    $ ./configure --prefix=/usr/local/pgsql --with-pgconfigdir=/usr/local/pgsql/bin/ --with-pgbindir=/usr/local/pgsql/bin/ --with-pgincludedir=/usr/local/pgsql
    /include/ --with-pgincludeserverdir=/usr/local/pgsql/include/server/ --with-pglibdir=/usr/local/pgsql/lib/ --with-pgpkglibdir=/usr/local/pgsql/lib/ --with-pgsharedir=/usr/local/pgsql/share/

    3.主库数据备份

     /usr/local/pgsql/bin/pg_dumpall > /home/mydb/backup/`date '+%Y%m%d'`_dumpall.sql

    4.新库恢复

    psql -f /home/mydb/backup/`date '+%Y%m%d'`_dumpall.sql

    发现报错:

    psql:20150611_dumpall.sql:406: ERROR: could not access file "$libdir/dblink": No such file or directory
    psql:20150611_dumpall.sql:409: ERROR: function public.dblink(text, text) does not exist
    psql:20150611_dumpall.sql:417: ERROR: could not access file "$libdir/dblink": No such file or directory
    psql:20150611_dumpall.sql:420: ERROR: function public.dblink(text, text, boolean) does not exist
    psql:20150611_dumpall.sql:428: ERROR: could not access file "$libdir/dblink": No such file or directory
    psql:20150611_dumpall.sql:431: ERROR: function public.dblink(text) does not exist
    psql:20150611_dumpall.sql:439: ERROR: could not access file "$libdir/dblink": No such file or directory
    psql:20150611_dumpall.sql:442: ERROR: function public.dblink(text, boolean) does not exist
    psql:20150611_dumpall.sql:450: ERROR: could not access file "$libdir/dblink": No such file or directory
    psql:20150611_dumpall.sql:453: ERROR: function public.dblink_build_sql_delete(text, int2vector, integer, text[]) does not exist
    psql:20150611_dumpall.sql:461: ERROR: could not access file "$libdir/dblink": No such file or directory
    psql:20150611_dumpall.sql:464: ERROR: function public.dblink_build_sql_insert(text, int2vector, integer, text[], text[]) does not exist
    psql:20150611_dumpall.sql:472: ERROR: could not access file "$libdir/dblink": No such file or directory
    psql:20150611_dumpall.sql:475: ERROR: function public.dblink_build_sql_update(text, int2vector, integer, text[], text[]) does not exist
    psql:20150611_dumpall.sql:483: ERROR: could not access file "$libdir/dblink": No such file or directory
    psql:20150611_dumpall.sql:486: ERROR: function public.dblink_close(text) does not exist

    报错原因是数据库中用到存储过程,存储过程用到dblink

    配置安装dblink(扩展)

    cd /home/postgres/postgresql-8.1.4/contrib
    make

    make install

    再恢复没问题了。

    5.旧从库上的脚本以及slon脚本文件都移到新库上来,修改IP为从库IP

  • 相关阅读:
    bootstrap组件+模板地址
    10个自动化测试框架,测试工程师用起来
    IP地址分类(A类 B类 C类 D类 E类)
    来不及解释!Linux常用命令大全,先收藏再说
    凭借祖传配方年入21亿(王守义十三香),一生坚持不上市,亏待自己也要善待员工
    不同手指戴戒指的含义
    Soul App 是一款怎样的产品? SOUL APP 机缘巧合我开始使用 今天第四天内心想知道大家对它的感受 又其实并没有那么想大家把感受具象化再描述出来 嗯 还是希望大家能说一说(网恋需谨慎,小心骗子)
    解放双手,markdown文章神器,Typora+PicGo+七牛云图床实现自动上传图片
    度学习与自然语言处理
    软件测试面试之剖析面试官
  • 原文地址:https://www.cnblogs.com/youhunyimeng/p/4578904.html
Copyright © 2011-2022 走看看