Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use copy with binary. #857

Merged
merged 8 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/include/clone.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@
--create-slot Create the replication slot
--origin Use this Postgres replication origin node name
--endpos Stop replaying changes when reaching this LSN
--use-copy-binary Use the COPY BINARY format for COPY operations

1 change: 1 addition & 0 deletions docs/include/copy-db.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@
--resume Allow resuming operations after a failure
--not-consistent Allow taking a new snapshot on the source database
--snapshot Use snapshot obtained with pg_export_snapshot
--use-copy-binary Use the COPY BINARY format for COPY operations

1 change: 1 addition & 0 deletions src/bin/pgcopydb/cli_clone_follow.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
" --create-slot Create the replication slot\n" \
" --origin Use this Postgres replication origin node name\n" \
" --endpos Stop replaying changes when reaching this LSN\n" \
" --use-copy-binary Use the COPY BINARY format for COPY operations\n" \
VaibhaveS marked this conversation as resolved.
Show resolved Hide resolved

CommandLine clone_command =
make_command(
Expand Down
14 changes: 12 additions & 2 deletions src/bin/pgcopydb/cli_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,9 @@ cli_copydb_getenv(CopyDBOptions *options)
{ PGCOPYDB_SKIP_CTID_SPLIT, ENV_TYPE_BOOL,
&(options->skipCtidSplit) },
{ PGCOPYDB_SKIP_TABLESPACES, ENV_TYPE_BOOL,
&(options->restoreOptions.noTableSpaces) }
&(options->restoreOptions.noTableSpaces) },
{ PGCOPYDB_USE_COPY_BINARY, ENV_TYPE_BOOL,
&(options->useCopyBinary) }
};

int parserCount = sizeof(parsers) / sizeof(parsers[0]);
Expand Down Expand Up @@ -616,6 +618,7 @@ cli_copy_db_getopts(int argc, char **argv)
{ "skip-db-properties", no_argument, NULL, 'g' },
{ "skip-split-by-ctid", no_argument, NULL, 'k' },
{ "no-tablespaces", no_argument, NULL, 'y' },
{ "use-copy-binary", no_argument, NULL, 'n' },
{ "filter", required_argument, NULL, 'F' },
{ "filters", required_argument, NULL, 'F' },
{ "requirements", required_argument, NULL, 'Q' },
Expand Down Expand Up @@ -651,7 +654,7 @@ cli_copy_db_getopts(int argc, char **argv)
}

const char *optstring =
"S:T:D:J:I:b:L:u:mcAPOXj:xBeMlUagkyF:F:Q:irRCN:fp:ws:o:tE:Vvdzqh";
"S:T:D:J:I:b:L:u:mcAPOXj:xBeMlUagkynF:F:Q:irRCN:fp:ws:o:tE:Vvdzqh";

while ((c = getopt_long(argc, argv,
optstring, long_options, &option_index)) != -1)
Expand Down Expand Up @@ -1084,6 +1087,13 @@ cli_copy_db_getopts(int argc, char **argv)
break;
}

case 'n':
{
options.useCopyBinary = true;
log_trace("--use-copy-binary");
break;
}

case '?':
default:
{
Expand Down
1 change: 1 addition & 0 deletions src/bin/pgcopydb/cli_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ typedef struct CopyDBOptions
bool skipCtidSplit;
bool noRolesPasswords;
bool failFast;
bool useCopyBinary;

bool restart;
bool resume;
Expand Down
3 changes: 2 additions & 1 deletion src/bin/pgcopydb/cli_copy.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ static CommandLine copy_db_command =
" --restart Allow restarting when temp files exist already\n"
" --resume Allow resuming operations after a failure\n"
" --not-consistent Allow taking a new snapshot on the source database\n"
" --snapshot Use snapshot obtained with pg_export_snapshot\n",
" --snapshot Use snapshot obtained with pg_export_snapshot\n"
" --use-copy-binary Use the COPY BINARY format for COPY operations\n",
cli_copy_db_getopts,
cli_clone);

