-
Notifications
You must be signed in to change notification settings - Fork 0
/
oracle_execute.py
executable file
·36 lines (29 loc) · 1.28 KB
/
oracle_execute.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/python
import cx_Oracle
from sqlalchemy import *
from sqlalchemy.orm import *
#Host - Ip ou DNS do banco Oracle que vai se conectar para ativar o supplement logs nas tabelas
#user - usuario para conectar no banco (Também é o schema)
#password - necessário o user a password estarem sincronizados (na ordem)
host = ""
user = [""]
password = [""]
def get_tables(host, user, password):
for u, p in zip(user, password):
#Buscar tabelas relacionadas ao usuario na lista acima
query= "SELECT table_name, owner FROM all_tables WHERE owner='"+str(str(u).upper())+"' ORDER BY owner, table_name"
print query
engine = create_engine("oracle://"+u+":"+p+"@"+host+"/ORCL")
conn = engine.connect()
result = conn.execute(query)
for table in result:
alter_tables(conn, u, p, str(table[0]))
conn.close()
def alter_tables(conn, u, p, tabela):
#executa a ativacao do supplent logging em todas as tabelas do schema informado
try:
conn.execute("alter table "+u+"."+tabela+" add supplemental log data (ALL) columns")
print "Schema: "+u+"Ativando supplemental loggin em "+tabela
except:
print "Schema "+ u + ": Supplemental logging ja ativado na tabela "+tabela
get_tables(host, user, password)