PostgreSQL pg_dump pg_dumpall and restore
pg_dump dumps a database as a text file or to other formats.
Usage:
pg_dump [OPTION]... [DBNAME]
General options:
-f, --file=FILENAME output file or directory name
-F, --format=c|d|t|p output file format (custom, directory, tar,
plain text (default))
-j, --jobs=NUM use this many parallel jobs to dump
-v, --verbose verbose mode
-V, --version output version information, then exit
-Z, --compress=0-9 compression level for compressed formats
--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
-b, --blobs include large objects in dump
-c, --clean clean (drop) database objects before recreating
-C, --create include commands to create database in dump
-E, --encoding=ENCODING dump the data in encoding ENCODING
-n, --schema=SCHEMA dump the named schema(s) only
-N, --exclude-schema=SCHEMA do NOT dump the named schema(s)
-o, --oids include OIDs in dump
-O, --no-owner skip restoration of object ownership in
plain-text format
-s, --schema-only dump only the schema, no data
-S, --superuser=NAME superuser user name to use in plain-text format
-t, --table=TABLE dump the named table(s) only
-T, --exclude-table=TABLE do NOT dump the named table(s)
-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
--exclude-table-data=TABLE do NOT dump data for the named table(s)
--if-exists use IF EXISTS when dropping objects
--inserts dump data as INSERT commands, rather than COPY
--no-security-labels do not dump security label assignments
--no-synchronized-snapshots do not use synchronized snapshots in parallel jobs
--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
--section=SECTION dump named section (pre-data, data, or post-data)
--serializable-deferrable wait until the dump can run without anomalies
--use-set-session-authorization
use SET SESSION AUTHORIZATION commands instead of
ALTER OWNER commands to set ownership
Connection options:
-d, --dbname=DBNAME database to dump
-h, --host=HOSTNAME database server host or socket directory
-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 no database name is supplied, then the PGDATABASE environment
variable value is used.
pg_dump is an effective tool to backup postgres database. It creates a *.sql file with CREATE TABLE, ALTER TABLE, and COPY SQL statements of source database. To restore these dumps psqlcommand is enough.
Using pg_dump, you can backup a local database and restore it on a remote database at the same time, using a single command.
Backup: $ pg_dump -U {user-name} {source_db} -f {dumpfilename.sql}
Restore: $ psql -U {user-name} -d {desintation_db}-f {dumpfilename.sql}
use pg_dump and psql backup and restore postgres database:
Backup a single postgres database
[postgres@minion2 bin]$ ./psql
psql (9.4.5)
Type "help" for help.
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
--------------+--------------+----------+---------+-------+-----------------------
benchmarksql | benchmarksql | UTF8 | C | C |
partition_db | postgres | UTF8 | C | C |
postgres | postgres | UTF8 | C | C |
template0 | postgres | UTF8 | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
test_pgdb | postgres | UTF8 | C | C |
(6 rows)
postgres=# \c benchmarksql benchmarksql
You are now connected to database "benchmarksql" as user "benchmarksql".
benchmarksql=# \d
List of relations
Schema | Name | Type | Owner
--------+------------+-------+--------------
public | customer | table | benchmarksql
public | district | table | benchmarksql
public | history | table | benchmarksql
public | item | table | benchmarksql
public | new_order | table | benchmarksql
public | oorder | table | benchmarksql
public | order_line | table | benchmarksql
public | stock | table | benchmarksql
public | warehouse | table | benchmarksql
(9 rows)
benchmarksql=# \d+
List of relations
Schema | Name | Type | Owner | Size | Description
--------+------------+-------+--------------+----------+-------------
public | customer | table | benchmarksql | 1804 MB |
public | district | table | benchmarksql | 536 kB |
public | history | table | benchmarksql | 250 MB |
public | item | table | benchmarksql | 10200 kB |
public | new_order | table | benchmarksql | 40 MB |
public | oorder | table | benchmarksql | 198 MB |
public | order_line | table | benchmarksql | 3011 MB |
public | stock | table | benchmarksql | 3477 MB |
public | warehouse | table | benchmarksql | 256 kB |
(9 rows)
benchmarksql=# \q
[postgres@minion2bin]$./pg_dump -U benchmarksql benchmarksql -f /tmp/benchmarksql_db_backup.sql
[root@minion2 tmp]# less benchmarksql_db_backup.sql
--
-- PostgreSQL database dump
--
SET statement_timeout = 0;
SET lock_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SET check_function_bodies = false;
SET client_min_messages = warning;
--
-- Name: plpgsql; Type: EXTENSION; Schema: -; Owner:
--
CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog;
--
-- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner:
--
COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language';
SET search_path = public, pg_catalog;
SET default_tablespace = '';
SET default_with_oids = false;
--
-- Name: customer; Type: TABLE; Schema: public; Owner: benchmarksql; Tablespace:
--
CREATE TABLE customer (
c_w_id integer NOT NULL,
c_d_id integer NOT NULL,
c_id integer NOT NULL,
c_discount numeric(4,4),
c_credit character(2),
c_last character varying(16),
c_first character varying(16),
c_credit_lim numeric(12,2),
c_balance numeric(12,2),
c_ytd_payment double precision,
c_payment_cnt integer,
c_delivery_cnt integer,
c_street_1 character varying(20),
c_street_2 character varying(20),
c_city character varying(20),
c_state character(2),
c_zip character(9),
c_phone character(16),
c_since timestamp without time zone,
c_middle character(2),
c_data character varying(500)
);
ALTER TABLE customer OWNER TO benchmarksql;
……
……
[postgres@minion2 bin]$ ./psql
psql (9.4.5)
Type "help" for help.
postgres=# drop database benchmarksql;
DROP DATABASE
postgres=# create database benchmarksql owner benchmarksql;
CREATE DATABASE
postgres=# \q
[postgres@minion2 bin]$ ./psql -U benchmarksql -d benchmarksql -f /tmp/benchmarksql_db_backup.sql
SET
SET
SET
SET
SET
SET
CREATE EXTENSION
COMMENT
SET
SET
SET
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
COPY 3000000
COPY 1000
COPY 3035734
COPY 100000
COPY 903653
COPY 3036923
COPY 30375276
COPY 10000000
COPY 100
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ERROR: canceling autovacuum task
CONTEXT: automatic analyze of table "benchmarksql.public.order_line"
ALTER TABLE
ERROR: canceling autovacuum task
CONTEXT: automatic analyze of table "benchmarksql.public.stock"
ALTER TABLE
ALTER TABLE
CREATE INDEX
CREATE INDEX
REVOKE
REVOKE
GRANT
GRANT
postgres=# \c benchmarksql benchmarksql
You are now connected to database "benchmarksql" as user "benchmarksql".
benchmarksql=# \d+
List of relations
Schema | Name | Type | Owner | Size | Description
--------+------------+-------+--------------+----------+-------------
public | customer | table | benchmarksql | 1772 MB |
public | district | table | benchmarksql | 152 kB |
public | history | table | benchmarksql | 250 MB |
public | item | table | benchmarksql | 10184 kB |
public | new_order | table | benchmarksql | 38 MB |
public | oorder | table | benchmarksql | 198 MB |
public | order_line | table | benchmarksql | 3000 MB |
public | stock | table | benchmarksql | 3392 MB |
public | warehouse | table | benchmarksql | 40 kB |
(9 rows)
Backup all postgres databases
Backup all postgres databases using pg_dumpall:
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, --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-security-labels do not dump security label assignments
--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.
[postgres@minion2 bin]$ ./psql -l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
--------------+--------------+----------+---------+-------+-----------------------
benchmarksql | benchmarksql | UTF8 | C | C |
partition_db | postgres | UTF8 | C | C |
postgres | postgres | UTF8 | C | C |
template0 | postgres | UTF8 | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
test_pgdb | postgres | UTF8 | C | C |
(6 rows)
[postgres@minion2 bin]$ ./pg_dumpall > /tmp/all_pgdatabase_backup.sql
[root@minion2 tmp]# less all_pgdatabase_backup.sql
--
-- PostgreSQL database cluster dump
--
SET default_transaction_read_only = off;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
--
-- Roles
--
CREATE ROLE benchmarksql;
ALTER ROLE benchmarksql WITH SUPERUSER INHERIT NOCREATEROLE NOCREATEDB LOGIN NOREPLICATION PASSWORD 'md540a665cab5a6807638fdd6b60b1eaf44';
CREATE ROLE postgres;
ALTER ROLE postgres WITH SUPERUSER INHERIT CREATEROLE CREATEDB LOGIN REPLICATION PASSWORD 'md53175bce1d3201d16594cebf9d7eb3f9d';
--
-- Database creation
--
CREATE DATABASE benchmarksql WITH TEMPLATE = template0 OWNER = benchmarksql;
CREATE DATABASE partition_db WITH TEMPLATE = template0 OWNER = postgres;
REVOKE ALL ON DATABASE template1 FROM PUBLIC;
REVOKE ALL ON DATABASE template1 FROM postgres;
GRANT ALL ON DATABASE template1 TO postgres;
GRANT CONNECT ON DATABASE template1 TO PUBLIC;
CREATE DATABASE test_pgdb WITH TEMPLATE = template0 OWNER = postgres;
\connect benchmarksql
SET default_transaction_read_only = off;
--
-- PostgreSQL database dump
--
SET statement_timeout = 0;
SET lock_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SET check_function_bodies = false;
SET client_min_messages = warning;
--
-- Name: plpgsql; Type: EXTENSION; Schema: -; Owner:
--
CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog;
--
-- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner:
--
COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language';
SET search_path = public, pg_catalog;
SET default_tablespace = '';
SET default_with_oids = false;
--
-- Name: customer; Type: TABLE; Schema: public; Owner: benchmarksql; Tablespace:
--
CREATE TABLE customer (
c_w_id integer NOT NULL,
c_d_id integer NOT NULL,
c_id integer NOT NULL,
c_discount numeric(4,4),
c_credit character(2),
c_last character varying(16),
c_first character varying(16),
c_credit_lim numeric(12,2),
c_balance numeric(12,2),
c_ytd_payment double precision,
c_payment_cnt integer,
c_delivery_cnt integer,
c_street_1 character varying(20),
c_street_2 character varying(20),
c_city character varying(20),
c_state character(2),
c_zip character(9),
c_phone character(16),
c_since timestamp without time zone,
c_middle character(2),
c_data character varying(500)
);
ALTER TABLE customer OWNER TO benchmarksql;
[postgres@minion2 bin]$ ./psql -d template1
psql (9.4.5)
Type "help" for help.
template1=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+---------+-------+-----------------------
template0 | postgres | UTF8 | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
(2 rows)
[postgres@minion2 bin]$ ./psql -f /tmp/all_pgdatabase_backup.sql
SET
SET
SET
ERROR: role "benchmarksql" already exists
STATEMENT: CREATE ROLE benchmarksql;
psql:/tmp/all_pgdatabase_backup.sql:14: ERROR: role "benchmarksql" already exists
ALTER ROLE
ERROR: role "postgres" already exists
STATEMENT: CREATE ROLE postgres;
psql:/tmp/all_pgdatabase_backup.sql:16: ERROR: role "postgres" already exists
ALTER ROLE
CREATE DATABASE
CREATE DATABASE
REVOKE
REVOKE
GRANT
GRANT
CREATE DATABASE
You are now connected to database "benchmarksql" as user "postgres".
SET
SET
SET
SET
SET
SET
SET
CREATE EXTENSION
COMMENT
SET
SET
SET
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
COPY 3000000
COPY 1000
COPY 3035734
COPY 100000
COPY 903653
COPY 3036923
COPY 30375276
COPY 10000000
COPY 100
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ERROR: canceling autovacuum task
CONTEXT: automatic analyze of table "benchmarksql.public.order_line"
ALTER TABLE
ALTER TABLE
ALTER TABLE
CREATE INDEX
CREATE INDEX
REVOKE
REVOKE
GRANT
GRANT
You are now connected to database "partition_db" as user "postgres".
SET
SET
SET
SET
SET
SET
SET
CREATE EXTENSION
COMMENT
SET
SET
SET
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
COPY 0
COPY 0
COPY 0
COPY 0
COPY 0
COPY 0
COPY 0
COPY 0
COPY 0
COPY 0
COPY 0
COPY 0
COPY 0
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
REVOKE
REVOKE
GRANT
GRANT
You are now connected to database "postgres" as user "postgres".
SET
SET
SET
SET
SET
SET
SET
COMMENT
CREATE EXTENSION
COMMENT
SET
SET
SET
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
COPY 0
COPY 0
COPY 0
COPY 0
COPY 0
COPY 0
COPY 0
COPY 0
COPY 0
REVOKE
REVOKE
GRANT
GRANT
You are now connected to database "template1" as user "postgres".
SET
SET
SET
SET
SET
SET
SET
COMMENT
CREATE EXTENSION
COMMENT
REVOKE
REVOKE
GRANT
GRANT
You are now connected to database "test_pgdb" as user "postgres".
SET
SET
SET
SET
SET
SET
SET
CREATE EXTENSION
COMMENT
SET
SET
SET
CREATE TABLE
ALTER TABLE
COPY 1
REVOKE
REVOKE
GRANT
GRANT
Backup a specific postgres table
To backup a specific table, use the –table TABLENAME option in the pg_dump command. If there are same table names in different schema then use the –schema SCHEMANAME option.
$ pg_dump -t tablename -U username dbname -f onlytable.sql
[postgres@minion2 bin]$ ./pg_dump -t customer -U benchmarksql benchmarksql -f /tmp/benchmarksql_customer.sql
[root@minion2 tmp]# less benchmarksql_customer.sql
--
-- PostgreSQL database dump
--
SET statement_timeout = 0;
SET lock_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SET check_function_bodies = false;
SET client_min_messages = warning;
SET search_path = public, pg_catalog;
SET default_tablespace = '';
SET default_with_oids = false;
--
-- Name: customer; Type: TABLE; Schema: public; Owner: benchmarksql; Tablespace:
--
CREATE TABLE customer (
c_w_id integer NOT NULL,
c_d_id integer NOT NULL,
c_id integer NOT NULL,
c_discount numeric(4,4),
c_credit character(2),
c_last character varying(16),
c_first character varying(16),
c_credit_lim numeric(12,2),
c_balance numeric(12,2),
c_ytd_payment double precision,
c_payment_cnt integer,
c_delivery_cnt integer,
c_street_1 character varying(20),
c_street_2 character varying(20),
c_city character varying(20),
c_state character(2),
c_zip character(9),
c_phone character(16),
c_since timestamp without time zone,
c_middle character(2),
c_data character varying(500)
);
ALTER TABLE customer OWNER TO benchmarksql;
--
-- Data for Name: customer; Type: TABLE DATA; Schema: public; Owner: benchmarksql
--
COPY customer (c_w_id, c_d_id, c_id, c_discount, c_credit, c_last, c_first, c_credit_lim, c_balance, c_ytd_payment, c_payment_cnt, c_d
elivery_cnt, c_street_1, c_street_2, c_city, c_state, c_zip, c_phone, c_since, c_middle, c_data) FROM stdin;
[postgres@minion2 bin]$ ./psql -U benchmarksql benchmarksql
psql (9.4.5)
Type "help" for help.
benchmarksql=# drop table customer ;
DROP TABLE
benchmarksql=# \d
List of relations
Schema | Name | Type | Owner
--------+------------+-------+--------------
public | district | table | benchmarksql
public | history | table | benchmarksql
public | item | table | benchmarksql
public | new_order | table | benchmarksql
public | oorder | table | benchmarksql
public | order_line | table | benchmarksql
public | stock | table | benchmarksql
public | warehouse | table | benchmarksql
(8 rows)
[postgres@minion2 bin]$ ./psql -U benchmarksql -d benchmarksql -f /tmp/benchmarksql_customer.sql
SET
SET
SET
SET
SET
SET
SET
SET
SET
CREATE TABLE
ALTER TABLE
COPY 3000000
ALTER TABLE
CREATE INDEX
[postgres@minion2 bin]$ ./psql -U benchmarksql benchmarksql
psql (9.4.5)
Type "help" for help.
benchmarksql=# \d+
List of relations
Schema | Name | Type | Owner | Size | Description
--------+------------+-------+--------------+----------+-------------
public | customer | table | benchmarksql | 1772 MB |
public | district | table | benchmarksql | 152 kB |
public | history | table | benchmarksql | 250 MB |
public | item | table | benchmarksql | 10184 kB |
public | new_order | table | benchmarksql | 38 MB |
public | oorder | table | benchmarksql | 198 MB |
public | order_line | table | benchmarksql | 3000 MB |
public | stock | table | benchmarksql | 3392 MB |
public | warehouse | table | benchmarksql | 40 kB |
(9 rows)
Backup a local postgres database and restore to remote server using single command:
$ pg_dump dbname | psql -h hostname dbname
The above dumps the local database, and extracts it at the given hostname.
dump locale database benchmarksql from 192.168.0.15 to remote server 192.168.0.71 and extracts it at database postgres
[postgres@minion2 bin]$ ./pg_dump -U benchmarksql benchmarksql |./psql -h 192.168.0.71 -p 6432 -U benchmarksql postgres
SET
SET
SET
SET
SET
SET
CREATE EXTENSION
COMMENT
SET
SET
SET
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
CREATE TABLE
ALTER TABLE
COPY 3000000
COPY 1000
COPY 3035734
COPY 100000
COPY 903653
COPY 3036923
COPY 30375276
COPY 10000000
COPY 100
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
CREATE INDEX
CREATE INDEX
REVOKE
REVOKE
GRANT
GRANT
shown at 192.168.0.17 database postgres
[postgres@DELL-R720 bin]$ ./psql -p 6432
psql (9.4.5)
Type "help" for help.
postgres=# \d+
List of relations
Schema | Name | Type | Owner | Size | Description
--------+------------+-------+--------------+----------+-------------
public | customer | table | benchmarksql | 1772 MB |
public | district | table | benchmarksql | 152 kB |
public | history | table | benchmarksql | 250 MB |
public | item | table | benchmarksql | 10184 kB |
public | new_order | table | benchmarksql | 38 MB |
public | oorder | table | benchmarksql | 198 MB |
public | order_line | table | benchmarksql | 3000 MB |
public | stock | table | benchmarksql | 3392 MB |
public | warehouse | table | benchmarksql | 40 kB |
(9 rows)
dump specified table of specified database to specified database
[postgres@minion2 bin]$ ./pg_dump -p 5432 -U postgres pgbench5432 -t pgbench_branches |./psql -p 6432 -U postgres pgbench6432
SET
SET
SET
SET
SET
SET
SET
SET
SET
CREATE TABLE
ALTER TABLE
COPY 1428
ALTER TABLE
[postgres@minion2 bin]$ ./pg_dump -p 5432 -U postgres pgbench5432 -t pgbench_history |./psql -p 6432 -U postgres pgbench6432
SET
SET
SET
SET
SET
SET
SET
SET
SET
CREATE TABLE
ALTER TABLE
COPY 0
[postgres@minion2 bin]$ ./pg_dump -p 5432 -U postgres pgbench5432 -t pgbench_tellers |./psql -p 7432 -U postgres pgbench7432
SET
SET
SET
SET
SET
SET
SET
SET
SET
CREATE TABLE
ALTER TABLE
COPY 14280
ALTER TABLE
backup
[postgres@minion1 bin]$ ./pg_dump -h 192.168.0.14 -p 5432 -U postgres -d pgbench5432 -C -Fp -f /mnt/data/pgbench5432.dump
restore
[postgres@minion1 bin]$ ./psql -h localhost -p 5432 -U postgres -f /mnt/data/pgbench5432.dump
backup
[postgres@minion1 bin]$ ./pg_dump -h 192.168.0.14 -p 5432 -U postgres -d pgbench5432 -C -Fc -f /mnt/data/pgbench.dump
restore
[postgres@minion1 bin]$ ./pg_restore -h 192.168.0.14 -p 5432 -U postgres -C -d postgres /mnt/data/pgbench.dump
#pg_restore: options -d/--dbname and -f/--file cannot be used together.
backup
[postgres@minion1 bin]$ ./pg_dump -h 192.168.0.14 -p 5432 -U postgres -d pgbench5432 -F d -f /mnt/data/backup/
restore
[postgres@minion1 bin]$ ./pg_restore -h 192.168.0.14 -p 5432 -U postgres -C -d postgres /mnt/data/backup/
PostgreSQL pg_dump pg_dumpall and restore的更多相关文章
- [转帖]PostgreSQL pg_dump&psql 数据的备份与恢复
PostgreSQL pg_dump&psql 数据的备份与恢复 https://www.cnblogs.com/chjbbs/p/6480687.html 文章写的挺好 今天试了下 挺不 ...
- (转)PostgreSQL pg_dump&psql 数据的备份与恢复
转自:https://www.cnblogs.com/chjbbs/p/6480687.html Usage: pg_dump [OPTION]... [DBNAME] 数据库名放最后,不指定默认 ...
- PostgreSQL pg_dump&psql 数据的备份与恢复
Usage: pg_dump [OPTION]... [DBNAME] 数据库名放最后,不指定默认是系统变量PGDATABASE指定的数据库. General options:(一般选项) - ...
- Postgresql pg_dump
pg_dump 命令详解 参数 描述 -h 指定服务器名称 -p 指定端口 -U 指定要连接的用户名 -w/--no-password 从不提示密码 -W/--password 强制pg_dump在连 ...
- Postgresql pg_dump 与 pg_restore 使用举例
pg_dump备份 备份本地osdb数据库,全备份,不需要密码 pg_dump osdb > osdb.sql 备份远程osdb数据库 pg_dump -h 192.168.122.1 -Uos ...
- postgresql 备份(pg_dump,pg_restore)
PG提供物理备份和逻辑备份(本篇主要讲逻辑备份)物理备份:WAL热备份逻辑备份:pg_dump,pg_dumpall,恢复时pg_restore 查看帮助命令: pg_dump --help 跟MyS ...
- postgresql 常规操作以及检查备份
一.建表时,复制源表的信息test=# test=# \d test.t1 Table "test.t1" Column | Type | Collation | Nullable ...
- postgresql学习笔记--基础篇
1. 客户端程序和服务器端程序 1.1 客户端程序 Command Example Describe clusterdb clusterdb -h pghost1 -p 1921 -d mydb Cl ...
- 【PostgreSQL】入门学习笔记
前言: 以下内容为前几天在备考PostgreSQL入门考试时候做的笔记,经过了全职的两天的奋战与实验,并最终顺利通过了PCA初级认证考试.现在把我学习的笔记分享给大家,文中有对应的思维导图图片可供 ...
随机推荐
- 使用fsck修复文件系统错误
1.问题描述 服务器maint_samba 由于服务器maint_samba (debian操作系统)没有正常关机,在重新启动过程中/dev/sdb1出现文件系统错误,需要手动使用fsck进行扫描 ...
- Natural Language Processing Computational Linguistics
http://www.nltk.org/book/ch00.html After this, the pace picks up, and we move on to a series of chap ...
- quanpailie quanbianli
#include<stdio.h>char data[5]={'a','b','c','d','e'};int vist[5]={0};char step[5]={0};char bu[5 ...
- [转载]:Delphi xe7并行编程快速入门
现在多数设备.计算机都有多个CPU单元,即使是手机也是多核的.但要在开发中使用多核的优势,却需要一些技巧,花费时间编写额外的代码.好了,现在可以使用Delphi做并行编程了. 在Delphi.C++ ...
- java Reentrant Lock
//Listing 7-1. Achieving Synchronization in Terms of Reentrant Locks import java.util.concurrent.Exe ...
- linux实现c多进程
线程(thread)技术早在60年代就被提出,但真正应用多线程到操作系统中去,是在80年代中期,solaris是这方面的佼佼者.传统的Unix也支持线程的概念,但是在一个进程(process)中只允许 ...
- mysql 存储过程--- 创建,调用,删除
DELIMITER //CREATE PROCEDURE p_addscore(nums INT,OUT retrows INT)BEGINDECLARE i INT DEFAULT 0;add_lo ...
- C++用数组实现的静态队列
#ifndef _STATIC_QUEUE_H_ #define _STATIC_QUEUE_H_ // 静态queue模板,用数组实现的队列,在初始化的时候需要指定长度 template<cl ...
- cdecl和stdcall调用约定-汇编演示
. .model flat, stdcall .stack ExitProcess PROTO, dwExitCode:DWORD .data val2 sdword result dword ? . ...
- 【转】Android Paint之 setXfermode PorterDuffXfermode 讲解
[置顶] Android Paint之 setXfermode PorterDuffXfermode 讲解 分类: android动效篇2015-04-07 17:23 978人阅读 评论(8) 收藏 ...