19
19
my $dataBasePassword;
22
my $schema = 'public';
24
"$0 -node host:database:user[:password:port] [-node ...] [-schema myschema]
24
"$0 -node host:database:user[:password:port] [-node ...] [-schema myschema] [-schema myschema2...]
25
25
First node is assumed to be the master.
26
26
Default schema is \"public\"\n";
28
&usage if ( !GetOptions( 'node=s@' => \@nodes, 'schema=s' => \$schema ) );
28
&usage if ( !GetOptions( 'node=s@' => \@nodes, 'schema=s' => \@schema ) );
30
30
die "At least one node is required" if ( scalar(@nodes) < 1 );
32
# If we get no schema, use public
33
@schema = ('public') unless (@schema);
32
35
my $nodeNumber = 1;
34
37
foreach my $node (@nodes) {
58
61
{ RaiseError => 0, PrintError => 0, AutoCommit => 1 } );
59
62
die "connect: $DBI::errstr" if ( !defined($dbh) || $DBI::err );
61
# Read in all the user 'normal' tables in $schema (public by default).
64
# Read in all the user 'normal' tables in @schema (public by default).
65
# put all schemas between single quotes for the query
66
my @protected_schema=map("'".$_."'",@schema);
62
67
my $tableQuery = $dbh->prepare( "
63
68
SELECT pg_namespace.nspname || '.' || pg_class.relname,pg_class.relkind,pg_class.relhaspkey
64
69
FROM pg_namespace,pg_class
65
70
WHERE pg_class.reltype > 0
66
71
AND pg_class.relnamespace = pg_catalog.pg_namespace.oid
67
72
AND (pg_class.relkind = 'r' OR pg_class.relkind = 'S')
68
AND pg_namespace.nspname = '$schema' AND pg_namespace.oid = pg_class.relnamespace"
73
AND pg_namespace.nspname IN (" . join(',',@protected_schema) . ") AND pg_namespace.oid = pg_class.relnamespace"
71
76
die "prepare(tableQuery): $DBI::errstr"
72
77
if ( !defined($tableQuery) || $DBI::err );
73
78
die "execute(tableQuery): $DBI::errstr" if ( !$tableQuery->execute() );
74
die "No objects to replicate found in schema \"$schema\"\n"
79
die "No objects to replicate found in schema(s) \"" . join(',',@schema) . "\"\n"
75
80
if ( $tableQuery->rows <= 0 );
77
82
my @tablesWithIndexes;