Expand Down
1 change: 1 addition & 0 deletions src/bin/pgcopydb/copydb.c
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,7 @@ copydb_init_specs(CopyDataSpec *specs,
.skipCtidSplit = options->skipCtidSplit,
.noRolesPasswords = options->noRolesPasswords,
.failFast = options->failFast,
.useCopyBinary = options->useCopyBinary,

.restart = options->restart,
.resume = options->resume,
Expand Down
1 change: 1 addition & 0 deletions src/bin/pgcopydb/copydb.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ typedef struct CopyDataSpec
bool skipDBproperties;
bool skipCtidSplit;
bool noRolesPasswords;
bool useCopyBinary;

bool restart;
bool resume;
Expand Down
1 change: 1 addition & 0 deletions src/bin/pgcopydb/defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
#define PGCOPYDB_SKIP_TABLESPACES "PGCOPYDB_SKIP_TABLESPACES"
#define PGCOPYDB_SKIP_DB_PROPERTIES "PGCOPYDB_SKIP_DB_PROPERTIES"
#define PGCOPYDB_SKIP_CTID_SPLIT "PGCOPYDB_SKIP_CTID_SPLIT"
#define PGCOPYDB_USE_COPY_BINARY "PGCOPYDB_USE_COPY_BINARY"

/* default values for the command line options */
#define DEFAULT_TABLE_JOBS 4
Expand Down
16 changes: 15 additions & 1 deletion src/bin/pgcopydb/pgsql.c
Original file line number Diff line number Diff line change
Expand Up @@ -3095,7 +3095,13 @@ pg_copy_send_query(PGSQL *pgsql, CopyArgs *args, ExecStatusType status)
args->srcAttrList,
args->srcQname);
}

appendPQExpBuffer(sql, "to stdout");

if (args->useCopyBinary)
{
appendPQExpBuffer(sql, " with (format binary)");
}
}
else if (status == PGRES_COPY_IN)
{
Expand All @@ -3110,10 +3116,18 @@ pg_copy_send_query(PGSQL *pgsql, CopyArgs *args, ExecStatusType status)
appendPQExpBuffer(sql, "copy %s from stdin", args->dstQname);
}

if (args->freeze)
if (args->freeze && args->useCopyBinary)
{
appendPQExpBuffer(sql, " with (freeze, format binary)");
}
else if (args->freeze)
{
appendPQExpBuffer(sql, " with (freeze)");
}
else if (args->useCopyBinary)
{
appendPQExpBuffer(sql, " with (format binary)");
}
}
else
{
Expand Down
1 change: 1 addition & 0 deletions src/bin/pgcopydb/pgsql.h
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ typedef struct CopyArgs
char *logCommand;
bool truncate;
bool freeze;
bool useCopyBinary;
} CopyArgs;


Expand Down
1 change: 1 addition & 0 deletions src/bin/pgcopydb/table-data.c
Original file line number Diff line number Diff line change
Expand Up @@ -1129,6 +1129,7 @@ copydb_table_create_lockfile(CopyDataSpec *specs,
args->dstAttrList = tableSpecs->sourceTable->attrList;
args->truncate = false; /* default value, see below */
args->freeze = tableSpecs->sourceTable->partition.partCount <= 1;
args->useCopyBinary = specs->useCopyBinary;

/*
* Check to see if we want to TRUNCATE the table and benefit from the COPY
Expand Down
2 changes: 1 addition & 1 deletion tests/endpos-in-multi-wal-txn/copydb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ sleep 1
pgcopydb stream setup

# pgcopydb clone uses the environment variables
pgcopydb clone
pgcopydb clone --use-copy-binary

# now that the copying is done, inject some SQL DML changes to the source
psql -d ${PGCOPYDB_SOURCE_PGURI} -f /usr/src/pgcopydb/multi-wal-txn.sql
Expand Down
2 changes: 1 addition & 1 deletion tests/follow-9.6/copydb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ psql -d ${PGCOPYDB_SOURCE_PGURI} -f /usr/src/pgcopydb/ddl.sql
find ${TMPDIR}

# pgcopydb copy db uses the environment variables
pgcopydb clone --follow --notice
pgcopydb clone --follow --notice --use-copy-binary

# cleanup
pgcopydb stream sentinel get
Expand Down
1 change: 1 addition & 0 deletions tests/pagila/copydb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ pgcopydb clone --notice \
--skip-ext-comments \
--skip-db-properties \
--estimate-table-sizes \
--use-copy-binary \
--source ${PAGILA_SOURCE_PGURI} \
--target ${PAGILA_TARGET_PGURI}

Expand Down
Loading