zoukankan      html  css  js  c++  java
  • psql 数据表导入导出

    $ createdb old_cms
    $ psql old_cms

    $ pg_restore --verbose --clean --no-acl --no-owner -h localhost -U aaa -d old_cms ~/Downloads/old_cms.dump

    # select * from pg_tables;
    # select * from "BlogPost";
    # select count(*) from "BlogPost";
    # d "BlogPost";
    # select * from "BlogPost" where 'FeaturedImageCaption' != '';

    get the password by:
    #sudo docker inspect cms | grep "SS_DATABASE

    #pg_dump -h preproduction-aaa.amazonaws.com -U ss -Fc ss > PG_DUMP_21_JULY_2021.dump -T *_versions

    #scp ubuntu@preproduction-aaat.com:/home/ubuntu/PG_DUMP_21_JULY_2021.dump ~/Downloads/

    scp ubuntu@preproduction-aaa.com:/home/ubuntu/PG_DUMP_21_JULY_2021.dump ~/Downloads/


    导出整个表结构
    pg_dump --host localhost -U aaa --file BlogCategory.dump --table "public."BlogCategory"" "old_cms"

    导入
    psql -U aaa -d preprod-cms < BlogCategory.dump


    导出表中数据数据 (不带header的方法)
    COPY (select * from "BlogCategory") TO '/Users/aaa/Downloads/BlogCategory.csv' WITH csv;
    导入 (不带header的csv数据)
    COPY "BlogCategory" FROM '/Users/aaa/Downloads/BlogCategory.csv' WITH csv;


    # DELETE FROM "BlogCategory" where "ID" > 1;

    $ scp ~/Downloads/BlogCategory.csv ubuntu@preproduction-aaa.com:/home/ubuntu/

    $ psql -h preproduction-aaa.amazonaws.com -U ss -Fc ss

    真正导入的时候发现前面要加一个反斜线

    # copy "BlogCategory" FROM '/home/ubuntu/BlogCategory.csv' with csv;
    由于csv文件改变了日期的格式,需要先run一下这行命令
    # SET datestyle = dmy;

    导出带header的csv文件

    COPY (select * from "Blog_Live") TO '/Users/aaa/Downloads/Blog_Live.csv' WITH csv header;

    拷贝到远程服务器
    scp ~/Downloads/Blog_Live.csv ubuntu@preproduction-aaa.com:/home/ubuntu/

    链接到远程服务器:

    ssh ubuntu@preproduction-aaa.com
    sudo docker inspect cms | grep "SS_DATABASE

    登录到服务器的数据库

    psql -h preproduction-aaa.amazonaws.com -U ss -Fc ss

    导入带header的csv文件

    copy "Blog_Live" FROM '/home/ubuntu/Blog_Live.csv' with csv header;

  • 相关阅读:
    【SPI】浅谈JDK中SPI技术
    【MySQL8.0.18】阿里云服务器上搭建MySQL数据库
    【JDK13】阿里云服务器安装JDK13
    小型个人博客搭建之数据库设计
    【算法题】CCF CSP第三题练习(更新中)
    【算法题】CCF CSP第一题练习
    【嵌入式】KEIL4和KEIL5合并
    【ROS】安装ubuntu18.04+ros-melodic
    Notepad++配置python之NppExec
    vi一般指令命令行
  • 原文地址:https://www.cnblogs.com/iwangzheng/p/15064034.html
Copyright © 2011-2022 走看看