Skip to content

Commit

Permalink
Fix pg_dump for non-babelfish databases (#1914)
Browse files Browse the repository at this point in the history
Recently, we introduced a change where we mistakenly disallowed pg_dump
for a non-Babelfish databases. This commit fixes this issue.

Added TAP tests to verify the behavior.

Task: MANFRED-19333
Signed-off-by: Rishabh Tanwar [email protected]
  • Loading branch information
rishabhtanwar29 authored Oct 18, 2023
1 parent 414e824 commit 5d7b8f7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .github/composite-actions/dump-restore-util/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ runs:
if [[ '${{ inputs.logical_database }}' == 'null' ]];then
echo 'Starting to dump whole Babelfish physical database'
~/${{ inputs.pg_new_dir }}/bin/pg_dumpall -h localhost --database jdbc_testdb --username jdbc_user --globals-only --quote-all-identifiers --verbose --no-role-passwords -f pg_dump_globals.sql 2>>error.log
~/${{ inputs.pg_new_dir }}/bin/pg_dumpall -h localhost --database jdbc_testdb --username jdbc_user --roles-only --quote-all-identifiers --verbose --no-role-passwords -f pg_dump_globals.sql 2>>error.log
~/${{ inputs.pg_new_dir }}/bin/pg_dump -h localhost --username jdbc_user $DUMP_OPTS --quote-all-identifiers --verbose --file="pg_dump.archive" --dbname=jdbc_testdb 2>>error.log
else
echo "Starting to dump Babelfish logical database ${{ inputs.logical_database }}"
~/${{ inputs.pg_new_dir }}/bin/pg_dumpall -h localhost --database jdbc_testdb --username jdbc_user --globals-only --quote-all-identifiers --verbose --no-role-passwords --bbf-database-name='${{ inputs.logical_database }}' -f pg_dump_globals.sql 2>>error.log
~/${{ inputs.pg_new_dir }}/bin/pg_dumpall -h localhost --database jdbc_testdb --username jdbc_user --roles-only --quote-all-identifiers --verbose --no-role-passwords --bbf-database-name='${{ inputs.logical_database }}' -f pg_dump_globals.sql 2>>error.log
~/${{ inputs.pg_new_dir }}/bin/pg_dump -h localhost --username jdbc_user $DUMP_OPTS --quote-all-identifiers --verbose --bbf-database-name='${{ inputs.logical_database }}' --file="pg_dump.archive" --dbname=jdbc_testdb 2>>error.log
fi
Expand Down
23 changes: 21 additions & 2 deletions contrib/babelfishpg_tds/test/t/004_bbfdumprestore.pl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
$oldnode->start;
my @dumpall_command = (
'pg_dumpall', '--database', 'testdb', '--username', 'test_master',
'--port', $oldnode->port, '--globals-only', '--quote-all-identifiers',
'--port', $oldnode->port, '--roles-only', '--quote-all-identifiers',
'--verbose', '--no-role-passwords', '--file', $dump1_file);
$newnode->command_ok(\@dumpall_command, 'Dump global objects.');
# Dump Babelfish database using pg_dump.
Expand Down Expand Up @@ -135,7 +135,7 @@
# need to use dump utilities from the new node here.
@dumpall_command = (
'pg_dumpall', '--database', 'testdb', '--username', 'test_master',
'--port', $newnode2->port, '--globals-only', '--quote-all-identifiers',
'--port', $newnode2->port, '--roles-only', '--quote-all-identifiers',
'--verbose', '--no-role-passwords', '--file', $dump3_file);
$newnode2->command_ok(\@dumpall_command, 'Dump global objects.');
# Dump Babelfish database using pg_dump. Let's dump with the custom format
Expand Down Expand Up @@ -177,4 +177,23 @@
qr/Dump and restore across different migration modes is not yet supported./,
'Restore of Babelfish database failed since source and target migration modes do not match.');
$newnode->stop;

############################################################################################
########################### Test dump for non Babelfish database ###########################
############################################################################################
$newnode->start;

# Dump global objects using pg_dumpall.
@dumpall_command = (
'pg_dumpall', '--database', 'postgres', '--port', $newnode->port,
'--roles-only', '--quote-all-identifiers', '--verbose',
'--no-role-passwords', '--file', $dump1_file);
$newnode->command_ok(\@dumpall_command, 'Dump global objects.');
# Dump Babelfish database using pg_dump.
@dump_command = (
'pg_dump', '--quote-all-identifiers', '--port', $newnode->port,
'--verbose', '--dbname', 'postgres',
'--file', $dump2_file);
$newnode->command_ok(\@dump_command, 'Dump non-Babelfish (postgres db) database.');
$newnode->stop;
done_testing();
4 changes: 2 additions & 2 deletions dev-tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,10 @@ pg_dump() {
rm -f pg_dump_globals.sql pg_dump.sql error.log

if [[ ! $2 ]];then
$1/postgres/bin/pg_dumpall --username jdbc_user --globals-only --quote-all-identifiers --verbose -f pg_dump_globals.sql 2>error.log
$1/postgres/bin/pg_dumpall --username jdbc_user --roles-only --quote-all-identifiers --verbose -f pg_dump_globals.sql 2>error.log
$1/postgres/bin/pg_dump --create --username jdbc_user --column-inserts --quote-all-identifiers --verbose --file="pg_dump.sql" --dbname=jdbc_testdb 2>>error.log
else
$1/postgres/bin/pg_dumpall --username jdbc_user --globals-only --quote-all-identifiers --verbose --bbf-database-name=$2 -f pg_dump_globals.sql 2>error.log
$1/postgres/bin/pg_dumpall --username jdbc_user --roles-only --quote-all-identifiers --verbose --bbf-database-name=$2 -f pg_dump_globals.sql 2>error.log
$1/postgres/bin/pg_dump --username jdbc_user --column-inserts --quote-all-identifiers --verbose --bbf-database-name=$2 --file="pg_dump.sql" --dbname=jdbc_testdb 2>>error.log
fi
stop $1
Expand Down

0 comments on commit 5d7b8f7

Please sign in to comment.