美文网首页
pgsql/postgres数据库备份还原

pgsql/postgres数据库备份还原

作者: 勇敢的心888 | 来源:发表于2021-10-17 13:09 被阅读0次

    备份命令(英文版)

    [pgsql@ 192.168.0.12 /opt/pgsql/pgsql/bin]$./pg_dumpall --help
    pg_dumpall extracts a PostgreSQL database cluster into an SQL script file.

    Usage:
    pg_dumpall [OPTION]...

    General options:
    -f, --file=FILENAME output file name
    -v, --verbose verbose mode
    -V, --version output version information, then exit
    --lock-wait-timeout=TIMEOUT fail after waiting TIMEOUT for a table lock
    -?, --help show this help, then exit

    Options controlling the output content:
    -a, --data-only dump only the data, not the schema
    -c, --clean clean (drop) databases before recreating
    -g, --globals-only dump only global objects, no databases
    -o, --oids include OIDs in dump
    -O, --no-owner skip restoration of object ownership
    -r, --roles-only dump only roles, no databases or tablespaces
    -s, --schema-only dump only the schema, no data
    -S, --superuser=NAME superuser user name to use in the dump
    -t, --tablespaces-only dump only tablespaces, no databases or roles
    -x, --no-privileges do not dump privileges (grant/revoke)
    --binary-upgrade for use by upgrade utilities only
    --column-inserts dump data as INSERT commands with column names
    --disable-dollar-quoting disable dollar quoting, use SQL standard quoting
    --disable-triggers disable triggers during data-only restore
    --if-exists use IF EXISTS when dropping objects
    --inserts dump data as INSERT commands, rather than COPY
    --no-publications do not dump publications
    --no-role-passwords do not dump passwords for roles
    --no-security-labels do not dump security label assignments
    --no-subscriptions do not dump subscriptions
    --no-sync do not wait for changes to be written safely to disk
    --no-tablespaces do not dump tablespace assignments
    --no-unlogged-table-data do not dump unlogged table data
    --quote-all-identifiers quote all identifiers, even if not key words
    --use-set-session-authorization
    use SET SESSION AUTHORIZATION commands instead of
    ALTER OWNER commands to set ownership

    Connection options:
    -d, --dbname=CONNSTR connect using connection string
    -h, --host=HOSTNAME database server host or socket directory
    -l, --database=DBNAME alternative default database
    -p, --port=PORT database server port number
    -U, --username=NAME connect as specified database user
    -w, --no-password never prompt for password
    -W, --password force password prompt (should happen automatically)
    --role=ROLENAME do SET ROLE before dump

    If -f/--file is not used, then the SQL script will be written to the standard
    output.

    Report bugs to pgsql-bugs@postgresql.org.

    备份命令(中文版)

    pg_dump 把一个数据库转储为纯文本文件或者是其它格式.

    用法:
    pg_dump [选项]... [数据库名字]

    一般选项:
    -f, --file=FILENAME 输出文件或目录名
    -F, --format=c|d|t|p 输出文件格式 (定制, 目录, tar)
    明文 (默认值))
    -j, --jobs=NUM 执行多个并行任务进行备份转储工作
    -v, --verbose 详细模式
    -V, --version 输出版本信息,然后退出
    -Z, --compress=0-9 被压缩格式的压缩级别
    --lock-wait-timeout=TIMEOUT 在等待表锁超时后操作失败
    -?, --help 显示此帮助, 然后退出

    控制输出内容选项:
    -a, --data-only 只转储数据,不包括模式
    -b, --blobs 在转储中包括大对象
    -c, --clean 在重新创建之前,先清除(删除)数据库对象
    -C, --create 在转储中包括命令,以便创建数据库
    -E, --encoding=ENCODING 转储以ENCODING形式编码的数据
    -n, --schema=SCHEMA 只转储指定名称的模式
    -N, --exclude-schema=SCHEMA 不转储已命名的模式
    -o, --oids 在转储中包括 OID
    -O, --no-owner 在明文格式中, 忽略恢复对象所属者

    -s, --schema-only 只转储模式, 不包括数据
    -S, --superuser=NAME 在明文格式中使用指定的超级用户名
    -t, --table=TABLE 只转储指定名称的表
    -T, --exclude-table=TABLE 不转储指定名称的表
    -x, --no-privileges 不要转储权限 (grant/revoke)
    --binary-upgrade 只能由升级工具使用
    --column-inserts 以带有列名的INSERT命令形式转储数据
    --disable-dollar-quoting 取消美元 (符号) 引号, 使用 SQL 标准引号
    --disable-triggers 在只恢复数据的过程中禁用触发器
    --enable-row-security 启用行安全性(只转储用户能够访问的内容)
    --exclude-table-data=TABLE 不转储指定名称的表中的数据
    --if-exists 当删除对象时使用IF EXISTS
    --inserts 以INSERT命令,而不是COPY命令的形式转储数据
    --no-security-labels 不转储安全标签的分配
    --no-synchronized-snapshots 在并行工作集中不使用同步快照
    --no-tablespaces 不转储表空间分配信息
    --no-unlogged-table-data 不转储没有日志的表数据
    --quote-all-identifiers 所有标识符加引号,即使不是关键字
    --section=SECTION 备份命名的节 (数据前, 数据, 及 数据后)
    --serializable-deferrable 等到备份可以无异常运行
    --snapshot=SNAPSHOT 为转储使用给定的快照
    --strict-names 要求每个表和/或schema包括模式以匹配至少一个实体
    --use-set-session-authorization
    使用 SESSION AUTHORIZATION 命令代替
    ALTER OWNER 命令来设置所有权

    联接选项:
    -d, --dbname=DBNAME 对数据库 DBNAME备份
    -h, --host=主机名 数据库服务器的主机名或套接字目录
    -p, --port=端口号 数据库服务器的端口号
    -U, --username=名字 以指定的数据库用户联接
    -w, --no-password 永远不提示输入口令
    -W, --password 强制口令提示 (自动)
    --role=ROLENAME 在转储前运行SET ROLE

    如果没有提供数据库名字, 那么使用 PGDATABASE 环境变量
    的数值.

    报告错误至 pgsql-bugs@postgresql.org.

    su - pgsql
    # 备份单个库
    pg_dump -U postgres -d myDBname -f dump.sql
    # 备份所有的库
    pg_dumpall –h 127.0.0.1 –p 5432 -U postgres –c  -C –f db_bak.sql
    

    还原数据库

    createdb newDBname
    psql -d newDBname -U postgres -f dump.sql
    

    相关文章

      网友评论

          本文标题:pgsql/postgres数据库备份还原

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