Created
July 22, 2024 08:12
-
-
Save ledger123/0afd9c74bc59ea03ac8a2f2e40872f9a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/perl | |
| use strict; | |
| use warnings; | |
| my $username = 'postgres'; | |
| my $sql_file = 'dbchanges.sql'; | |
| my @databases = `psql -U $username -l -t | cut -d '|' -f 1`; | |
| foreach my $db (@databases) { | |
| $db =~ s/^\s+|\s+$//g; | |
| } | |
| foreach my $db (@databases) { | |
| next if $db eq 'template0' || $db eq 'template1'; # Skipping system databases | |
| my $command = "psql -U $username $db < $sql_file"; | |
| system($command) == 0 or die "Failed to execute command: $command\n"; | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment