Merge branch 'improve-postgres-restore-cleaning' into 'master'
Use native Postgres database cleaning during backup restore We were using hacks to drop tables etc during a Postgres backup restore. With this change, we let pg_dump insert the DROP TABLE statements it needs at the start of the SQL dump. See merge request !1891
This commit is contained in:
commit
b9452d7bcd
|
@ -39,6 +39,7 @@ v 7.13.0 (unreleased)
|
||||||
- Correctly show anonymous authorized applications under Profile > Applications.
|
- Correctly show anonymous authorized applications under Profile > Applications.
|
||||||
- Query Optimization in MySQL.
|
- Query Optimization in MySQL.
|
||||||
- Allow users to be blocked and unblocked via the API
|
- Allow users to be blocked and unblocked via the API
|
||||||
|
- Use native Postgres database cleaning during backup restore
|
||||||
|
|
||||||
v 7.12.2
|
v 7.12.2
|
||||||
- Correctly show anonymous authorized applications under Profile > Applications.
|
- Correctly show anonymous authorized applications under Profile > Applications.
|
||||||
|
|
|
@ -18,7 +18,8 @@ module Backup
|
||||||
when "postgresql" then
|
when "postgresql" then
|
||||||
$progress.print "Dumping PostgreSQL database #{config['database']} ... "
|
$progress.print "Dumping PostgreSQL database #{config['database']} ... "
|
||||||
pg_env
|
pg_env
|
||||||
system('pg_dump', config['database'], out: db_file_name)
|
# Pass '--clean' to include 'DROP TABLE' statements in the DB dump.
|
||||||
|
system('pg_dump', '--clean', config['database'], out: db_file_name)
|
||||||
end
|
end
|
||||||
report_success(success)
|
report_success(success)
|
||||||
abort 'Backup failed' unless success
|
abort 'Backup failed' unless success
|
||||||
|
@ -41,10 +42,6 @@ module Backup
|
||||||
system('mysql', *mysql_args, config['database'], in: db_file_name)
|
system('mysql', *mysql_args, config['database'], in: db_file_name)
|
||||||
when "postgresql" then
|
when "postgresql" then
|
||||||
$progress.print "Restoring PostgreSQL database #{config['database']} ... "
|
$progress.print "Restoring PostgreSQL database #{config['database']} ... "
|
||||||
# Drop all tables because PostgreSQL DB dumps do not contain DROP TABLE
|
|
||||||
# statements like MySQL.
|
|
||||||
Rake::Task["gitlab:db:drop_all_tables"].invoke
|
|
||||||
Rake::Task["gitlab:db:drop_all_postgres_sequences"].invoke
|
|
||||||
pg_env
|
pg_env
|
||||||
system('psql', config['database'], '-f', db_file_name)
|
system('psql', config['database'], '-f', db_file_name)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
namespace :gitlab do
|
|
||||||
namespace :db do
|
|
||||||
task drop_all_postgres_sequences: :environment do
|
|
||||||
connection = ActiveRecord::Base.connection
|
|
||||||
connection.execute("SELECT c.relname FROM pg_class c WHERE c.relkind = 'S';").each do |sequence|
|
|
||||||
connection.execute("DROP SEQUENCE #{sequence['relname']}")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,10 +0,0 @@
|
||||||
namespace :gitlab do
|
|
||||||
namespace :db do
|
|
||||||
task drop_all_tables: :environment do
|
|
||||||
connection = ActiveRecord::Base.connection
|
|
||||||
connection.tables.each do |table|
|
|
||||||
connection.drop_table(table)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
Loading…
Reference in New Issue