美文网首页
PostgreSQL-数据导入/导出

PostgreSQL-数据导入/导出

作者: JAVA_ASS | 来源:发表于2020-04-29 17:38 被阅读0次
    commond模式:
        数据库内:
            copy tablename to xx.csv【绝对路径】 
            copy tablename from xx.csv【绝对路径】
        终端机:
            psql --dbname=e1531124800582r61db --host=110.49.136.24 --port 6440 --username=admin -c "COPY (select * from event_operation) TO STDOUT with csv header" > /var/tomcat/event_operation_all.csv
            psql --dbname=e1531124800582r61db --host=110.49.136.24 --port 6440 --username=admin -c "COPY (select * from event_operation) TO STDOUT with csv header" > /var/tomcat/event_operation_all.csv
        https://www.cnblogs.com/dview112/archive/2012/10/22/2733706.html
    可视化工具:
        pgAdmin:
            选择表-->备份-->
            选择表-->导入-->csv格式、UTF8格式
    

    数据导出到csv

    设置 输出
    设置分隔符: \f ','(\f 'Ctrl-V TAB' tab分隔符) Field separator is ",".
    设置输出格式: \a Output format is unaligned.
    设置输出行:\t Tuples only is on.
    设置输出文件名:\o outputfile.csv ''
    执行导出数据脚本:select * from table ''
    输出到文件:\o ''

    数据导出到txt

     psql --dbname=dbname --host=hostIP --port port --username=dbuser -c "COPY (select * from table ) TO STDOUT">/home/a.sql
    

    数据以json格式导出text

    \o outputfile.txt
    select row_to_json(tablename) from tablename;
    \o
    

    9、linux下安装postgresql

    yum install http://yum.postgresql.org/9.4/redhat/rhel-6-x86_64/pgdg-redhat94-9.4-3.noarch.rpm
     yum -y install postgresql94-server postgresql94-contrib
    

    9、查询所有的序列seq

    select relname from pg_class where relowner=(select usesysid from pg_user where usename='YOURUSERNAME') and relkind='S'
    

    相关文章

      网友评论

          本文标题:PostgreSQL-数据导入/导出

          本文链接:https://www.haomeiwen.com/subject/czynwhtx.html