Skip to content
Snippets Groups Projects
Commit 61d622dd authored by Rafael De Lima Prado's avatar Rafael De Lima Prado
Browse files

database: Add creation of tablespaces. Add script to migrate data and indexes...

database: Add creation of tablespaces. Add script to migrate data and indexes to the respective tablespaces

Signed-off-by: default avatarRafael de Lima Prado <rlp09@inf.ufpr.br>
parent 16974fbc
Branches exemplo/6
No related tags found
No related merge requests found
CREATE TABLESPACE dw_index_ts LOCATION '/home/index/dw_tablespace';
CREATE TABLESPACE aggr_index_ts LOCATION '/home/index/aggr_tablespace';
CREATE TABLESPACE aggr_table_ts LOCATION '/home/banco/aggr_tablespace';
CREATE TABLESPACE dw_table_ts LOCATION '/home/banco/dw_tablespace';
CREATE TABLESPACE sa_ts LOCATION '/home/banco/sa_tablespace';
CREATE TABLESPACE le_save_conf_tablespace location '/home/banco/le_save_conf';
#!/usr/bin/python
# -*- coding: utf-8 -*-
import psycopg2
import sys
dbName = "proinfodata"
tablespace_table_dw = "dw_table_ts"
tablespace_index_dw = "dw_index_ts"
try:
con = psycopg2.connect(user = 'postgres', database = dbName, port = '5432')
db = con.cursor()
db.execute( "alter table %s.%s set tablespace %s" % ( 'public', 'aggr_availability', 'aggr_table_ts' ) )
db.execute("select * from pg_indexes where schemaname = '%s' and tablename = '%s' order by indexname" % ( 'public', 'aggr_availability'))
rows = db.fetchall()
for index in rows:
db.execute( "alter index %s.%s set tablespace %s" % ( 'public', index[2], 'aggr_index_ts' ) )
db.execute("alter table %s.%s set tablespace %s" % ('public', 'proinfo_inventory', 'sa_ts'))
db.execute( "select * from pg_indexes where schemaname = '%s' and tablename = '%s' order by indexname" % ( 'public', 'proinfo_inventory'))
rows = db.fetchall()
for index in rows:
db.execute( "alter index %s.%s set tablespace %s" % ( 'public', index[2], 'sa_ts' ) )
db.execute( "alter table %s.%s set tablespace %s" % ( 'public', 'proinfo_net_usage', 'sa_ts' ) )
db.execute( "select * from pg_indexes where schemaname = '%s' and tablename = '%s' order by indexname" % ( 'public', 'proinfo_net_usage'))
rows = db.fetchall()
for index in rows:
db.execute( "alter index %s.%s set tablespace %s" % ( 'public', index[2], 'sa_ts' ) )
db.execute("select * from pg_tables where tablename != 'aggr_availability' and tablename != 'proinfo_inventory' and tablename != 'proinfo_net_usage' order by tablename")
rows_tables = db.fetchall()
for table in rows_tables:
schemaName = table[0]
if schemaName == "public":
tableName = table[1]
db.execute( "alter table %s.%s set tablespace %s" % ( schemaName, tableName, tablespace_table_dw ) )
db.execute( "select * from pg_indexes where schemaname = '%s' and tablename = '%s' order by indexname" % ( schemaName, tableName ))
rows_indexes = db.fetchall()
for index in rows_indexes:
db.execute( "alter index %s.%s set tablespace %s" % ( schemaName, index[2], tablespace_index_dw ) )
con.commit()
except psycopg2.DatabaseError, e:
if con:
con.rollback()
print 'Error %s' % e
sys.exit(1)
finally:
if con:
con.close()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment